39 $this->connection = $connection;
40 $this->syncSection = $syncSection;
68 $owner = $this->syncSection->
getSection()->getOwner();
70 ->setName($this->getName())
71 ->setUid($this->item[
'iCalUID'])
72 ->setSection($this->syncSection->getSection())
75 ->setEventHost($owner)
76 ->setAttendeesCollection($this->getAttendeeCollection($owner->getId()))
77 ->setMeetingDescription($this->getDefaultMeeting($owner->getId()))
78 ->setDescription($this->getDescription())
79 ->setLocation($this->getLocation())
80 ->setColor($this->item[
'colorId'] ??
null)
84 if (!empty($this->item[
'start']))
86 if (!empty($this->item[
'start'][
'date']))
88 $event->setIsFullDay(
true);
89 $date =
new Type\Date($this->item[
'start'][
'date'], \DateTimeInterface::ATOM);
90 $event->setStart(
new Core\
Base\
Date($date));
92 elseif (!empty($this->item[
'start'][
'dateTime']))
94 $event->setIsFullDay(
false);
97 $this->item[
'start'][
'dateTime'],
98 \DateTimeInterface::ATOM,
101 $date->setTimeZone($timeZone);
103 $event->setStart(
new Core\
Base\
Date($date));
104 $event->setStartTimeZone(
new Core\
Base\DateTimeZone($timeZone));
108 if (!empty($this->item[
'end']))
110 if (!empty($this->item[
'end'][
'date']))
112 $date =
new Type\Date($this->item[
'end'][
'date'], \DateTimeInterface::ATOM);
113 $event->setEnd((
new Core\
Base\
Date($date))->sub(
'1 day'));
115 elseif (!empty($this->item[
'end'][
'dateTime']))
119 $this->item[
'end'][
'dateTime'],
120 \DateTimeInterface::ATOM,
123 $date->setTimeZone($timeZone);
125 $event->setEnd(
new Core\
Base\
Date($date));
126 $event->setEndTimeZone(
new Core\
Base\DateTimeZone($timeZone));
130 if (isset($this->item[
'transparency']) && ($this->item[
'transparency'] ===
'transparent'))
132 $event->setAccessibility(
'free');
135 if (isset($this->item[
'visibility']) && $this->item[
'visibility'] ===
'private')
137 $event->setIsPrivate(
true);
140 if (!empty($this->item[
'reminders']))
142 $event->setRemindCollection($this->getReminders($event->getStart()));
145 $event->setRecurringRule($this->prepareRecurringRule($event->getStart()));
146 $event->setExcludedDateCollection($this->prepareExcludedDatesCollection());
160 ->setConnection($this->connection)
161 ->setEntityTag($this->item[
'etag'] ??
null)
162 ->setVendorEventId($this->item[
'id'] ??
null)
164 ->setVendorVersionId($this->item[
'etag'] ??
null)
165 ->setVersion(($this->item[
'sequence'] ?? 0))
168 ->setRecurrenceId($this->item[
'recurringEventId'] ??
null)
180 if (empty($this->item[
'recurrence']))
184 foreach ($this->item[
'recurrence'] as $row)
186 if (strpos($row,
'RRULE:') === 0)
190 $rules = explode(
';', substr($row, 6));
192 foreach ($rules as $rule)
198 [$name, $value] = explode(
'=', $rule);
200 if (empty($name) || empty($value))
205 $rrule[$name] = $value;
208 if (!empty($rrule[
'FREQ']) && in_array($rrule[
'FREQ'], RecurringEventRules::FREQUENCY,
true))
210 $property =
new RecurringEventRules($rrule[
'FREQ']);
217 if (!empty($rrule[
'COUNT']))
219 $property->setCount((
int)$rrule[
'COUNT']);
221 if (!empty($rrule[
'INTERVAL']))
223 $property->setInterval((
int)$rrule[
'INTERVAL']);
225 if (!empty($rrule[
'UNTIL']))
229 $phpDate = new \DateTime($rrule[
'UNTIL']);
232 $property->setUntil($date);
234 catch (\Exception $e)
239 if ($rrule[
'FREQ'] === RecurringEventRules::FREQUENCY_WEEKLY)
241 if (!empty($rrule[
'BYDAY']))
243 $property->setByDay(explode(
',', $rrule[
'BYDAY']));
247 $dayOfWeek = $start->format(
'w');
248 $day = \CCalendar::WeekDayByInd($dayOfWeek);
251 $property->setByDay([$day]);
267 private function prepareExcludedDatesCollection(): ?ExcludedDatesCollection
269 if (empty($this->item[
'recurrence']))
274 $exDatesCollection =
new ExcludedDatesCollection();
275 foreach ($this->item[
'recurrence'] as $row)
277 if (strpos($row,
'EXDATE;') === 0)
279 $exDate = explode(
':', substr($row, 7));
281 if ($exDate[0] ===
'VALUE=DATE-TIME')
283 $date = Core\Base\Date::createDateTimeFromFormat(
290 $exDatesCollection->add($date);
293 else if ($exDate[0] ===
'VALUE=DATE')
295 $date = Core\Base\Date::createDateTimeFromFormat(
302 $exDatesCollection->add($date);
308 if ($exDatesCollection->count())
310 return $exDatesCollection;
322 if (!empty($this->item[
'originalStartTime']))
324 if (!empty($this->item[
'originalStartTime'][
'dateTime']))
326 return Core\Base\Date::createDateTimeFromFormat(
327 $this->item[
'originalStartTime'][
'dateTime'],
328 \DateTimeInterface::ATOM
332 if (!empty($this->item[
'originalStartTime'][
'date']))
334 return Core\Base\Date::createDateFromFormat(
335 $this->item[
'originalStartTime'][
'date'],
347 private function getLocation(): ?Core\
Event\Properties\
Location
349 if (!empty($this->item[
'location']))
351 $parsedLocation = \Bitrix\Calendar\Rooms\Util::unParseTextLocation($this->item[
'location']);
362 private function getDescription(): string
364 if (!empty($this->item[
'description']))
366 $languageId = \CCalendar::getUserLanguageId($this->syncSection->getSection()->getOwner()->getId());
367 $this->item[
'description'] = \CCalendar::ParseHTMLToBB($this->item[
'description']);
369 return (
new Sync\
Util\EventDescription())->prepareAfterImport($this->item[
'description'], $languageId);
379 private function getReminders(Core\Base\Date $start): RemindCollection
381 $collection =
new RemindCollection();
382 $collection->setEventStart($start);
384 if (!empty($this->item[
'reminders'][
'overrides']) && is_array($this->item[
'reminders'][
'overrides']))
386 foreach ($this->item[
'reminders'][
'overrides'] as $remind)
388 $collection->add((
new Core\Event\Properties\Remind())
389 ->setTimeBeforeEvent($remind[
'minutes'])
390 ->setEventStart($start)
395 if (!empty($this->item[
'reminders'][
'useDefault']))
397 $collection->add((
new Core\Event\Properties\Remind())
398 ->setTimeBeforeEvent(30)
399 ->setEventStart($start)
409 private function getName()
411 if (empty($this->item[
'summary']))
413 IncludeModuleLangFile($_SERVER[
"DOCUMENT_ROOT"].
"/bitrix/modules/calendar/classes/general/calendar_js.php");
417 return $this->item[
'summary'];
425 private function getAttendeeCollection(
int $userId): AttendeeCollection
427 return (
new AttendeeCollection())
428 ->setAttendeesCodes([
'U' . $userId])
437 private function getDefaultMeeting(
int $userId): MeetingDescription
439 return (
new MeetingDescription())
440 ->setHostName(\CCalendar::GetUserName($userId))
443 ->setAllowInvite(
false)
444 ->setMeetingCreator($userId)
445 ->setHideGuests(
true)
446 ->setLanguageId(\CCalendar::getUserLanguageId($userId))
static getMessage($code, $replace=null, $language=null)
static createFromPhp(\DateTime $datetime)