Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
bot.php
1<?php
2namespace Bitrix\Im\Model;
3
7use Bitrix\Im\V2\Common\UpdateByFilterTrait;
8
9
37class BotTable extends Main\Entity\DataManager
38{
39 use UpdateByFilterTrait;
45 public static function getTableName()
46 {
47 return 'b_im_bot';
48 }
49
55 public static function getMap()
56 {
57 return array(
58 'BOT_ID' => array(
59 'data_type' => 'integer',
60 'primary' => true,
61 //'title' => Loc::getMessage('BOT_ENTITY_BOT_ID_FIELD'),
62 ),
63 'MODULE_ID' => array(
64 'data_type' => 'string',
65 'validation' => array(__CLASS__, 'validateModuleId'),
66 'required' => true,
67 //'title' => Loc::getMessage('BOT_ENTITY_MODULE_ID_FIELD'),
68 ),
69 'CODE' => array(
70 'data_type' => 'string',
71 'required' => true,
72 'validation' => array(__CLASS__, 'validateBotCode'),
73 //'title' => Loc::getMessage('BOT_ENTITY_BOT_NAME_FIELD'),
74 ),
75 'TYPE' => array(
76 'data_type' => 'string',
77 'validation' => array(__CLASS__, 'validateBotType'),
78 //'title' => Loc::getMessage('BOT_ENTITY_BOT_TYPE_FIELD'),
79 'default_value' => 'B',
80 ),
81 'CLASS' => array(
82 'data_type' => 'string',
83 'validation' => array(__CLASS__, 'validateToClass'),
84 //'title' => Loc::getMessage('BOT_ENTITY_TO_CLASS_FIELD'),
85 ),
86 'LANG' => array(
87 'data_type' => 'string',
88 'validation' => array(__CLASS__, 'validateLanguage'),
89 //'title' => Loc::getMessage('BOT_ENTITY_LANGUAGE_FIELD'),
90 'default_value' => '',
91 ),
92 'METHOD_BOT_DELETE' => array(
93 'data_type' => 'string',
94 'validation' => array(__CLASS__, 'validateToMethod'),
95 //'title' => Loc::getMessage('BOT_ENTITY_METHOD_BOT_DELETE_FIELD'),
96 ),
97 'METHOD_MESSAGE_ADD' => array(
98 'data_type' => 'string',
99 'validation' => array(__CLASS__, 'validateToMethod'),
100 //'title' => Loc::getMessage('BOT_ENTITY_METHOD_MESSAGE_ADD_FIELD'),
101 ),
102 'METHOD_MESSAGE_UPDATE' => array(
103 'data_type' => 'string',
104 'validation' => array(__CLASS__, 'validateToMethod'),
105 //'title' => Loc::getMessage('BOT_ENTITY_METHOD_MESSAGE_UPDATE_FIELD'),
106 ),
107 'METHOD_MESSAGE_DELETE' => array(
108 'data_type' => 'string',
109 'validation' => array(__CLASS__, 'validateToMethod'),
110 //'title' => Loc::getMessage('BOT_ENTITY_METHOD_MESSAGE_DELETE_FIELD'),
111 ),
112 'METHOD_WELCOME_MESSAGE' => array(
113 'data_type' => 'string',
114 'validation' => array(__CLASS__, 'validateToMethod'),
115 //'title' => Loc::getMessage('BOT_ENTITY_METHOD_WELCOME_MESSAGE_FIELD'),
116 ),
117 'TEXT_PRIVATE_WELCOME_MESSAGE' => array(
118 'data_type' => 'text',
119 //'title' => Loc::getMessage('BOT_ENTITY_TEXT_CHAT_WELCOME_MESSAGE_FIELD'),
120 ),
121 'TEXT_CHAT_WELCOME_MESSAGE' => array(
122 'data_type' => 'text',
123 //'title' => Loc::getMessage('BOT_ENTITY_TEXT_CHAT_WELCOME_MESSAGE_FIELD'),
124 ),
125 'COUNT_MESSAGE' => array(
126 'data_type' => 'integer',
127 //'title' => Loc::getMessage('BOT_ENTITY_COUNT_MESSAGE_FIELD'),
128 ),
129 'COUNT_COMMAND' => array(
130 'data_type' => 'integer',
131 //'title' => Loc::getMessage('BOT_ENTITY_COUNT_COMMAND_FIELD'),
132 ),
133 'COUNT_CHAT' => array(
134 'data_type' => 'integer',
135 //'title' => Loc::getMessage('BOT_ENTITY_COUNT_CHAT_FIELD'),
136 ),
137 'COUNT_USER' => array(
138 'data_type' => 'integer',
139 //'title' => Loc::getMessage('BOT_ENTITY_COUNT_USER_FIELD'),
140 ),
141 'APP_ID' => array(
142 'data_type' => 'string',
143 'validation' => array(__CLASS__, 'validateAppId'),
144 //'title' => Loc::getMessage('BOT_ENTITY_APP_ID_FIELD'),
145 'default_value' => '',
146 ),
147 'VERIFIED' => array(
148 'data_type' => 'boolean',
149 'values' => array('N', 'Y'),
150 //'title' => Loc::getMessage('BOT_ENTITY_VERIFIED_FIELD'),
151 'default_value' => 'N',
152 ),
153 'OPENLINE' => array(
154 'data_type' => 'boolean',
155 'values' => array('N', 'Y'),
156 //'title' => Loc::getMessage('BOT_ENTITY_OPENLINE_FIELD'),
157 'default_value' => 'N',
158 ),
159 'HIDDEN' => array(
160 'data_type' => 'boolean',
161 'values' => array('N', 'Y'),
162 'default_value' => 'N',
163 ),
164 );
165 }
171 public static function validateBotCode()
172 {
173 return array(
174 new Main\Entity\Validator\Length(1, 50),
175 );
176 }
182 public static function validateToClass()
183 {
184 return array(
185 new Main\Entity\Validator\Length(null, 255),
186 );
187 }
193 public static function validateModuleId()
194 {
195 return array(
196 new Main\Entity\Validator\Length(null, 255),
197 );
198 }
204 public static function validateToMethod()
205 {
206 return array(
207 new Main\Entity\Validator\Length(null, 255),
208 );
209 }
210
216 public static function validateAppId()
217 {
218 return array(
219 new Main\Entity\Validator\Length(null, 128),
220 );
221 }
222
228 public static function validateBotType()
229 {
230 return array(
231 new Main\Entity\Validator\Length(null, 1),
232 );
233 }
239 public static function validateLanguage()
240 {
241 return array(
242 new Main\Entity\Validator\Length(null, 50),
243 );
244 }
245
246 public static function onAfterUpdate(\Bitrix\Main\ORM\Event $event)
247 {
248 $id = (int)$event->getParameter('primary')['BOT_ID'];
249 $fields = $event->getParameter('fields');
250
251 if (static::needCacheInvalidate($fields))
252 {
253 BotData::cleanCache($id);
254 }
255
256 return new Main\Entity\EventResult();
257 }
258
259 public static function onAfterDelete(Event $event)
260 {
261 $id = (int)$event->getParameter('primary')['BOT_ID'];
262 BotData::cleanCache($id);
263
264 return new Main\Entity\EventResult();
265 }
266
267 protected static function needCacheInvalidate(array $updatedFields): bool
268 {
269 $cacheInvalidatingFields = [
270 'BOT_ID',
271 'MODULE_ID',
272 'CODE',
273 'TYPE',
274 'CLASS',
275 'LANG',
276 'METHOD_BOT_DELETE',
277 'METHOD_MESSAGE_ADD',
278 'METHOD_MESSAGE_UPDATE',
279 'METHOD_MESSAGE_DELETE',
280 'METHOD_WELCOME_MESSAGE',
281 'TEXT_PRIVATE_WELCOME_MESSAGE',
282 'TEXT_CHAT_WELCOME_MESSAGE',
283 'APP_ID',
284 'VERIFIED',
285 'OPENLINE',
286 'HIDDEN',
287 ];
288
289 return !empty(array_intersect($cacheInvalidatingFields, array_keys($updatedFields)));
290 }
291}
static validateToMethod()
Definition bot.php:204
static validateAppId()
Definition bot.php:216
static validateBotCode()
Definition bot.php:171
static validateLanguage()
Definition bot.php:239
static validateBotType()
Definition bot.php:228
static validateToClass()
Definition bot.php:182
static needCacheInvalidate(array $updatedFields)
Definition bot.php:267
static onAfterDelete(Event $event)
Definition bot.php:259
static onAfterUpdate(\Bitrix\Main\ORM\Event $event)
Definition bot.php:246
static validateModuleId()
Definition bot.php:193
static getTableName()
Definition bot.php:45