Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
eventcomparemanager.php
1<?php
2
4
7
9{
10 public const SIGNIFICANT_FIELDS = [
11 'name' => 'name',
12 'attendees' => 'attendees',
13 'start' => 'start',
14 'end' => 'end',
15 'location' => 'location',
16 'recurringRule' => 'recurringRule',
17 'creatorId' => 'creatorId',
18 'hostId' => 'hostId',
19 'excludedDates' => 'excludedDates',
20 ];
21
22 public const COMPARE_FIELDS = [
23 'name' => 'name',
24 'recurringRule' => 'recurringRule',
25 'start' => 'start',
26 'end' => 'end',
27 'startTimezone' => 'startTimezone',
28 'endTimezone' => 'endTimezone',
29 'location' => 'location',
30 'attendees' => 'attendees',
31 'description' => 'description',
32 'ownerId' => 'ownerId',
33 'creatorId' => 'creatorId',
34 'accessibility' => 'accessibility',
35 'transparent' => 'transparent',
36 'isPrivate' => 'isPrivate',
37 'importance' => 'importance',
38 'calendarType' => 'calendarType',
39 'specialLabel' => 'specialLabel',
40 'isFullDay' => 'isFullDay',
41 'color' => 'color',
42 'section' => 'section',
43 'uid' => 'uid',
44 'isActive' => 'isActive',
45 'deleted' => 'deleted',
46 'originalDateFrom' => 'originalDateFrom',
47 // 'excludedDates' => 'excludedDates',
48 // 'version' => 'version',
49 // 'recurrenceId' => 'recurrenceId',
50 // 'dateCreate' => 'dateCreate',
51 // 'dateModified' => 'dateModified',
52 // 'reminds' => 'reminds',
53 // 'hostId' => 'hostId',
54 // 'meetingDescription' => 'meetingDescription',
55 ];
56
60 private array $differenceFields = [];
64 protected array $difference = [];
68 protected array $eventValueForCompare;
72 protected array $originalValueForCompare;
76 protected array $significantFields;
80 protected Event $event;
85
91 {
92 $this->event = $event;
93 $this->originalEvent = $originalEvent;
94
95 $this->compare();
96 }
97
101 public function compare(): EventCompareManager
102 {
103 $this->eventValueForCompare = $this->transformValuesForCompare($this->event);
104 $this->originalValueForCompare = $this->transformValuesForCompare($this->originalEvent);
105 $this->compareFields();
106
107 $this->significantFields = array_intersect($this->getDifferenceKeyFields(), $this->getSignificantFields());
108
109 return $this;
110 }
111
115 public function hasDifferenceFields(): bool
116 {
117 return (bool)$this->differenceFields;
118 }
119
123 public function hasSignificantFields(): bool
124 {
125 return (bool)$this->significantFields;
126 }
127
131 public function getSignificantChanges(): array
132 {
134 }
135
139 private function getFields(): array
140 {
141 return [
142 'NAME',
143 'DESCRIPTION',
144 'RRULE',
145 'EXDATE',
146 'DATE_FROM',
147 'DATE_TO',
148 'LOCATION',
149 'SECTION',
150 ];
151 }
152
156 public function getDifferenceKeyFields(): array
157 {
158 return array_keys($this->differenceFields);
159 }
160
165 {
166 return [
167 'event' => $this->differenceFields,
168 'originalEvent' => array_intersect_key($this->originalValueForCompare, $this->differenceFields),
169 ];
170 }
171
176 private function transformValuesForCompare(Event $event): array
177 {
178 return [
179 'name' => $event->getName(),
180 'recurringRule' => $event->isRecurrence() ? $event->getRecurringRule()->toString() : null,
181 'start' => (string)$event->getStart(),
182 'end' => (string)$event->getEnd(),
183 'startTimeZone' => $event->getStartTimeZone() ? (string)$event->getStartTimeZone() : null,
184 'endTimeZone' => $event->getEndTimeZone() ? (string)$event->getEndTimeZone() : null,
185 'location' => $event->getLocation() ? (string) $event->getLocation()->toString() : '',
186 'attendees' => (string) $event->getAttendeesCollection(),
187 'description' => trim($event->getDescription()),
188 'ownerId' => $event->getOwner() ? $event->getOwner()->getId() : null,
189 'creatorId' => $event->getCreator() ? $event->getCreator()->getId(): null,
190 'hostId' => $event->getEventHost() ? $event->getEventHost()->getId() : null,
191 'meetingDescription' => $event->getMeetingDescription() ? (string)$event->getMeetingDescription() : null,
192 'accessibility' => (string)$event->getAccessibility(),
193 'transparent' => (string)$event->getTransparent(),
194 'isPrivate' => (string)$event->getIsPrivate(),
195 'importance' => (string)$event->getImportance(),
196 'calendarType' => (string)$event->getCalendarType(),
197 'specialLabel' => (string)$event->getSpecialLabel(),
198 'excludedDates' => (string)$event->getExcludedDateCollection(),
199 'isFullDay' => $event->isFullDayEvent(),
200 'color' => (string)$event->getColor(),
201 'section' => $event->getSection()->getId(),
202 'version' => $event->getVersion(),
203 'uid' => (string)$event->getUid(),
204 'isActive' => $event->isActive(),
205 'deleted' => $event->isDeleted(),
206 'recurrenceId' => $event->getRecurrenceId(),
207 'originalDateFrom' => $event->getOriginalDateFrom(),
208 'dateCreate' => (string)$event->getDateCreate(),
209 'dateModified' => (string)$event->getDateModified(),
210 'reminds' => (string)$event->getRemindCollection(),
211 ];
212 }
213
217 private function getSignificantFields(): array
218 {
220 }
221
225 private function getCompareFields(): array
226 {
228 }
229
233 private function compareFields(): void
234 {
235 $this->compareHandler();
236 $this->compareExcludedDates();
237 $this->compareReminders();
238 }
239
243 private function compareHandler(): void
244 {
245 foreach ($this->getCompareFields() as $field)
246 {
247 if (($this->eventValueForCompare[$field] ?? null) != ($this->originalValueForCompare[$field] ?? null))
248 {
249 $this->differenceFields[$field] = $this->eventValueForCompare[$field] ?? null;
250 }
251 }
252 }
253
257 protected function compareExcludedDates(): void
258 {
259 if ($this->originalEvent->getExcludedDateCollection() || $this->event->getExcludedDateCollection())
260 {
261 $excludedDatesManager = ExcludedDateCompareManager::createInstance(
262 $this->originalEvent->getExcludedDateCollection(),
263 $this->event->getExcludedDateCollection()
264 );
265 if (!$excludedDatesManager->isEqual())
266 {
267 $this->differenceFields['excludedDates'] = $excludedDatesManager
268 ->getDiffCollection()->toString(';');
269 }
270 }
271 }
272
276 protected function compareReminders(): void
277 {
278 $remindersCompareManager = RemindCompareManager::createInstance(
279 $this->event->getRemindCollection() ?? new RemindCollection([]),
280 $this->originalEvent->getRemindCollection() ?? new RemindCollection([])
281 );
282 if (!$remindersCompareManager->isEqual())
283 {
284 $this->differenceFields['reminds'] = $remindersCompareManager->getDiffCollection()->toString(';');
285 }
286 }
287
291 public function getDiff(): array
292 {
293 return $this->differenceFields;
294 }
295}
static createInstance(?ExcludedDatesCollection $originalCollection, ?ExcludedDatesCollection $currentCollection)
static createInstance(RemindCollection $currentCollection, RemindCollection $originalCollection)