30 if (!Loader::includeModule(
'dav'))
37 'CREATED' => date(
'Ymd\\THis\\Z', $event->
getDateCreate()->getTimestamp()),
38 'LAST-MODIFIED' => date(
'Ymd\\THis\\Z', $event->
getDateModified()->getTimestamp()),
39 'DTSTAMP' => date(
'Ymd\\THis\\Z', $event->
getDateModified()->getTimestamp()),
46 $content[
'DTSTART'] = [
47 'VALUE' => $event->
getStart()->format(
'Ymd'),
48 'PARAMETERS' => [
'VALUE' =>
'DATE'],
51 'VALUE' => $event->
getEnd()->add(
'1 day')->format(
'Ymd'),
52 'PARAMETERS' => [
'VALUE' =>
'DATE'],
57 $content[
'DTSTART'] = [
58 'VALUE' => $event->
getStart()->format(
'Ymd\\THis'),
59 'PARAMETERS' => [
'TZID' => $this->prepareTimeZone($event->
getStartTimeZone())],
62 'VALUE' => $event->
getEnd()->format(
'Ymd\\THis'),
63 'PARAMETERS' => [
'TZID' => $this->prepareTimeZone($event->
getEndTimeZone())],
71 $content[
'RECURRENCE-ID'] = [
73 'PARAMETERS' => [
'VALUE' =>
'DATE'],
78 $content[
'RECURRENCE-ID'] = [
80 'PARAMETERS' => [
'TZID' => $this->prepareTimeZone($event->
getStartTimeZone())],
87 $content[
'TRANSP'] =
'TRANSPARENT';
91 $content[
'TRANSP'] =
'OPAQUE';
96 $content[
'LOCATION'] = Rooms\Util::getTextLocation($event->
getLocation()->getActualLocation());
100 if ($importance ===
'low')
102 $content[
'PRIORITY'] = 9;
104 else if ($importance ===
'high')
106 $content[
'PRIORITY'] = 1;
110 $content[
'PRIORITY'] = 5;
113 $content[
'DESCRIPTION'] = $this->prepareDescription($event);
114 if (!$content[
'DESCRIPTION'])
116 unset($content[
'DESCRIPTION']);
121 $content[
'@VALARM'] = $this->prepareReminders($event);
133 $content[
'EXDATE'] = $this->prepareExcludedDates($event);
136 $this->prepareOuterParams($data, $content);
146 private function prepareDescription(
Event $event): string
158 private function prepareReminderValue(
166 if ($remind->getUnits() ===
'minutes')
168 $valueType =
'DURATION';
169 if ($remind->getTime() === 60 || $remind->getTime() === 120)
171 $value =
'-PT' . $remind->getTime() / 60 .
'H';
173 else if ($remind->getTime() === 0)
175 $value =
'PT' . $remind->getTime() .
'S';
179 $value =
'-PT' . $remind->getTime() .
'M';
182 else if ($remind->getSpecificTime() && $remind->getDaysBefore() !==
null)
184 $valueType =
'DURATION';
185 $diff = $remind->getTimeBeforeStartInMinutes();
187 if ($isFullDay && $remind->getDaysBefore() === 0)
189 $value =
'PT' . $parsedDiff[
'hours'] .
'H';
192 ($remind->getDaysBefore() === 0 && !$isFullDay && $diff > 0)
193 || ($remind->getDaysBefore() === 1 && $parsedDiff[
'days'] === 0)
198 if ($parsedDiff[
'hours'])
200 $hours = $parsedDiff[
'hours'] .
'H';
202 if ($parsedDiff[
'minutes'])
204 $minutes = $parsedDiff[
'minutes'] .
'M';
206 $value =
'-PT' . $hours . $minutes;
208 else if ($parsedDiff[
'days'] > 0)
212 $value =
'-P' . $parsedDiff[
'days'] .
'D';
213 if ($parsedDiff[
'hours'])
215 $hours = $parsedDiff[
'hours'] .
'H';
217 if ($parsedDiff[
'minutes'])
219 $minutes = $parsedDiff[
'minutes'] .
'M';
221 if ($hours || $minutes)
223 $value .=
'T' . $hours . $minutes;
231 else if ($remind->getSpecificTime())
233 $valueType =
'DATE-TIME';
234 $value = date(
'Ymd\\THis\\Z', $remind->getSpecificTime()->getTimestamp());
237 return [$value, $valueType];
245 private function prepareTimeZone(?DateTimeZone $timeZone): string
249 return $timeZone->getTimeZone()->getName();
261 private function prepareReminders(Event $event): array
265 foreach ($event->getRemindCollection()->getCollection() as $remind)
267 [$value, $valueType] = $this->prepareReminderValue(
269 $event->isFullDayEvent()
272 if (!$value || !$valueType)
279 'X-WR-ALARMUID' => $uuId,
282 'ACTION' =>
'DISPLAY',
284 'PARAMETERS' => [
'VALUE' => $valueType],
300 private function prepareRecurrenceRule(RecurringEventRules $rrule, ?DateTimeZone $timeZone): string
302 $result =
'FREQ=' . $rrule->getFrequency();
303 if ($rrule->getInterval())
305 $result .=
';INTERVAL=' . $rrule->getInterval();
307 if ($rrule->getByday())
309 $result .=
';BYDAY=' . implode(
',', $rrule->getByday());
311 if ($rrule->getCount())
313 $result .=
';COUNT=' . $rrule->getCount();
317 && $rrule->getUntil()->getDate()->getTimestamp()
318 && $rrule->getUntil()->getDate()->getTimestamp() < 2145830400
324 $offset = $timeZone->getTimeZone()->getOffset(
new \DateTime(
'now', $timeZone->getTimeZone()));
327 $untilTimestamp = $rrule->getUntil()->getDate()->getTimestamp() + (self::DAY_LENGTH - 1) - $offset;
328 $result .=
';UNTIL=' . date(
'Ymd\\THis\\Z', $untilTimestamp);
339 private function prepareExcludedDates(Event $event): array
342 $exDate = $event->getExcludedDateCollection()->getCollection();
343 foreach ($exDate as $date)
345 $fields = $date->getFields();
346 if ($event->isFullDayEvent())
349 'VALUE' => date(
'Ymd', MakeTimeStamp($fields[
'date'])),
350 'PARAMETERS' => [
'VALUE' =>
'DATE'],
356 'VALUE' => date(
'Ymd', MakeTimeStamp($fields[
'date']))
357 .
'T' . $event->getStart()->format(
'His'),
358 'PARAMETERS' => [
'TZID' => $this->prepareTimeZone($event->getStartTimeZone())],
372 private function prepareOuterParams(?array $data, array &$content): void
379 if ($data[
'ATTENDEE'])
381 foreach ($data[
'ATTENDEE'] as $attendee)
383 $value = $attendee[
'VALUE'];
384 unset($attendee[
'VALUE']);
386 $content[
'ATTENDEE'][] = [
387 'PARAMETERS' => $attendee,
395 foreach ($data[
'ATTACH'] as $attachment)
397 $value = $attachment[
'VALUE'];
398 unset($attachment[
'VALUE']);
400 $content[
'ATTACH'][] = [
401 'PARAMETERS' => $attachment,
407 if ($data[
'ORGANIZER'])
409 $value = $data[
'ORGANIZER'][
'VALUE'];
410 unset($data[
'ORGANIZER'][
'VALUE']);
412 $content[
'ORGANIZER'] = [
413 'PARAMETERS' => $data[
'ORGANIZER'],
420 $content[
'URL'] = $data[
'URL'];