Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
settings.php
1<?php
10
11
13{
14 protected $endpoint = array('MODULE_ID' => '', 'CODE' => '');
15 protected $fields = array();
16 protected $eventOccur = true;
17 protected $preventEmail = false;
18 protected $intervalValue = 0;
19 protected $intervalType = 'M';
20 protected $typeStart = true;
21 protected $isClosedTrigger = false;
22 protected $runForOldData = false;
23 protected $wasRunForOldData = false;
24 protected $closedTriggerTime = '';
26 protected $eventModuleId = '';
27 protected $eventType = '';
28
29 /*
30 array(
31 'MODULE_ID' => '',
32 'CODE' => 'order_cancel',
33 'FIELDS' => array(
34 'BASKET_PRODUCT_ID' => 99
35 ),
36 'IS_TYPE_START' => true,
37 'IS_PREVENT_EMAIL' => true,
38 'IS_EVENT_OCCUR' => true,
39 'SEND_INTERVAL_UNIT' => 'M',
40 'SEND_INTERVAL' => 0,
41 'IS_CLOSED_TRIGGER' => false,
42 'CLOSED_TRIGGER_INTERVAL' => 0,
43 'CLOSED_TRIGGER_TIME' => '',
44 'RUN_FOR_OLD_DATA' => '',
45 'WAS_RUN_FOR_OLD_DATA' => '',
46 )
47 */
48
49 public function __construct(array $settings = null)
50 {
51 if(empty($settings))
52 return;
53
54 $this->setEndpoint($settings['CODE'], $settings['MODULE_ID']);
55 $this->setFields($settings['FIELDS']);
56
57 $this->setTypeStart($settings['IS_TYPE_START']);
58 $this->setPreventEmail($settings['IS_PREVENT_EMAIL']);
59 $this->setEventOccur($settings['IS_EVENT_OCCUR']);
60 $this->setInterval($settings['SEND_INTERVAL'], $settings['SEND_INTERVAL_UNIT']);
61
62 $this->setClosedTrigger($settings['IS_CLOSED_TRIGGER']);
63 $this->setClosedTriggerInterval($settings['CLOSED_TRIGGER_INTERVAL']);
64 $this->setClosedTriggerTime($settings['CLOSED_TRIGGER_TIME']);
65
66 $this->setEventModuleId($settings['EVENT_MODULE_ID']);
67 $this->setEventType($settings['EVENT_TYPE']);
68
69 $this->setRunForOldData($settings['RUN_FOR_OLD_DATA']);
70 $this->setWasRunForOldData($settings['WAS_RUN_FOR_OLD_DATA']);
71 }
72
73 public static function getArrayFromTrigger(Base $trigger)
74 {
75 return array(
76 'MODULE_ID' => $trigger->getModuleId(),
77 'CODE' => $trigger->getCode(),
78 'NAME' => $trigger->getName(),
79 'IS_CLOSED_TRIGGER' => ($trigger->isClosed() ? 'Y' : 'N'),
80 'CAN_RUN_FOR_OLD_DATA' => ($trigger->canRunForOldData() ? 'Y' : 'N'),
81 'CLOSED_TRIGGER_INTERVAL' => '1440',
82 'CLOSED_TRIGGER_TIME' => '00:00',
83 'EVENT_MODULE_ID' => $trigger->getEventModuleId(),
84 'EVENT_TYPE' => $trigger->getEventType(),
85 );
86 }
87
88 public function getArray()
89 {
90 return array(
91 'MODULE_ID' => $this->getEndpoint('MODULE_ID'),
92 'CODE' => $this->getEndpoint('CODE'),
93 'FIELDS' => $this->getFields(),
94 'IS_TYPE_START' => $this->isTypeStart(),
95 'IS_PREVENT_EMAIL' => $this->isPreventEmail(),
96 'IS_EVENT_OCCUR' => $this->isEventOccur(),
97 'SEND_INTERVAL_UNIT' => $this->getIntervalType(),
98 'SEND_INTERVAL' => $this->getIntervalValue(),
99 'IS_CLOSED_TRIGGER' => $this->isClosedTrigger(),
100 'CLOSED_TRIGGER_INTERVAL' => $this->getClosedTriggerInterval(),
101 'CLOSED_TRIGGER_TIME' => $this->getClosedTriggerTime(),
102 'RUN_FOR_OLD_DATA' => $this->canRunForOldData(),
103 'WAS_RUN_FOR_OLD_DATA' => $this->wasRunForOldData(),
104 'EVENT_MODULE_ID' => $this->getEventModuleId(),
105 'EVENT_TYPE' => $this->getEventType(),
106 );
107 }
108
112 public function getTriggerId()
113 {
114 $endpoint = $this->getEndpoint();
115 if(!empty($endpoint['CODE']))
116 $triggerId = $endpoint['MODULE_ID'] . '_' . $endpoint['CODE'];
117 else
118 $triggerId = '';
119
120 return $triggerId;
121 }
122
127 public function getEndpoint($key = null)
128 {
129 if($key)
130 {
131 return (isset($this->endpoint[$key]) ? $this->endpoint[$key] : '');
132 }
133 else
134 return $this->endpoint;
135 }
136
141 public function setEndpoint($code, $moduleId)
142 {
143 if(!empty($code))
144 {
145 $this->endpoint['CODE'] = $code;
146 if(!empty($moduleId))
147 $this->endpoint['MODULE_ID'] = $moduleId;
148 }
149 }
150
154 public function getFields()
155 {
156 return $this->fields;
157 }
158
162 public function setFields($fields)
163 {
164 $this->fields = $fields;
165 }
166
171 public function setTypeStart($state)
172 {
173 if(is_string($state))
174 {
175 $state = ($state == 'Y' ? true : false);
176 }
177
178 $this->typeStart = (bool) $state;
179 }
180
184 public function isTypeStart()
185 {
186 return $this->typeStart;
187 }
188
193 public function setEventOccur($state)
194 {
195 if(is_string($state))
196 {
197 $state = ($state == 'Y' ? true : false);
198 }
199
200 $this->eventOccur = (bool) $state;
201 }
202
206 public function isEventOccur()
207 {
208 return $this->eventOccur;
209 }
210
214 public function isPreventEmail()
215 {
216 return $this->preventEmail;
217 }
218
223 public function setPreventEmail($state)
224 {
225 if(is_string($state))
226 {
227 $state = ($state == 'Y' ? true : false);
228 }
229
230
231 $this->preventEmail = (bool) $state;
232 }
233
237 public function isClosedTrigger()
238 {
240 }
241
246 public function setClosedTrigger($state)
247 {
248 if(is_string($state))
249 {
250 $state = ($state == 'Y' ? true : false);
251 }
252
253 $this->isClosedTrigger = (bool) $state;
254 }
255
259 public function getClosedTriggerTime()
260 {
261 if($this->isClosedTrigger())
262 {
264 }
265 else
266 {
267 return '';
268 }
269 }
270
274 public function setClosedTriggerTime($time)
275 {
276 $this->closedTriggerTime = (string) $time;
277 }
278
282 public function getClosedTriggerInterval()
283 {
284 if($this->isClosedTrigger())
285 return (int) $this->closedTriggerInterval;
286 else
287 return 0;
288 }
289
293 public function setClosedTriggerInterval($interval)
294 {
295 $this->closedTriggerInterval = (int) $interval;
296 }
297
302 public function setRunForOldData($state)
303 {
304 if(is_string($state))
305 {
306 $state = ($state == 'Y' ? true : false);
307 }
308
309 $this->runForOldData = (bool) $state;
310 }
311
315 public function canRunForOldData()
316 {
318 }
319
324 public function setWasRunForOldData($state)
325 {
326 if(is_string($state))
327 {
328 $state = ($state == 'Y' ? true : false);
329 }
330
331 $this->wasRunForOldData = (bool) $state;
332 }
333
337 public function wasRunForOldData()
338 {
340 }
341
346 public function setEventModuleId($moduleId)
347 {
348 $this->eventModuleId = $moduleId;
349 }
350
354 public function getEventModuleId()
355 {
357 }
358
363 public function setEventType($eventType)
364 {
365 $this->eventType = $eventType;
366 }
367
371 public function getEventType()
372 {
373 return $this->eventType;
374 }
375
379 public function getFullEventType()
380 {
381 if(!empty($this->eventModuleId) && !empty($this->eventType))
382 return $this->eventModuleId . '_' . $this->eventType;
383 else
384 return '';
385 }
386
391 public function setInterval($value = 0, $type = 'H')
392 {
393 $this->setIntervalValue($value);
394 $this->setIntervalType($type);
395 }
396
400 public function getInterval()
401 {
402 $value = $this->getIntervalValue();
403 if($value <= 0) return 0;
404
405 $type = $this->getIntervalType();
406 switch($type)
407 {
408 case 'H': // hours
409 $koeff = 60;
410 break;
411 case 'D': // days
412 $koeff = 60*24;
413 break;
414 case 'M': // minutes
415 default:
416 $koeff = 1;
417 }
418
419 return $value * $koeff;
420 }
421
425 public function getIntervalValue()
426 {
428 }
429
433 public function getIntervalType()
434 {
435 return $this->intervalType;
436 }
437
442 {
443 $this->intervalValue = (int) $intervalValue;
444 }
445
450 {
451 $this->intervalType = $intervalType;
452 }
453}
static getArrayFromTrigger(Base $trigger)
Definition settings.php:73
setInterval($value=0, $type='H')
Definition settings.php:391
__construct(array $settings=null)
Definition settings.php:49
setEndpoint($code, $moduleId)
Definition settings.php:141
setIntervalValue($intervalValue)
Definition settings.php:441