Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
event.php
1<?php
2namespace Bitrix\Rest;
3
7
36class EventTable extends Main\Entity\DataManager
37{
38 const ERROR_EVENT_NOT_FOUND = 'ERROR_EVENT_NOT_FOUND';
39
40 const TYPE_ONLINE = 'online';
41 const TYPE_OFFLINE = 'offline';
42
48 public static function getTableName()
49 {
50 return 'b_rest_event';
51 }
52
58 public static function getMap()
59 {
60 return array(
61 'ID' => array(
62 'data_type' => 'integer',
63 'primary' => true,
64 'autocomplete' => true,
65 ),
66 'APP_ID' => array(
67 'data_type' => 'integer',
68 ),
69 'EVENT_NAME' => array(
70 'data_type' => 'string',
71 'required' => true,
72 ),
73 'EVENT_HANDLER' => array(
74 'data_type' => 'string',
75 ),
76 'USER_ID' => array(
77 'data_type' => 'integer',
78 ),
79 'TITLE' => array(
80 'data_type' => 'string'
81 ),
82 'COMMENT' => array(
83 'data_type' => 'string'
84 ),
85 'DATE_CREATE' => array(
86 'data_type' => 'datetime'
87 ),
88 'APPLICATION_TOKEN' => array(
89 'data_type' => 'string'
90 ),
91 'CONNECTOR_ID' => array(
92 'data_type' => 'string'
93 ),
94 'INTEGRATION_ID' => array(
95 'data_type' => 'integer',
96 ),
97 'OPTIONS' => new ArrayField('OPTIONS'),
98 'REST_APP' => array(
99 'data_type' => 'Bitrix\Rest\AppTable',
100 'reference' => array('=this.APP_ID' => 'ref.ID'),
101 ),
102
107 'APP' => array(
108 'data_type' => 'Bitrix\Bitrix24\AppsTable',
109 'reference' => array('=this.APP_ID' => 'ref.ID'),
110 ),
111 );
112 }
113
121 public static function deleteByApp($appId)
122 {
123 $connection = Main\Application::getConnection();
124 return $connection->query("DELETE FROM ".static::getTableName()." WHERE APP_ID='".intval($appId)."'");
125 }
126
134 public static function deleteAppInstaller($appId)
135 {
136 $connection = Main\Application::getConnection();
137 return $connection->query("DELETE FROM ".static::getTableName()." WHERE APP_ID='".intval($appId)."' AND EVENT_NAME='ONAPPINSTALL'");
138 }
139
145 public static function checkCallback($eventCallback, $appInfo, $checkInstallUrl = true)
146 {
147 return \Bitrix\Rest\HandlerHelper::checkCallback($eventCallback, $appInfo, $checkInstallUrl);
148 }
149
150 public static function onBeforeUpdate(Main\Entity\Event $event)
151 {
152 return static::checkUniq($event);
153 }
154
155 public static function onBeforeAdd(Main\Entity\Event $event)
156 {
157 return static::checkUniq($event);
158 }
159
160 public static function bind($eventName)
161 {
162 $provider = new \CRestProvider();
163 $restDescription = $provider->getDescription();
164 foreach($restDescription as $scope => $scopeDescription)
165 {
166 if(
167 is_array($scopeDescription[\CRestUtil::EVENTS])
168 && array_key_exists($eventName, $scopeDescription[\CRestUtil::EVENTS])
169 )
170 {
171 \Bitrix\Rest\Event\Sender::bind(
172 $scopeDescription[\CRestUtil::EVENTS][$eventName][0],
173 $scopeDescription[\CRestUtil::EVENTS][$eventName][1]
174 );
175
176 break;
177 }
178 }
179 }
180
181 public static function onAfterAdd(Main\Entity\Event $event)
182 {
183 $result = new Main\Entity\EventResult();
184
185 $fields = $event->getParameter('fields');
186 static::bind($fields['EVENT_NAME']);
187
188 EventController::onAfterAddEvent($event);
189
190 return $result;
191 }
192
193 public static function onAfterUpdate(Main\Entity\Event $event)
194 {
195 $result = new Main\Entity\EventResult();
196
197 $fields = $event->getParameter('fields');
198 static::bind($fields['EVENT_NAME']);
199
200 return $result;
201 }
202
203 protected static function checkUniq(Main\Entity\Event $event)
204 {
205 $result = new Main\Entity\EventResult();
206 $data = $event->getParameter("fields");
207
208 $dbRes = static::getList(array(
209 'filter' => array(
210 '=APP_ID' => $data['APP_ID'],
211 '=EVENT_NAME' => $data['EVENT_NAME'],
212 '=EVENT_HANDLER' => $data['EVENT_HANDLER'],
213 '=USER_ID' => $data['USER_ID'],
214 '=CONNECTOR_ID' => $data['CONNECTOR_ID'],
215 ),
216 'select' => array('ID')
217 ));
218
219 if($dbRes->fetch())
220 {
221 $result->addError(new Main\Entity\EntityError(
222 "Handler already binded"
223 ));
224 }
225
226 return $result;
227 }
228}
static bind($eventName)
Definition event.php:160
static onBeforeAdd(Main\Entity\Event $event)
Definition event.php:155
static deleteAppInstaller($appId)
Definition event.php:134
const ERROR_EVENT_NOT_FOUND
Definition event.php:38
static onAfterUpdate(Main\Entity\Event $event)
Definition event.php:193
static onBeforeUpdate(Main\Entity\Event $event)
Definition event.php:150
static deleteByApp($appId)
Definition event.php:121
static checkCallback($eventCallback, $appInfo, $checkInstallUrl=true)
Definition event.php:145
static onAfterAdd(Main\Entity\Event $event)
Definition event.php:181
static checkUniq(Main\Entity\Event $event)
Definition event.php:203
static getTableName()
Definition event.php:48