Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
eventbuilder.php
1<?php
2
4
22use Bitrix\Main\EO_User;
27
28abstract class EventBuilder implements Builder
29{
30 private Event $event;
31
32 public function setBaseEvent(Event $event): self
33 {
34 $this->event = $event;
35
36 return $this;
37 }
38
43 public function build(): Event
44 {
45 return $this->getBaseEvent()
46 ->setId($this->getId())
47 ->setParentId($this->getParentId())
48 ->setName($this->getName())
49 ->setRecurringRule($this->getRecurringRule())
50 ->setLocation($this->getLocation())
51 ->setStart($this->getStart())
52 ->setStartTimeZone($this->getStartTimezone())
53 ->setEnd($this->getEnd())
54 ->setEndTimeZone($this->getEndTimezone())
55 ->setIsFullDay($this->getFullDay())
56 ->setAttendeesCollection($this->getAttendees())
57 ->setRemindCollection($this->getReminders())
58 ->setSection($this->getSection())
59 ->setDescription($this->getDescription())
60 ->setColor($this->getColor())
61 ->setTransparent($this->getTransparency())
62 ->setAccessibility($this->getAccessibility())
63 ->setImportance($this->getImportance())
64 ->setIsPrivate($this->getIsPrivate())
65 ->setEventHost($this->getEventHost())
66 ->setCreator($this->getCreator())
67 ->setOwner($this->getOwner())
68 ->setMeetingDescription($this->getMeetingDescription())
69 ->setVersion($this->getVersion())
70 ->setCalendarType($this->getCalendarType())
71 ->setSpecialLabel($this->getSpecialLabel())
72 ->setUid($this->getUid())
73 ->setIsActive($this->isActive())
74 ->setIsDeleted($this->isDeleted())
75 ->setRecurrenceId($this->getRecurrenceId())
76 ->setDateCreate($this->getDateCreate())
77 ->setDateModified($this->getDateModified())
78 ->setOriginalDateFrom($this->getOriginalDate())
79 ->setExcludedDateCollection($this->getExcludedDate())
80 ->setIsMeeting($this->isMeeting())
81 ->setMeetingStatus($this->getMeetingStatus())
82 ->setOriginalDateFrom($this->getOriginalDate())
83 ->setRelations($this->getRelations())
84 ;
85 }
86
90 protected function getBaseEvent(): Event
91 {
92 if (empty($this->event))
93 {
94 $this->event = new Event();
95 }
96 return $this->event;
97 }
98
106 protected function prepareRecurringRule($ruleData = null): ?RecurringEventRules
107 {
108 if (empty($ruleData))
109 {
110 return null;
111 }
112
113 if (is_string($ruleData))
114 {
115 $ruleData = \CCalendarEvent::ParseRRULE($ruleData);
116 }
117
118 if (
119 isset($ruleData['FREQ'])
120 && $ruleData['FREQ'] !== 'NONE'
121 )
122 {
123 $rule = new RecurringEventRules($ruleData['FREQ']);
124
125 if (isset($ruleData['COUNT']))
126 {
127 $rule->setCount((int)$ruleData['COUNT']);
128 }
129
130 if (is_string($ruleData['UNTIL'] ?? null))
131 {
132 $ruleData['UNTIL'] = \CCalendarEvent::convertDateToCulture($ruleData['UNTIL']);
133 $rule->setUntil(new Date(Util::getDateObject($ruleData['UNTIL'])));
134 }
135
136 if (isset($ruleData['INTERVAL']))
137 {
138 $rule->setInterval((int)$ruleData['INTERVAL']);
139 }
140
141 if (!empty($ruleData['BYDAY']) && $ruleData['FREQ'] === RecurringEventRules::FREQUENCY_WEEKLY)
142 {
143 if (
144 is_string($ruleData['BYDAY'])
145 )
146 {
147 $rule->setByDay(explode(",", $ruleData['BYDAY']));
148 }
149 elseif (
150 is_array($ruleData['BYDAY'])
151 )
152 {
153 $rule->setByDay($ruleData['BYDAY']);
154 }
155 }
156
157 return $rule;
158 }
159
160 return null;
161 }
162
168 protected function prepareLocation($locationData = ''): ?Location
169 {
170 if (!$locationData)
171 {
172 return null;
173 }
174
175 if (is_array($locationData) && isset($locationData['NEW']))
176 {
177 $location = new Location($locationData['NEW']);
178 if (isset($locationData['OLD']))
179 {
180 $location->setOriginalLocation($locationData['OLD']);
181 }
182
183 return $location;
184 }
185
186 if (is_string($locationData))
187 {
188 return new Location($locationData);
189 }
190
191 return null;
192 }
193
199 protected function prepareEventHost(int $hostId = null): ?Role
200 {
201 return $this->prepareUserInstance($hostId);
202 }
203
209 protected function prepareUserInstance(int $userId): ?Role
210 {
211 try
212 {
213 return Helper::getUserRole($userId);
214 }
215 catch (BaseException $e)
216 {}
217
218 return null;
219 }
220
230 private function getUserEntityObject(int $userId): ?EO_User
231 {
232 return User::$users[$userId] = UserTable::query()
233 ->setSelect(['*'])
234 ->whereIn('ID', $userId)
235 ->exec()
236 ->fetchObject()
237 ;
238 }
239
240 protected function fillAttendeeCollection(AttendeeCollection $collection, $hostEventId)
241 {
242 // TODO: implement method
243 }
244
248 abstract protected function getId(): ?int;
249
253 abstract protected function getParentId(): ?int;
254
258 abstract protected function getName(): string;
259
263 abstract protected function getStartTimezone(): ?DateTimeZone;
264
268 abstract protected function getEndTimezone(): ?DateTimeZone;
269
273 abstract protected function getRecurringRule(): ?RecurringEventRules;
274
278 abstract protected function getLocation(): ?Location;
279
283 abstract protected function getStart(): Date;
284
288 abstract protected function getEnd(): Date;
289
293 abstract protected function getFullDay(): bool;
294
298 abstract protected function getAttendees(): ?AttendeeCollection;
299
303 abstract protected function getReminders(): RemindCollection;
304
308 abstract protected function getDescription(): ?string;
309
313 abstract protected function getSection(): Section;
314
318 abstract protected function getColor(): ?string;
319
323 abstract protected function getTransparency(): ?string;
324
328 abstract protected function getImportance(): ?string;
329
333 abstract protected function getAccessibility(): ?string;
334
338 abstract protected function getIsPrivate(): bool;
339
343 abstract protected function getEventHost(): ?Role;
344
348 abstract protected function getCreator(): ?Role;
349
353 abstract protected function getOwner(): ?Role;
354
358 abstract protected function getMeetingDescription(): ?MeetingDescription;
359
363 abstract protected function getVersion(): int;
364
368 abstract protected function getCalendarType(): ?string;
369
373 abstract protected function getSpecialLabel(): ?string;
374
378 abstract protected function getUid(): ?string;
379
383 abstract protected function isDeleted(): bool;
384
388 abstract protected function isActive(): bool;
389
393 abstract protected function getRecurrenceId(): ?int;
394
398 abstract protected function getOriginalDate(): ?Date;
399
403 abstract protected function getDateCreate(): ?Date;
404
408 abstract protected function getDateModified(): ?Date;
409
413 abstract protected function getExcludedDate(): ExcludedDatesCollection;
414
418 abstract protected function isMeeting(): bool;
419
423 abstract protected function getMeetingStatus(): ?string;
424
428 abstract protected function getRelations(): ?Relations;
429
435 protected function prepareMeetingDescription($meeting = null): ?MeetingDescription
436 {
437 if (!isset($meeting))
438 {
439 return null;
440 }
441
442 $meeting = is_string($meeting)
443 ? unserialize($meeting, ['allowed_classes' => false])
444 : $meeting;
445
446 if ($meeting && !empty($meeting['HOST_NAME']))
447 {
448 return (new MeetingDescription())
449 ->setAllowInvite((bool)($meeting['ALLOW_INVITE'] ?? null))
450 ->setReInvite((bool)($meeting['REINVITE'] ?? null))
451 ->setHideGuests((bool)($meeting['HIDE_GUESTS'] ?? null))
452 ->setHostName($meeting['HOST_NAME'])
453 ->setIsNotify((bool)($meeting['NOTIFY'] ?? null))
454 ->setMeetingCreator((int)($meeting['MEETING_CREATOR'] ?? null))
455 ->setLanguageId($meeting['LANGUAGE_ID'] ?? null)
456 ->setMailFrom($meeting['MAIL_FROM'] ?? null)
457 ->setChatId($meeting['CHAT_ID'] ?? null)
458 ;
459 }
460
461 return null;
462 }
463
464 protected function prepareRelations($relations): ?Relations
465 {
466 if (!isset($relations))
467 {
468 return null;
469 }
470
471 $relations = is_string($relations)
472 ? unserialize($relations, ['allowed_classes' => false])
473 : $relations
474 ;
475
476 if ($relations && !empty($relations['COMMENT_XML_ID']))
477 {
478 return (new Relations($relations['COMMENT_XML_ID']));
479 }
480
481 return null;
482 }
483
490 protected function prepareExcludedDates(string $dates = ''): ExcludedDatesCollection
491 {
492 if (empty($dates))
493 {
494 return new ExcludedDatesCollection();
495 }
496
497 $collection = new ExcludedDatesCollection();
498 foreach (explode(";", $dates) as $exDate)
499 {
500 $collection->add($this->createDateForRecurrence($exDate));
501 }
502
503 return $collection;
504 }
505
513 protected function createDateForRecurrence(string $date): Date
514 {
515 if ($date[2] === '.' && $date[5] === '.')
516 {
517 return Date::createDateFromFormat(
518 $date,
519 ExcludedDatesCollection::EXCLUDED_DATE_FORMAT
520 );
521 }
522
523 return new Date(Util::getDateObject($date));
524 }
525}
fillAttendeeCollection(AttendeeCollection $collection, $hostEventId)
static getDateObject(string $date=null, ?bool $fullDay=true, ?string $tz='UTC')
Definition util.php:102