Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
group.php
1<?php
8namespace Bitrix\Sender;
9
12use Bitrix\Main\Entity\ReferenceField;
18
19Loc::loadMessages(__FILE__);
20
22{
23 public const STATUS_NEW = 'N';
24 public const STATUS_IN_PROGRESS = 'P';
25 public const STATUS_READY_TO_USE = 'R';
26 public const STATUS_DONE = 'D';
30 public static function getTableName()
31 {
32 return 'b_sender_group';
33 }
34
38 public static function getMap()
39 {
40 return array(
41 'ID' => array(
42 'data_type' => 'integer',
43 'primary' => true,
44 'autocomplete' => true,
45 ),
46 'CODE' => array(
47 'data_type' => 'string',
48 'validation' => function ()
49 {
50 return array(
51 //new Entity\Validator\Unique
52 );
53 }
54 ),
55 'NAME' => array(
56 'data_type' => 'string',
57 'required' => true,
58 'title' => Loc::getMessage('SENDER_ENTITY_GROUP_FIELD_TITLE_NAME')
59 ),
60 'DATE_INSERT' => array(
61 'data_type' => 'datetime',
62 'required' => true,
63 'default_value' => new Type\DateTime(),
64 ),
65 'DATE_UPDATE' => array(
66 'data_type' => 'datetime',
67 'required' => true,
68 'default_value' => new Type\DateTime(),
69 ),
70 'DATE_USE' => array(
71 'data_type' => 'datetime',
72 ),
73 'DATE_USE_EXCLUDE' => array(
74 'data_type' => 'datetime',
75 ),
76 'ACTIVE' => array(
77 'data_type' => 'boolean',
78 'required' => true,
79 'default_value' => 'Y',
80 'values' => array('N', 'Y'),
81 ),
82 'HIDDEN' => array(
83 'data_type' => 'boolean',
84 'required' => true,
85 'default_value' => 'N',
86 'values' => array('N', 'Y'),
87 ),
88 'IS_SYSTEM' => array(
89 'data_type' => 'boolean',
90 'required' => true,
91 'default_value' => 'N',
92 'values' => array('N', 'Y'),
93 ),
94 'DESCRIPTION' => array(
95 'data_type' => 'string',
96 'title' => Loc::getMessage('SENDER_ENTITY_GROUP_FIELD_TITLE_DESCRIPTION'),
97 'validation' => array(__CLASS__, 'validateDescription'),
98 ),
99 'SORT' => array(
100 'data_type' => 'integer',
101 'required' => true,
102 'default_value' => 100,
103 'title' => Loc::getMessage('SENDER_ENTITY_GROUP_FIELD_TITLE_SORT')
104 ),
105 'ADDRESS_COUNT' => array(
106 'data_type' => 'integer',
107 'default_value' => 0,
108 'required' => true,
109 ),
110 'USE_COUNT' => array(
111 'data_type' => 'integer',
112 'default_value' => 0,
113 'required' => true,
114 ),
115 'USE_COUNT_EXCLUDE' => array(
116 'data_type' => 'integer',
117 'default_value' => 0,
118 'required' => true,
119 ),
120 'GROUP_CONNECTOR' => array(
121 'data_type' => 'Bitrix\Sender\GroupConnectorTable',
122 'reference' => array('=this.ID' => 'ref.GROUP_ID'),
123 ),
124 'MAILING_GROUP' => array(
125 'data_type' => 'Bitrix\Sender\MailingGroupTable',
126 'reference' => array('=this.ID' => 'ref.GROUP_ID'),
127 ),
128 'DEAL_CATEGORY' => new ReferenceField(
129 'DEAL_CATEGORY',
130 GroupDealCategoryTable::class,
131 [
132 '=this.ID' => 'ref.GROUP_ID',
133 ],
134 ['join_type' => 'LEFT']
135 ),
136 'STATUS' => [
137 'data_type' => 'string',
138 'default_value' => self::STATUS_NEW,
139 'values' => [
140 self::STATUS_NEW,
141 self::STATUS_IN_PROGRESS,
142 self::STATUS_READY_TO_USE,
143 self::STATUS_DONE,
144 ]
145 ],
146 );
147 }
148
154 public static function validateDescription()
155 {
156 return array(
157 new Entity\Validator\Length(null, 2000),
158 );
159 }
160
165 public static function onAfterDelete(Entity\Event $event)
166 {
167 $result = new Entity\EventResult;
168 $data = $event->getParameters();
169
170 $primary = array('GROUP_ID' => $data['primary']['ID']);
171 GroupConnectorTable::delete($primary);
172 GroupCounterTable::deleteList($primary);
173 SegmentDataBuilder::clearGroupBuilding((int) $data['primary']['ID']);
174
175 return $result;
176 }
177
178 public static function onBeforeUpdate(Entity\Event $event)
179 {
180 $result = new Entity\EventResult;
181
182 $data = $event->getParameters();
183 if (array_key_exists('DATE_UPDATE', $data['fields']))
184 {
185 $data['fields']['DATE_UPDATE'] = new Type\DateTime();
186 $result->modifyFields($data['fields']);
187 }
188
189 if (array_key_exists('CODE', $data['fields']) && is_null($data['fields']['CODE']))
190 {
191 $data['fields']['CODE'] = new SqlExpression('NULL');
192 $result->modifyFields($data['fields']);
193 }
194
195 return $result;
196 }
197}
198
199
201{
205 public static function getTableName()
206 {
207 return 'b_sender_group_connector';
208 }
209
213 public static function getMap()
214 {
215 return array(
216 'GROUP_ID' => array(
217 'data_type' => 'integer',
218 'primary' => true,
219 ),
220 'NAME' => array(
221 'data_type' => 'string',
222 ),
223 'ENDPOINT' => array(
224 'data_type' => 'string',
225 'required' => true,
226 'serialized' => true,
227 ),
228 'ADDRESS_COUNT' => array(
229 'data_type' => 'integer',
230 'default_value' => 0,
231 ),
232 'GROUP' => array(
233 'data_type' => 'Bitrix\Sender\GroupTable',
234 'reference' => array('=this.GROUP_ID' => 'ref.ID'),
235 ),
236 'FILTER_ID' => array(
237 'data_type' => 'string',
238 ),
239 );
240 }
241
242 public static function onAfterUpdate(Entity\Event $event)
243 {
244 $result = new Entity\EventResult;
245
246 $data = $event->getParameters();
247 $groupId = $data['fields']['GROUP_ID'];
248
249 SegmentDataBuilder::actualize($groupId, false);
250 return $result;
251 }
252}
253
254
255
273{
277 public static function getTableName()
278 {
279 return 'b_sender_group_deal_category';
280 }
281
285 public static function getMap()
286 {
287 return array(
288 'GROUP_ID' => array(
289 'data_type' => 'integer',
290 'primary' => true,
291 ),
292 'GROUP' => array(
293 'data_type' => 'Bitrix\Sender\GroupTable',
294 'reference' => array('=this.GROUP_ID' => 'ref.ID'),
295 ),
296 'DEAL_CATEGORY_ID' => array(
297 'data_type' => 'integer',
298 'primary' => true,
299 ),
300 );
301 }
302
303
311 public static function deleteList(array $filter)
312 {
313 $entity = static::getEntity();
314 $connection = $entity->getConnection();
315
316 \CTimeZone::disable();
317 $sql = sprintf(
318 'DELETE FROM %s WHERE %s',
319 $connection->getSqlHelper()->quote($entity->getDbTableName()),
320 Query::buildFilterSql($entity, $filter)
321 );
322 $res = $connection->query($sql);
323 \CTimeZone::enable();
324
325 return $res;
326 }
327}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static onAfterUpdate(Entity\Event $event)
Definition group.php:242
static deleteList(array $filter)
Definition group.php:311
static onBeforeUpdate(Entity\Event $event)
Definition group.php:178
static validateDescription()
Definition group.php:154
static onAfterDelete(Entity\Event $event)
Definition group.php:165