Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
delayinterval.php
1<?php
3
5
7{
8 public const TYPE_BEFORE = 'before';
9 public const TYPE_AFTER = 'after';
10 public const TYPE_IN = 'in';
11
12 protected $type = 'after'; //TYPE_AFTER
13 protected $value;
14 protected $valueType;
15 protected $basis;
16 protected $workTime = false;
17 protected bool $waitWorkDay = false;
18 protected ?array $inTime = null;
19 protected bool $activated = true;
20
25 public function __construct(array $params = null)
26 {
27 if ($params)
28 {
29 if (isset($params['type']))
30 {
31 $this->setType($params['type']);
32 }
33 if (isset($params['value']))
34 {
35 $this->setValue($params['value']);
36 }
37 if (isset($params['valueType']))
38 {
39 $this->setValueType($params['valueType']);
40 }
41
42 $this->setBasis(isset($params['basis']) ? $params['basis'] : Helper::CURRENT_DATETIME_BASIS);
43
44 if (isset($params['workTime']))
45 {
46 $this->setWorkTime($params['workTime']);
47 }
48
49 if (isset($params['waitWorkDay']))
50 {
51 $this->setWaitWorkDay($params['waitWorkDay']);
52 }
53
54 if (isset($params['inTime']) && is_array($params['inTime']))
55 {
56 $this->setInTime($params['inTime']);
57 }
58 }
59 }
60
65 public static function createFromActivityProperties(array $properties)
66 {
67 $params = [];
68 if (is_array($properties))
69 {
70 if (isset($properties['TimeoutTime']))
71 {
72 $params = Helper::parseDateTimeInterval($properties['TimeoutTime']);
73 }
74 elseif
75 (
76 isset($properties['TimeoutDuration'])
77 && isset($properties['TimeoutDurationType'])
78 && is_numeric($properties['TimeoutDuration'])
79 && $properties['TimeoutDurationType'] !== 's'
80 )
81 {
82 if ($properties['TimeoutDurationType'] === 'm')
83 {
84 $properties['TimeoutDurationType'] = 'i';
85 }
86 $params = array(
87 'type' => static::TYPE_AFTER,
88 'value' => (int)$properties['TimeoutDuration'],
89 'valueType' => $properties['TimeoutDurationType'],
90 );
91 }
92
93 if (!empty($properties['WaitWorkDayUser']))
94 {
95 $params['waitWorkDay'] = true;
96 }
97 }
98
99 return new static($params);
100 }
101
105 public function getType()
106 {
107 return $this->type;
108 }
109
114 public function setType($type)
115 {
116 $type = (string)$type;
117 if ($type === static::TYPE_BEFORE || $type === static::TYPE_AFTER || $type === static::TYPE_IN)
118 {
119 $this->type = $type;
120 }
121
122 return $this;
123 }
124
128 public function getValue()
129 {
130 return $this->value;
131 }
132
137 public function setValue($value)
138 {
139 $this->value = (int)$value;
140
141 return $this;
142 }
143
147 public function getValueType()
148 {
149 return $this->valueType;
150 }
151
156 public function setValueType($valueType)
157 {
158 if ($valueType === 'i' || $valueType === 'h' || $valueType === 'd')
159 {
160 $this->valueType = $valueType;
161 }
162
163 return $this;
164 }
165
169 public function getBasis()
170 {
171 return $this->basis;
172 }
173
178 public function setBasis($basis)
179 {
180 $this->basis = $basis;
181
182 return $this;
183 }
184
188 public function isWorkTime()
189 {
190 return $this->workTime;
191 }
192
197 public function setWorkTime($flag)
198 {
199 $this->workTime = (bool)$flag;
200 return $this;
201 }
202
203 public function isWaitWorkDay(): bool
204 {
205 return $this->waitWorkDay;
206 }
207
211 public function setWaitWorkDay(bool $flag)
212 {
213 $this->waitWorkDay = $flag;
214
215 return $this;
216 }
217
221 public function setInTime(?array $inTime)
222 {
223 $this->inTime = $inTime;
224
225 return $this;
226 }
227
228 public function getInTime(): ?array
229 {
230 return $this->inTime;
231 }
232
233 public function setActivated(bool $activated): void
234 {
235 $this->activated = $activated;
236 }
237
238 public function isActivated(): bool
239 {
240 return $this->activated;
241 }
242
247 public function toArray()
248 {
249 return [
250 'type' => $this->getType(),
251 'value' => $this->getValue(),
252 'valueType' => $this->getValueType(),
253 'basis' => $this->getBasis(),
254 'workTime' => $this->isWorkTime(),
255 'waitWorkDay' => $this->isWaitWorkDay(),
256 'inTime' => $this->getInTime(),
257 ];
258 }
259
265 public function toActivityProperties(array $documentType)
266 {
267 $properties = [
268 'TimeoutTimeIsLocal' => 'N',
269 ];
270
271 $worker = Helper::getResponsibleUserExpression($documentType);
272
273 if (
275 && $this->getType() === static::TYPE_AFTER
276 && !$this->isWorkTime()
277 && !$this->getInTime()
278 )
279 {
280 $valueType = $this->getValueType();
281 if ($valueType === 'i')
282 {
283 $valueType = 'm';
284 }
285
286 $properties['TimeoutDuration'] = $this->getValue();
287 $properties['TimeoutDurationType'] = $valueType;
288 }
289 elseif ($this->getType() === static::TYPE_IN && !$this->isWorkTime() && !$this->getInTime())
290 {
291 $properties['TimeoutTime'] = $this->getBasis();
292 }
293 else
294 {
295 $intervalProperties = $this->toArray();
296 $intervalProperties['worker'] = $worker;
297
298 $properties['TimeoutTime'] = Helper::getDateTimeIntervalString($intervalProperties);
299 }
300
301 if ($this->isWaitWorkDay())
302 {
303 $properties['WaitWorkDayUser'] = $worker;
304 }
305
306 return $properties;
307 }
308
313 public function isNow()
314 {
315 return (
316 !$this->isWorkTime()
317 && !$this->isWaitWorkDay()
318 && !$this->getInTime()
320 && $this->getValue() === 0
321 );
322 }
323}
static createFromActivityProperties(array $properties)
static getResponsibleUserExpression(array $documentType)
Definition helper.php:108
static parseDateTimeInterval($interval)
Definition helper.php:632
static getDateTimeIntervalString($interval)
Definition helper.php:730