Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
command.php
1<?php
9namespace Bitrix\Im\Model;
10
12use Bitrix\Main;
13
14
49class CommandTable extends Main\Entity\DataManager
50{
56 public static function getTableName()
57 {
58 return 'b_im_command';
59 }
60
66 public static function getMap()
67 {
68 return array(
69 'ID' => array(
70 'data_type' => 'integer',
71 'primary' => true,
72 'autocomplete' => true,
73 //'title' => Loc::getMessage('COMMAND_ENTITY_ID_FIELD'),
74 ),
75 'BOT_ID' => array(
76 'data_type' => 'integer',
77 //'title' => Loc::getMessage('COMMAND_ENTITY_BOT_ID_FIELD'),
78 ),
79 'APP_ID' => array(
80 'data_type' => 'string',
81 'validation' => array(__CLASS__, 'validateAppId'),
82 //'title' => Loc::getMessage('COMMAND_ENTITY_APP_ID_FIELD'),
83 'default_value' => '',
84 ),
85 'COMMAND' => array(
86 'data_type' => 'string',
87 'required' => true,
88 'validation' => array(__CLASS__, 'validateCommand'),
89 //'title' => Loc::getMessage('COMMAND_ENTITY_COMMAND_FIELD'),
90 ),
91 'COMMON' => array(
92 'data_type' => 'boolean',
93 'values' => array('N', 'Y'),
94 //'title' => Loc::getMessage('COMMAND_ENTITY_COMMON_FIELD'),
95 'default_value' => 'N',
96 ),
97 'HIDDEN' => array(
98 'data_type' => 'boolean',
99 'values' => array('N', 'Y'),
100 //'title' => Loc::getMessage('COMMAND_ENTITY_HIDDEN_FIELD'),
101 'default_value' => 'N',
102 ),
103 'EXTRANET_SUPPORT' => array(
104 'data_type' => 'boolean',
105 'values' => array('N', 'Y'),
106 //'title' => Loc::getMessage('COMMAND_ENTITY_EXTRANET_SUPPORT_FIELD'),
107 'default_value' => 'N',
108 ),
109 'SONET_SUPPORT' => array(
110 'data_type' => 'boolean',
111 'values' => array('N', 'Y'),
112 //'title' => Loc::getMessage('COMMAND_ENTITY_SONET_SUPPORT_FIELD'),
113 'default_value' => 'N',
114 ),
115 'CLASS' => array(
116 'data_type' => 'string',
117 'validation' => array(__CLASS__, 'validateClass'),
118 //'title' => Loc::getMessage('COMMAND_ENTITY_CLASS_FIELD'),
119 ),
120 'METHOD_COMMAND_ADD' => array(
121 'data_type' => 'string',
122 'validation' => array(__CLASS__, 'validateMethodCommandAdd'),
123 //'title' => Loc::getMessage('COMMAND_ENTITY_METHOD_COMMAND_ADD_FIELD'),
124 ),
125 'METHOD_LANG_GET' => array(
126 'data_type' => 'string',
127 'validation' => array(__CLASS__, 'validateMethodLangGet'),
128 //'title' => Loc::getMessage('COMMAND_ENTITY_METHOD_LANG_GET_FIELD'),
129 ),
130 'MODULE_ID' => array(
131 'data_type' => 'string',
132 'required' => true,
133 'validation' => array(__CLASS__, 'validateModuleId'),
134 //'title' => Loc::getMessage('COMMAND_ENTITY_MODULE_ID_FIELD'),
135 ),
136 );
137 }
143 public static function validateAppId()
144 {
145 return array(
146 new Main\Entity\Validator\Length(null, 255),
147 );
148 }
154 public static function validateCommand()
155 {
156 return array(
157 new Main\Entity\Validator\Length(null, 255),
158 );
159 }
165 public static function validateClass()
166 {
167 return array(
168 new Main\Entity\Validator\Length(null, 255),
169 );
170 }
176 public static function validateMethodCommandAdd()
177 {
178 return array(
179 new Main\Entity\Validator\Length(null, 255),
180 );
181 }
187 public static function validateMethodLangGet()
188 {
189 return array(
190 new Main\Entity\Validator\Length(null, 255),
191 );
192 }
198 public static function validateModuleId()
199 {
200 return array(
201 new Main\Entity\Validator\Length(null, 50),
202 );
203 }
204
205 public static function onAfterAdd(\Bitrix\Main\ORM\Event $event)
206 {
207 return self::clearCommandCache($event);
208 }
209
210 public static function onAfterUpdate(\Bitrix\Main\ORM\Event $event)
211 {
212 return self::clearCommandCache($event);
213 }
214
215 public static function onAfterDelete(\Bitrix\Main\ORM\Event $event)
216 {
217 return self::clearCommandCache($event);
218 }
219
220 protected static function clearCommandCache(\Bitrix\Main\ORM\Event $event): Main\Entity\EventResult
221 {
222 $id = (int)$event->getParameter('primary')['ID'];
223 $botId = self::getBotId($id);
224
225 if (isset($botId))
226 {
227 Command::cleanCache($botId);
228 }
229
230 return new Main\Entity\EventResult();
231 }
232
233 protected static function getBotId(int $id): ?int
234 {
235 $result = CommandTable::getById($id)->fetch();
236
237 return $result['BOT_ID'] ?: null;
238 }
239}
static onAfterAdd(\Bitrix\Main\ORM\Event $event)
Definition command.php:205
static onAfterDelete(\Bitrix\Main\ORM\Event $event)
Definition command.php:215
static getBotId(int $id)
Definition command.php:233
static onAfterUpdate(\Bitrix\Main\ORM\Event $event)
Definition command.php:210
static clearCommandCache(\Bitrix\Main\ORM\Event $event)
Definition command.php:220