1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
eventbuilder.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Core\Builders;
4
5use Bitrix\Calendar\Core\Base\BaseException;
6use Bitrix\Calendar\Core\Base\Date;
7use Bitrix\Calendar\Core\Base\DateTimeZone;
8use Bitrix\Calendar\Core\Event\Event;
9use Bitrix\Calendar\Core\Event\Properties\AttendeeCollection;
10use Bitrix\Calendar\Core\Event\Properties\ExcludedDatesCollection;
11use Bitrix\Calendar\Core\Event\Properties\Location;
12use Bitrix\Calendar\Core\Event\Properties\MeetingDescription;
13use Bitrix\Calendar\Core\Event\Properties\RecurringEventRules;
14use Bitrix\Calendar\Core\Event\Properties\Relations;
15use Bitrix\Calendar\Core\Event\Properties\RemindCollection;
16use Bitrix\Calendar\Core\eventoption\EventOption;
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\EO_User;
24use Bitrix\Main\ObjectException;
25use Bitrix\Main\ObjectPropertyException;
26use Bitrix\Main\SystemException;
27use Bitrix\Main\UserTable;
28
29abstract class EventBuilder implements Builder
30{
31 private Event $event;
32
33 public function setBaseEvent(Event $event): self
34 {
35 $this->event = $event;
36
37 return $this;
38 }
39
44 public function build(): Event
45 {
46 return $this->getBaseEvent()
47 ->setId($this->getId())
48 ->setParentId($this->getParentId())
49 ->setName($this->getName())
50 ->setRecurringRule($this->getRecurringRule())
51 ->setLocation($this->getLocation())
52 ->setStart($this->getStart())
53 ->setStartTimeZone($this->getStartTimezone())
54 ->setEnd($this->getEnd())
55 ->setEndTimeZone($this->getEndTimezone())
56 ->setIsFullDay($this->getFullDay())
57 ->setAttendeesCollection($this->getAttendees())
58 ->setRemindCollection($this->getReminders())
59 ->setSection($this->getSection())
60 ->setDescription($this->getDescription())
61 ->setColor($this->getColor())
62 ->setTransparent($this->getTransparency())
63 ->setAccessibility($this->getAccessibility())
64 ->setImportance($this->getImportance())
65 ->setIsPrivate($this->getIsPrivate())
66 ->setEventHost($this->getEventHost())
67 ->setCreator($this->getCreator())
68 ->setOwner($this->getOwner())
69 ->setMeetingDescription($this->getMeetingDescription())
70 ->setVersion($this->getVersion())
71 ->setCalendarType($this->getCalendarType())
72 ->setSpecialLabel($this->getSpecialLabel())
73 ->setUid($this->getUid())
74 ->setIsActive($this->isActive())
75 ->setIsDeleted($this->isDeleted())
76 ->setRecurrenceId($this->getRecurrenceId())
77 ->setDateCreate($this->getDateCreate())
78 ->setDateModified($this->getDateModified())
79 ->setOriginalDateFrom($this->getOriginalDate())
80 ->setExcludedDateCollection($this->getExcludedDate())
81 ->setIsMeeting($this->isMeeting())
82 ->setMeetingStatus($this->getMeetingStatus())
83 ->setOriginalDateFrom($this->getOriginalDate())
84 ->setRelations($this->getRelations())
85 ->setEventOption($this->getEventOption())
86 ->setDtLength($this->getDtLength())
87 ->setCollabId($this->getCollabId())
88 ;
89 }
90
94 protected function getBaseEvent(): Event
95 {
96 if (empty($this->event))
97 {
98 $this->event = new Event();
99 }
100 return $this->event;
101 }
102
110 protected function prepareRecurringRule($ruleData = null): ?RecurringEventRules
111 {
112 if (empty($ruleData))
113 {
114 return null;
115 }
116
117 if (is_string($ruleData))
118 {
119 $ruleData = \CCalendarEvent::ParseRRULE($ruleData);
120 }
121
122 if (
123 isset($ruleData['FREQ'])
124 && $ruleData['FREQ'] !== 'NONE'
125 )
126 {
127 $rule = new RecurringEventRules($ruleData['FREQ']);
128
129 if (isset($ruleData['COUNT']))
130 {
131 $rule->setCount((int)$ruleData['COUNT']);
132 }
133
134 if (is_string($ruleData['UNTIL'] ?? null))
135 {
136 $ruleData['UNTIL'] = \CCalendarEvent::convertDateToCulture($ruleData['UNTIL']);
137 $rule->setUntil(new Date(Util::getDateObject($ruleData['UNTIL'])));
138 }
139
140 if (isset($ruleData['INTERVAL']))
141 {
142 $rule->setInterval((int)$ruleData['INTERVAL']);
143 }
144
145 if (!empty($ruleData['BYDAY']) && $ruleData['FREQ'] === RecurringEventRules::FREQUENCY_WEEKLY)
146 {
147 if (
148 is_string($ruleData['BYDAY'])
149 )
150 {
151 $rule->setByDay(explode(",", $ruleData['BYDAY']));
152 }
153 elseif (
154 is_array($ruleData['BYDAY'])
155 )
156 {
157 $rule->setByDay($ruleData['BYDAY']);
158 }
159 }
160
161 return $rule;
162 }
163
164 return null;
165 }
166
172 protected function prepareLocation($locationData = ''): ?Location
173 {
174 if (!$locationData)
175 {
176 return null;
177 }
178
179 if (is_array($locationData) && isset($locationData['NEW']))
180 {
181 $location = new Location($locationData['NEW']);
182 if (isset($locationData['OLD']))
183 {
184 $location->setOriginalLocation($locationData['OLD']);
185 }
186
187 return $location;
188 }
189
190 if (is_string($locationData))
191 {
192 return new Location($locationData);
193 }
194
195 return null;
196 }
197
203 protected function prepareEventHost(int $hostId = null): ?Role
204 {
205 return $this->prepareUserInstance($hostId);
206 }
207
213 protected function prepareUserInstance(int $userId): ?Role
214 {
215 try
216 {
217 return Helper::getUserRole($userId);
218 }
219 catch (BaseException $e)
220 {}
221
222 return null;
223 }
224
234 private function getUserEntityObject(int $userId): ?EO_User
235 {
236 return User::$users[$userId] = UserTable::query()
237 ->setSelect(['*'])
238 ->whereIn('ID', $userId)
239 ->exec()
240 ->fetchObject()
241 ;
242 }
243
244 protected function fillAttendeeCollection(AttendeeCollection $collection, $hostEventId)
245 {
246 // TODO: implement method
247 }
248
252 abstract protected function getId(): ?int;
253
257 abstract protected function getParentId(): ?int;
258
262 abstract protected function getName(): string;
263
267 abstract protected function getStartTimezone(): ?DateTimeZone;
268
272 abstract protected function getEndTimezone(): ?DateTimeZone;
273
277 abstract protected function getRecurringRule(): ?RecurringEventRules;
278
282 abstract protected function getLocation(): ?Location;
283
287 abstract protected function getStart(): Date;
288
292 abstract protected function getEnd(): Date;
293
297 abstract protected function getFullDay(): bool;
298
302 abstract protected function getAttendees(): ?AttendeeCollection;
303
307 abstract protected function getReminders(): RemindCollection;
308
312 abstract protected function getDescription(): ?string;
313
317 abstract protected function getSection(): Section;
318
322 abstract protected function getColor(): ?string;
323
327 abstract protected function getTransparency(): ?string;
328
332 abstract protected function getImportance(): ?string;
333
337 abstract protected function getAccessibility(): ?string;
338
342 abstract protected function getIsPrivate(): bool;
343
347 abstract protected function getEventHost(): ?Role;
348
352 abstract protected function getCreator(): ?Role;
353
357 abstract protected function getOwner(): ?Role;
358
362 abstract protected function getMeetingDescription(): ?MeetingDescription;
363
367 abstract protected function getVersion(): int;
368
372 abstract protected function getCalendarType(): ?string;
373
377 abstract protected function getSpecialLabel(): ?string;
378
382 abstract protected function getUid(): ?string;
383
387 abstract protected function isDeleted(): bool;
388
392 abstract protected function isActive(): bool;
393
397 abstract protected function getRecurrenceId(): ?int;
398
402 abstract protected function getOriginalDate(): ?Date;
403
407 abstract protected function getDateCreate(): ?Date;
408
412 abstract protected function getDateModified(): ?Date;
413
417 abstract protected function getExcludedDate(): ExcludedDatesCollection;
418
422 abstract protected function isMeeting(): bool;
423
427 abstract protected function getMeetingStatus(): ?string;
428
432 abstract protected function getRelations(): ?Relations;
433
434 abstract protected function getEventOption(): ?EventOption;
435
436 abstract protected function getDtLength(): ?int;
437
438 abstract protected function getCollabId(): ?int;
439
445 protected function prepareMeetingDescription($meeting = null): ?MeetingDescription
446 {
447 if (!isset($meeting))
448 {
449 return null;
450 }
451
452 $meeting = is_string($meeting)
453 ? unserialize($meeting, ['allowed_classes' => false])
454 : $meeting;
455
456 if ($meeting && !empty($meeting['HOST_NAME']))
457 {
458 return (new MeetingDescription())
459 ->setAllowInvite((bool)($meeting['ALLOW_INVITE'] ?? null))
460 ->setReInvite((bool)($meeting['REINVITE'] ?? null))
461 ->setHideGuests((bool)($meeting['HIDE_GUESTS'] ?? null))
462 ->setHostName($meeting['HOST_NAME'])
463 ->setIsNotify((bool)($meeting['NOTIFY'] ?? null))
464 ->setMeetingCreator((int)($meeting['MEETING_CREATOR'] ?? null))
465 ->setLanguageId($meeting['LANGUAGE_ID'] ?? null)
466 ->setMailFrom($meeting['MAIL_FROM'] ?? null)
467 ->setChatId($meeting['CHAT_ID'] ?? null)
468 ;
469 }
470
471 return null;
472 }
473
474 protected function prepareRelations($relations): ?Relations
475 {
476 if (!isset($relations))
477 {
478 return null;
479 }
480
481 $relations = is_string($relations)
482 ? unserialize($relations, ['allowed_classes' => false])
483 : $relations
484 ;
485
486 if ($relations && !empty($relations['COMMENT_XML_ID']))
487 {
488 return (new Relations($relations['COMMENT_XML_ID']));
489 }
490
491 return null;
492 }
493
500 protected function prepareExcludedDates(string $dates = ''): ExcludedDatesCollection
501 {
502 if (empty($dates))
503 {
504 return new ExcludedDatesCollection();
505 }
506
507 $collection = new ExcludedDatesCollection();
508 foreach (explode(";", $dates) as $exDate)
509 {
510 $collection->add($this->createDateForRecurrence($exDate));
511 }
512
513 return $collection;
514 }
515
523 protected function createDateForRecurrence(string $date): Date
524 {
525 if ($date[2] === '.' && $date[5] === '.')
526 {
527 return Date::createDateFromFormat(
528 $date,
529 ExcludedDatesCollection::EXCLUDED_DATE_FORMAT
530 );
531 }
532
533 return new Date(Util::getDateObject($date));
534 }
535}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
prepareEventHost(int $hostId=null)
Определения eventbuilder.php:203
prepareLocation($locationData='')
Определения eventbuilder.php:172
prepareUserInstance(int $userId)
Определения eventbuilder.php:213
prepareMeetingDescription($meeting=null)
Определения eventbuilder.php:445
createDateForRecurrence(string $date)
Определения eventbuilder.php:523
fillAttendeeCollection(AttendeeCollection $collection, $hostEventId)
Определения eventbuilder.php:244
prepareRecurringRule($ruleData=null)
Определения eventbuilder.php:110
prepareExcludedDates(string $dates='')
Определения eventbuilder.php:500
static getDateObject(string $date=null, ?bool $fullDay=true, ?string $tz='UTC')
Определения util.php:107
Определения orm.php:16144
Определения date.php:9
$event
Определения prolog_after.php:141
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$location
Определения options.php:2729