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 if ($externalEventConnection)
52 $externalEventConnection
53 ->setId($eventConnectionId)
54 ->setVersion($localEvent->getVersion())
59 return $externalSyncEvent;
70 private function prepareReminders(
Event $localEvent,
Event $externalEvent): ?Core\
Event\Properties\RemindCollection
74 if (!$externalRemindCollection || $externalRemindCollection->count() === 0)
76 if ($localRemindCollection)
80 return ($localRemindCollection->count() > 1)
91 if ((!$localRemindCollection || $localRemindCollection->count() < 2))
97 if ($externalRemindCollection->isSingle())
99 $this->removeClosestRemind($localRemindCollection);
100 $localRemindCollection->add($externalRemindCollection->fetch());
101 return $localRemindCollection;
105 return $this->mergeRemindCollections(
106 $externalRemindCollection,
107 $localRemindCollection,
118 private function removeClosestRemind(?Core\Event\Properties\RemindCollection $remindCollection)
124 foreach ($remindCollection->getCollection() as $index => $item)
126 $offset = $item->getTimeBeforeStartInMinutes();
132 if ($minValue ===
null || $offset < $minValue)
138 if ($minIndex !==
null)
140 $remindCollection->remove($minIndex);
150 private function mergeRemindCollections(
151 Core\Event\Properties\RemindCollection $externalRemindCollection,
152 Core\Event\Properties\RemindCollection $localRemindCollection
153 ): Core\Event\Properties\RemindCollection
155 $prepareMap =
function (?Core\Event\Properties\RemindCollection $collection)
159 foreach ($collection as $index => $item)
161 $result[$item->getTimeBeforeStartInMinutes()] = $index;
166 $externalMap = $prepareMap($externalRemindCollection);
167 $localMap = $prepareMap($localRemindCollection);
169 foreach ($localMap as $key => $index)
171 if (!array_key_exists($key, $externalMap))
173 $localRemindCollection->remove($index);
177 return $localRemindCollection->addItems($externalRemindCollection->getCollection());