Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
syncevent.php
1<?php
3
4use Bitrix\Calendar\Core;
6
8{
20 protected ?InstanceMap $instanceMap = null;
24 protected ?string $action = null;
25
29 public function getEvent(): Core\Event\Event
30 {
31 return $this->event;
32 }
33
38 public function setEvent(Core\Event\Event $event): SyncEvent
39 {
40 $this->event = $event;
41
42 return $this;
43 }
44
48 public function getEventConnection(): ?Sync\Connection\EventConnection
49 {
51 }
52
58 public function setEventConnection(?Sync\Connection\EventConnection $eventConnection): SyncEvent
59 {
60 $this->eventConnection = $eventConnection;
61
62 return $this;
63 }
64
70 public function setAction(?string $action): SyncEvent
71 {
72 $this->action = $action ?? '';
73
74 return $this;
75 }
76
80 public function getAction(): ?string
81 {
82 return $this->action;
83 }
84
88 public function getId(): ?int
89 {
90 return $this->getEvent() ? $this->getEvent()->getId() : null;
91 }
92
96 public function getEventId(): ?int
97 {
98 return $this->event->getId();
99 }
100
104 public function getParentId(): ?int
105 {
106 return $this->event->getParentId();
107 }
108
112 public function getEntityTag(): ?string
113 {
114 return $this->eventConnection->getEntityTag();
115 }
116
120 public function getVendorEventId(): string
121 {
122 return $this->eventConnection->getVendorEventId();
123 }
124
128 public function getUid(): ?string
129 {
130 return $this->event->getUid();
131 }
132
136 public function isRecurrence(): bool
137 {
138 return $this->event->isRecurrence();
139 }
140
146 {
147 $this->instanceMap = $instanceMap;
148
149 return $this;
150 }
151
155 public function getInstanceMap(): ?InstanceMap
156 {
157 return $this->instanceMap;
158 }
159
163 public function isInstance(): bool
164 {
165 return $this->event->isInstance();
166 }
167
174 public function addInstance(SyncEvent $instance): self
175 {
176 if ($this->instanceMap === null)
177 {
178 $this->instanceMap = new InstanceMap();
179 }
180
181 if (!$this->event->getExcludedDateCollection())
182 {
183 $this->event->setExcludedDateCollection(new Core\Event\Properties\ExcludedDatesCollection());
184 }
185
186 $instance->getEvent()->getOriginalDateFrom()
187 ? $this->updateExcludedDatesMasterEvent($instance->getEvent()->getOriginalDateFrom())
188 : $this->updateExcludedDatesMasterEvent($instance->getEvent()->getStart())
189 ;
190
191 $this->instanceMap->add($instance);
192
193 return $this;
194 }
195
202 public function addInstanceList(array $list): SyncEvent
203 {
204 if ($this->instanceMap === null)
205 {
206 $this->instanceMap = new InstanceMap();
207 }
208
210 foreach ($list as $item)
211 {
212 $this->addInstance($item);
213 }
214
215 return $this;
216 }
217
221 public function hasInstances(): bool
222 {
223 return $this->instanceMap !== null && $this->instanceMap->count();
224 }
225
229 public function getVendorRecurrenceId(): ?string
230 {
231 if (!$this->eventConnection)
232 {
233 return null;
234 }
235
236 return $this->eventConnection->getRecurrenceId();
237 }
238
242 public function isSuccessAction(): bool
243 {
244 return $this->action === Sync\Dictionary::SYNC_SECTION_ACTION['success'];
245 }
246
252 private function updateExcludedDatesMasterEvent(Core\Base\Date $excludedDate): void
253 {
254 $date = clone $excludedDate;
255 $date->setDateTimeFormat(Core\Event\Properties\ExcludedDatesCollection::EXCLUDED_DATE_FORMAT);
256
257 if ($this->event->getExcludedDateCollection())
258 {
259 $this->addExcludeDate($date);
260 }
261 else
262 {
263 $this->event->setExcludedDateCollection(new Core\Event\Properties\ExcludedDatesCollection([$date]));
264 }
265 }
266
270 public function isBaseEvent(): bool
271 {
272 return $this->event->isBaseEvent();
273 }
274
278 public function isSingle(): bool
279 {
280 return $this->event->isSingle();
281 }
282
288 private function addExcludeDate(Core\Base\Date $newExDate)
289 {
291 foreach ($this->event->getExcludedDateCollection() as $exDate)
292 {
293 if ($exDate->format('Ymd') === $newExDate->format('Ymd'))
294 {
295 return;
296 }
297 }
298
299 $this->event->getExcludedDateCollection()->add($newExDate);
300 }
301}
setEvent(Core\Event\Event $event)
Definition syncevent.php:38
Sync Connection EventConnection $eventConnection
Definition syncevent.php:16
setEventConnection(?Sync\Connection\EventConnection $eventConnection)
Definition syncevent.php:58
setInstanceMap(?InstanceMap $instanceMap)