1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
eventbuilderfromarray.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Core\Builders;
4
5use Bitrix\Calendar\Core\Base\BaseException;
6use Bitrix\Calendar\Core\Base\DateTimeZone;
7use Bitrix\Calendar\Core\Event;
8use Bitrix\Calendar\Core\Event\Properties\AttendeeCollection;
9use Bitrix\Calendar\Core\Base\Date;
10use Bitrix\Calendar\Core\Event\Properties\Location;
11use Bitrix\Calendar\Core\Event\Properties\MeetingDescription;
12use Bitrix\Calendar\Core\Event\Properties\RecurringEventRules;
13use Bitrix\Calendar\Core\Event\Properties\Relations;
14use Bitrix\Calendar\Core\Event\Properties\RemindCollection;
15use Bitrix\Calendar\Core\eventoption\EventOption;
16use Bitrix\Calendar\Core\Mappers\Factory;
17use Bitrix\Calendar\Core\Role\Helper;
18use Bitrix\Calendar\Core\Role\Role;
19use Bitrix\Calendar\Core\Role\User;
20use Bitrix\Calendar\Core\Section\Section;
21use Bitrix\Calendar\Util;
22use Bitrix\Main\ArgumentException;
23use Bitrix\Main\DI\ServiceLocator;
24use Bitrix\Main\ObjectException;
25use Bitrix\Main\ObjectPropertyException;
26use Bitrix\Main\SystemException;
27use DateTime;
28
29IncludeModuleLangFile($_SERVER['DOCUMENT_ROOT'] . BX_ROOT . '/modules/calendar/classes/general/calendar.php');
30
32{
36 protected $fields;
37
41 public function __construct(array $fields)
42 {
43 $this->fields = $fields;
44 $this->prepareRecurrenceRuleField();
45 }
46
47 private function prepareRecurrenceRuleField(): void
48 {
49 if (!empty($this->fields['RRULE']) && is_string($this->fields['RRULE']))
50 {
51 $result = [];
52 foreach (explode(';', $this->fields['RRULE']) as $item) {
53 if (!empty($item))
54 {
55 [$key, $value] = explode('=', $item);
56 $result[$key] = $value;
57 }
58 }
59 $this->fields['RRULE'] = $result;
60 }
61 }
62
66 protected function getName(): string
67 {
68 return $this->fields['NAME'] ?? '';
69 }
70
74 protected function getStartTimezone(): ?DateTimeZone
75 {
76 if (!isset($this->fields['TZ_FROM']))
77 {
78 return null;
79 }
80
81 return new DateTimeZone(Util::prepareTimezone($this->fields['TZ_FROM']));
82 }
83
87 protected function getEndTimezone(): ?DateTimeZone
88 {
89 if (!isset($this->fields['TZ_TO']))
90 {
91 return null;
92 }
93
94 return new DateTimeZone(Util::prepareTimezone($this->fields['TZ_TO']));
95 }
96
103 {
104 if (!empty($this->fields['RRULE']))
105 {
106 if (is_string($this->fields['RRULE']))
107 {
108 $this->fields['RRULE'] = \CCalendarEvent::convertDateToCulture($this->fields['RRULE']);
109 }
110 elseif (is_array($this->fields['RRULE']) && !empty($this->fields['RRULE']['UNTIL']))
111 {
112 $this->fields['RRULE']['UNTIL'] = \CCalendarEvent::convertDateToCulture($this->fields['RRULE']['UNTIL']);
113 }
114
115 return $this->prepareRecurringRule($this->fields['RRULE']);
116 }
117 else
118 {
119 return null;
120 }
121 }
122
126 protected function getLocation(): ?Location
127 {
128 return $this->prepareLocation($this->fields['LOCATION'] ?? null);
129 }
130
135 protected function getStart(): Date
136 {
137 return new Date(
139 $this->fields['DATE_FROM'] ?? null,
140 $this->isFullDay(),
141 $this->fields['TZ_FROM'] ?? null
142 )
143 );
144 }
145
150 protected function getEnd(): Date
151 {
152 return new Date(
154 $this->fields['DATE_TO'] ?? null,
155 $this->isFullDay(),
156 $this->fields['TZ_TO'] ?? null,
157 )
158 );
159 }
160
161 private function isFullDay(): bool
162 {
163 return (isset($this->fields['SKIP_TIME']) && $this->fields['SKIP_TIME'] === 'Y')
164 || (isset($this->fields['DT_SKIP_TIME']) && $this->fields['DT_SKIP_TIME'] === 'Y');
165 }
166
171 protected function getOriginalDate(): ?Date
172 {
173 if (!isset($this->fields['ORIGINAL_DATE_FROM']))
174 {
175 return null;
176 }
177
178 return new Date(Util::getDateObject(
179 $this->fields['ORIGINAL_DATE_FROM'],
180 ($this->fields['SKIP_TIME'] ?? null) === 'Y' || ($this->fields['DT_SKIP_TIME'] ?? null) === 'Y',
181 $this->fields['TZ_FROM'] ?? null
182 ));
183 }
184
188 protected function getFullDay(): bool
189 {
190 return $this->isFullDay();
191 }
192
196 protected function getAttendees(): ?AttendeeCollection
197 {
198 $collection = new AttendeeCollection();
199
200 if (isset($this->fields['ATTENDEES_CODES']))
201 {
202 if (is_string($this->fields['ATTENDEES_CODES']))
203 {
204 $collection->setAttendeesCodes(explode(',', $this->fields['ATTENDEES_CODES']));
205 }
206 else if (is_array($this->fields['ATTENDEES_CODES']))
207 {
208 $collection->setAttendeesCodes($this->fields['ATTENDEES_CODES']);
209 }
210 }
211
212 if (isset($this->fields['ATTENDEES']) && is_array($this->fields['ATTENDEES']))
213 {
214 $collection->setAttendeesId($this->fields['ATTENDEES']);
215 }
216 else
217 {
218 $collection->setAttendeesId([(int)$this->fields['OWNER_ID']]);
219 }
220
221
222 return $collection;
223 }
224
229 protected function getReminders(): RemindCollection
230 {
231 if (isset($this->fields['REMIND']) && is_string($this->fields['REMIND']))
232 {
233 $this->fields['REMIND'] = unserialize($this->fields['REMIND'], ['allowed_classes' => false]);
234 }
235
236 if (!isset($this->fields['REMIND']) || !is_array($this->fields['REMIND']))
237 {
238 return new RemindCollection();
239 }
240
241 $eventStart = $this->getStart();
242
243 $collection = new RemindCollection();
244 $collection->setEventStart($eventStart);
245
246 foreach ($this->fields['REMIND'] as $remind)
247 {
248 if ($remind['type'] === Event\Tools\Dictionary::REMIND_UNIT['date'])
249 {
250 $collection->add((new Event\Properties\Remind())
251 ->setSpecificTime(
252 new Date(
254 $remind['value'],
255 false,
256 $this->fields['TZ_FROM']
257 )
258 )
259 )
260 ->setEventStart($eventStart)
261 );
262 }
263 elseif ($remind['type'] === Event\Properties\Remind::UNIT_DAY_BEFORE)
264 {
265 $collection->add((new Event\Properties\Remind())
266 ->setEventStart($eventStart)
267 ->setSpecificTime(
268 (new Date(
270 $eventStart->toString(),
271 false,
272 $this->fields['TZ_FROM'])
273 ))
274 ->resetTime()
275 ->sub("{$remind['before']} days")
276 ->add("{$remind['time']} minutes")
277 )
278 ->setDaysBefore($remind['before'])
279 );
280 }
281 else
282 {
283 $collection->add((new Event\Properties\Remind())
284 ->setTimeBeforeEvent(
285 $remind['count'],
286 Event\Tools\Dictionary::REMIND_UNIT[$remind['type']]
287 ?? Event\Properties\Remind::UNIT_MINUTES
288 )
289 ->setEventStart($eventStart)
290 );
291 }
292 }
293
294 return $collection;
295 }
296
300 protected function getDescription(): ?string
301 {
302 return $this->fields['DESCRIPTION'] ?? null;
303 }
304
311 protected function getSection(): Section
312 {
313 $sectionId = $this->fields['SECTION_ID'] ??
314 (is_array($this->fields['SECTIONS'])
315 ? (int)$this->fields['SECTIONS'][0]
316 : null
317 );
318
319 if ($sectionId)
320 {
321 return (new \Bitrix\Calendar\Core\Mappers\Section())->getMap([
322 '=ID' => $sectionId
323 ])->fetch();
324 }
325
326 throw new BuilderException('it is impossible to find the section');
327 }
328
332 protected function getColor(): ?string
333 {
334 return $this->fields['COLOR'] ?? null;
335 }
336
340 protected function getTransparency(): ?string
341 {
342 return $this->fields['TRANSPARENT'] ?? null;
343 }
344
348 protected function getImportance(): ?string
349 {
350 return $this->fields['IMPORTANCE'] ?? null;
351 }
352
356 protected function getAccessibility(): ?string
357 {
358 return $this->fields['ACCESSIBILITY'] ?? null;
359 }
360
364 protected function getIsPrivate(): bool
365 {
366 return $this->fields['PRIVATE_EVENT'] ?? false;
367 }
368
375 protected function getEventHost(): ?Role
376 {
377 if (empty($this->fields['MEETING_HOST']))
378 {
379 return null;
380 }
381
382 try
383 {
384 return Helper::getUserRole($this->fields['MEETING_HOST']);
385 }
386 catch (BaseException $exception)
387 {
388 return null;
389 }
390 }
391
398 protected function getCreator(): ?Role
399 {
400 if (empty($this->fields['CREATED_BY']))
401 {
402 return null;
403 }
404
405 try
406 {
407 return Helper::getUserRole($this->fields['CREATED_BY']);
408 }
409 catch (BaseException $exception)
410 {
411 return null;
412 }
413 }
414
421 protected function getOwner(): ?Role
422 {
423 if (empty($this->fields['OWNER_ID']))
424 {
425 return null;
426 }
427 if (empty($this->fields['CAL_TYPE']))
428 {
429 $this->fields['CAL_TYPE'] = User::TYPE;
430 }
431
432 try
433 {
434 return Helper::getRole($this->fields['OWNER_ID'], $this->fields['CAL_TYPE']);
435 }
436 catch (BaseException $exception)
437 {
438 return null;
439 }
440 }
441
446 {
447 return $this->prepareMeetingDescription($this->fields['MEETING'] ?? null);
448 }
449
453 protected function getVersion(): int
454 {
455 return (int)($this->fields['VERSION'] ?? null);
456 }
457
461 protected function getCalendarType(): ?string
462 {
463 return $this->fields['CAL_TYPE'] ?? null;
464 }
465
469 protected function getUid(): ?string
470 {
471 return $this->fields['DAV_XML_ID'] ?? null;
472 }
473
477 protected function isDeleted(): bool
478 {
479 return isset($this->fields['DELETED']) && $this->fields['DELETED'] === 'Y';
480 }
481
485 protected function isActive(): bool
486 {
487 return isset($this->fields['ACTIVE']) && $this->fields['ACTIVE'] === 'Y';
488 }
489
493 protected function getRecurrenceId(): ?int
494 {
495 return $this->fields['RECURRENCE_ID'] ?? null;
496 }
497
502 protected function getDateCreate(): ?Date
503 {
504 if (!isset($this->fields['DATE_CREATE']))
505 {
506 return null;
507 }
508
509 return new Date(Util::getDateObject(
510 $this->fields['DATE_CREATE'],
511 false,
512 (new DateTime())->getTimezone()->getName()
513 ));
514 }
515
520 protected function getDateModified(): ?Date
521 {
522 if (!isset($this->fields['TIMESTAMP_X']))
523 {
524 return null;
525 }
526
527 return new Date(Util::getDateObject(
528 $this->fields['TIMESTAMP_X'],
529 false,
530 (new DateTime())->getTimezone()->getName()
531 ));
532 }
533
539 {
540 if (empty($this->fields['EXDATE']))
541 {
543 }
544
546 if (is_string($this->fields['EXDATE']))
547 {
548 foreach (explode(";", $this->fields['EXDATE']) as $exDate)
549 {
550 $collection->add($this->createDateForRecurrence($exDate));
551 }
552 }
553
554 else if (is_array($this->fields['EXDATE']))
555 {
556 foreach ($this->fields['EXDATE'] as $exDate)
557 {
558 $collection->add($this->createDateForRecurrence($exDate));
559 }
560 }
561
562 return $collection;
563 }
564
568 protected function getId(): ?int
569 {
570 return $this->fields['ID'] ?? null;
571 }
572
576 protected function getParentId(): ?int
577 {
578 return $this->fields['PARENT_ID'] ?? null;
579 }
580
584 protected function isMeeting(): bool
585 {
586 return (bool)($this->fields['IS_MEETING'] ?? null);
587 }
588
592 protected function getMeetingStatus(): ?string
593 {
594 return $this->fields['MEETING_STATUS'] ?? null;
595 }
596
600 protected function getRelations(): ?Relations
601 {
602 return $this->prepareRelations($this->fields['RELATIONS'] ?? null);
603 }
604
608 protected function getSpecialLabel(): ?string
609 {
610 return $this->fields['EVENT_TYPE'] ?? null;
611 }
612
613 protected function getEventOption(): ?EventOption
614 {
615 if ($eventId = $this->fields['ID'] ?? null)
616 {
618 $mapper = ServiceLocator::getInstance()->get('calendar.service.mappers.factory');
619
620 return $mapper->getEventOption()->getMap(['=EVENT_ID' => $eventId])->fetch();
621 }
622
623 return null;
624 }
625
626 protected function getDtLength(): ?int
627 {
628 return $this->fields['DT_LENGTH'] ?? null;
629 }
630
631 protected function getCollabId(): ?int
632 {
633 return $this->fields['COLLAB_ID'] ?? null;
634 }
635}
const BX_ROOT
Определения bx_root.php:3
prepareLocation($locationData='')
Определения eventbuilder.php:172
prepareMeetingDescription($meeting=null)
Определения eventbuilder.php:445
createDateForRecurrence(string $date)
Определения eventbuilder.php:523
prepareRecurringRule($ruleData=null)
Определения eventbuilder.php:110
static prepareTimezone(?string $tz=null)
Определения util.php:80
static getDateObject(string $date=null, ?bool $fullDay=true, ?string $tz='UTC')
Определения util.php:107
Определения date.php:9
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257