25 ?
int $eventConnectionId =
null
28 $localEvent = $savedSyncEvent->
getEvent();
29 $externalEvent = $externalSyncEvent->
getEvent();
32 ->setOwner($localEvent->getOwner())
33 ->setSection($localEvent->getSection())
35 ->setCreator($localEvent->getCreator())
36 ->setCalendarType($localEvent->getCalendarType())
37 ->setSpecialLabel($localEvent->getSpecialLabel())
38 ->setMeetingDescription($localEvent->getMeetingDescription())
39 ->setEventHost($localEvent->getEventHost())
40 ->setAttendeesCollection($localEvent->getAttendeesCollection())
41 ->setIsMeeting($localEvent->isMeeting())
42 ->setMeetingStatus($localEvent->getMeetingStatus())
43 ->setRelations($localEvent->getRelations())
44 ->setVersion($localEvent->getVersion())
45 ->setRemindCollection($this->prepareReminders($localEvent, $externalEvent))
50 $externalEventConnection?->setId($eventConnectionId)
51 ->setVersion($localEvent->getVersion())
55 return $externalSyncEvent;
66 private function prepareReminders(
Event $localEvent,
Event $externalEvent): ?
Core\
Event\Properties\RemindCollection
70 if (!$externalRemindCollection || $externalRemindCollection->count() === 0)
72 if ($localRemindCollection)
76 return ($localRemindCollection->count() > 1)
87 if ((!$localRemindCollection || $localRemindCollection->count() < 2))
93 if ($externalRemindCollection->isSingle())
95 $this->removeClosestRemind($localRemindCollection);
96 $localRemindCollection->add($externalRemindCollection->fetch());
97 return $localRemindCollection;
101 return $this->mergeRemindCollections(
102 $externalRemindCollection,
103 $localRemindCollection,
114 private function removeClosestRemind(?Core\Event\Properties\RemindCollection $remindCollection)
120 foreach ($remindCollection->getCollection() as $index => $item)
122 $offset = $item->getTimeBeforeStartInMinutes();
128 if ($minValue ===
null || $offset < $minValue)
134 if ($minIndex !==
null)
136 $remindCollection->remove($minIndex);
146 private function mergeRemindCollections(
147 Core\Event\Properties\RemindCollection $externalRemindCollection,
148 Core\Event\Properties\RemindCollection $localRemindCollection
149 ): Core\Event\Properties\RemindCollection
151 $prepareMap =
function (?Core\Event\Properties\RemindCollection $collection)
155 foreach ($collection as $index => $item)
157 $result[$item->getTimeBeforeStartInMinutes()] = $index;
162 $externalMap = $prepareMap($externalRemindCollection);
163 $localMap = $prepareMap($localRemindCollection);
165 foreach ($localMap as
$key => $index)
167 if (!array_key_exists(
$key, $externalMap))
169 $localRemindCollection->remove($index);
173 return $localRemindCollection->addItems($externalRemindCollection->getCollection());