22 'workingElsewhere' =>
'absent',
23 'tentative' =>
'quest',
29 'quest' =>
'tentative',
45 ? (clone $event->
getEnd())->add(
'1 day')
51 'contentType' =>
'HTML',
52 'content' => $this->prepareDescription($event),
57 'timeZone' => $this->prepareTimeZone(
65 'timeZone' => $this->prepareTimeZone(
73 'displayName' => $this->prepareLocation($event->
getLocation()),
84 $this->prepareReminders($event, $data);
87 if ($accessibility = $this->convertAccessibility($event->
getAccessibility()))
89 $data[
'showAs'] = $accessibility;
100 private function convertAccessibility(?
string $ourValue): ?string
102 return self::ACCESSIBILITY_EXPORT_MAP[$ourValue] ??
null;
111 private function prepareRecurringForDto(RecurringEventRules $rule,
Type\
Date $startDate): array
115 'interval' => $rule->getInterval(),
128 if ($rule->getFrequency() ===
'WEEKLY')
130 $result[
'pattern'][
'type'] =
'weekly';
132 $firstDayOfWeek = \COption::GetOptionString(
'calendar',
'week_start',
'MO');
133 $result[
'pattern'][
'firstDayOfWeek'] = $dayMap[$firstDayOfWeek];
135 if ($rule->getByday())
137 $result[
'pattern'][
'daysOfWeek'] = array_map(
function ($val) use ($dayMap) {
138 return $dayMap[$val] ??
'';
139 }, array_values($rule->getByday()));
142 elseif ($rule->getFrequency() ===
'DAILY')
144 $result[
'pattern'][
'type'] =
'daily';
146 elseif ($rule->getFrequency() ===
'MONTHLY')
148 $result[
'pattern'][
'type'] =
'absoluteMonthly';
149 $result[
'pattern'][
'interval'] = $rule->getInterval();
150 $result[
'pattern'][
'dayOfMonth'] = (int) $startDate->format(
'd');
153 elseif ($rule->getFrequency() ===
'YEARLY')
155 $result[
'pattern'][
'type'] =
'absoluteYearly';
156 $result[
'pattern'][
'dayOfMonth'] = (int) $startDate->format(
'd');
157 $result[
'pattern'][
'month'] = (int) $startDate->format(
'm');
159 $result[
'range'][
'startDate'] = $startDate->format(
'Y-m-d');
161 if ($rule->getCount())
163 $result[
'range'][
'type'] =
'numbered';
164 $result[
'range'][
'numberOfOccurrences'] = $rule->getCount();
165 $result[
'range'][
'endDate'] =
'0001-01-01';
167 elseif ($rule->getUntil())
169 $result[
'range'][
'type'] =
'endDate';
170 $result[
'range'][
'endDate'] = $rule->getUntil()->format(
'Y-m-d');
174 $result[
'range'][
'type'] =
'noEnd';
175 $result[
'range'][
'endDate'] = $this->getFarFarAwayDate();
184 private function getFarFarAwayDate(): string
195 private function prepareReminders(Event $event, array &$data): void
197 $remindCollection = $event->getRemindCollection();
201 foreach ($remindCollection as $remind)
203 if (!$remind->isBeforeEventStart() && !$event->isFullDayEvent())
208 $newDelta = $remind->getTimeBeforeStartInMinutes();
210 if ($newDelta < -1440)
215 $delta = $delta ===
null ? $newDelta : min($delta, $newDelta);
220 $delta = (int)$delta;
221 $data[
'isReminderOn'] =
true;
222 $data[
'reminderMinutesBeforeStart'] = $delta;
226 $data[
'isReminderOn'] =
false;
227 $data[
'reminderMinutesBeforeStart'] = 0;
237 private function prepareLocation(?Location $location)
241 return CCalendar::GetTextLocation($location->getActualLocation());
254 private function prepareTimeZone(
256 ?Base\DateTimeZone $timeZone,
262 return $timeZone->getTimeZone()->getName();
267 $coreDate = $date->getDate();
268 if ($coreDate instanceof
Type\DateTime)
270 return $coreDate->getTimeZone()->getName();
274 return $this->getDefaultTimezone();
280 private function getDefaultTimezone(): string
290 private function prepareDescription(Event $event): string
292 $description = (
new EventDescription())->prepareForExport($event);
294 return $description ? \CCalendarEvent::ParseText($this->parseImagesInDescription($description)) :
'';
302 private function parseImagesInDescription(
string $description): string
305 "#\[img]((cid):[.\\-_:a-z0-9@]+)*\[/img]#is".BX_UTF_PCRE_MODIFIER,