1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
eventmanager.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Sync\Icloud;
4
5use Bitrix\Calendar;
6use Bitrix\Calendar\Core;
7use Bitrix\Calendar\Core\Event\Event;
8use Bitrix\Calendar\Sync\Connection\Connection;
9use Bitrix\Calendar\Sync\Connection\EventConnection;
10use Bitrix\Calendar\Sync\Connection\SectionConnection;
11use Bitrix\Calendar\Sync\Connection\Server;
12use Bitrix\Calendar\Sync\Entities\SyncEvent;
13use Bitrix\Calendar\Sync\Managers\EventManagerInterface;
14use Bitrix\Calendar\Sync\Util\EventContext;
15use Bitrix\Calendar\Sync\Util\Context;
16use Bitrix\Calendar\Sync\Util\Result;
17use Bitrix\Main\Error;
18use Generator;
19
21{
35 {
36 $result = new Result();
37
38 $data = $this->getApiService()->createEvent($context->getSectionConnection()->getVendorSectionId(), $event);
39
40 if ($this->getApiService()->getError())
41 {
42 $this->processConnectionError($this->connection, $this->getApiService()->getError());
43 }
44
45 if ($data && is_array($data))
46 {
47 $result->setData([
48 'event' => [
49 'id' => $data['XML_ID'],
50 'version' => $data['MODIFICATION_LABEL'],
51 'etag' => $data['MODIFICATION_LABEL'],
52 ],
53 ]);
54 }
55 else
56 {
57 $result->addError(new Error('Error while trying to save event'));
58 }
59
60 return $result;
61 }
62
76 {
77 $result = new Result();
78 $event->setUid($context->getEventConnection()->getVendorEventId());
79
80 $context->getEventConnection()->setData($context->getEventConnection()->fetchData());
81
82 if ($event->getRecurringRule())
83 {
84 return $this->saveInstance($event, $context);
85 }
86
87 $data = $this->getApiService()->updateEvent(
88 $context->getSectionConnection()->getVendorSectionId(),
89 $event,
90 $context->getEventConnection()->getData()
91 );
92
93 if ($this->getApiService()->getError())
94 {
95 $this->processConnectionError($this->connection, $this->getApiService()->getError());
96 }
97
98 if ($data && is_array($data))
99 {
100 $result->setData([
101 'event' => [
102 'id' => $data['XML_ID'],
103 'version' => $data['MODIFICATION_LABEL'],
104 'etag' => $data['MODIFICATION_LABEL'],
105 ],
106 ]);
107 }
108 else
109 {
110 $result->addError(new Error('Error while trying to update event'));
111 }
112
113 return $result;
114 }
115
125 public function delete(Event $event, EventContext $context): Result
126 {
127 $result = new Result();
128 $sectionId = $context->getSectionConnection()->getVendorSectionId();
129 $event->setUid($context->getEventConnection()->getVendorEventId());
130
131 $data = $this->getApiService()->deleteEvent($sectionId, $event);
132
133 if ($this->getApiService()->getError())
134 {
135 $this->processConnectionError($this->connection, $this->getApiService()->getError());
136 }
137
138 if (!$data)
139 {
140 $result->addError(new Error('Error while trying delete event'));
141 }
142
143 return $result;
144 }
145
159 {
160 return $this->saveInstance($event, $context);
161 }
162
176 {
177 return $this->saveInstance($event, $context);
178 }
179
192 private function saveInstance(Event $event, EventContext $context): Result
193 {
194 $result = new Result();
195 $masterLink = $context->getEventConnection();
196
197 if (!$masterLink)
198 {
199 $result->addError(new Error('Master link not found'));
200
201 return $result;
202 }
203
204 $sectionId = $context->getSectionConnection()->getVendorSectionId();
205 $masterEvent = $masterLink->getEvent();
206 $masterEvent->setUid($masterLink->getVendorEventId());
207
208 $data = $this->getApiService()->saveInstance(
209 $sectionId,
210 $masterEvent,
211 $masterLink->getData()
212 );
213
214 if ($this->getApiService()->getError())
215 {
216 $this->processConnectionError($this->connection, $this->getApiService()->getError());
217 }
218
219 if ($data && is_array($data))
220 {
221 $result->setData([
222 'event' => [
223 'id' => $data['XML_ID'],
224 'version' => $data['MODIFICATION_LABEL'],
225 'etag' => $data['MODIFICATION_LABEL'],
226 ],
227 ]);
228 }
229 else
230 {
231 $result->addError(new Error('Error while trying to save instance'));
232 }
233
234 return $result;
235 }
236
250 {
251 $result = new Result();
252 $masterLink = $context->getEventConnection();
253
254 if (!$masterLink)
255 {
256 $result->addError(new Error('Master link not found'));
257
258 return $result;
259 }
260
261 $sectionId = $context->getSectionConnection()->getVendorSectionId();
262 $excludeDate = $context->sync['excludeDate'];
263 $masterEvent = $masterLink->getEvent();
264 $masterEvent->setUid($masterLink->getVendorEventId());
265
266 $data = $this->getApiService()->saveInstance(
267 $sectionId,
268 $masterEvent,
269 $masterLink->getData(),
270 $excludeDate
271 );
272
273 if ($this->getApiService()->getError())
274 {
275 $this->processConnectionError($this->connection, $this->getApiService()->getError());
276 }
277
278 if ($data && is_array($data))
279 {
280 $result->setData([
281 'event' => [
282 'id' => $data['XML_ID'],
283 'version' => $data['MODIFICATION_LABEL'],
284 'etag' => $data['MODIFICATION_LABEL'],
285 ],
286 ]);
287 }
288 else
289 {
290 $result->addError(new Error('Error while trying to delete instance'));
291 }
292
293 return $result;
294 }
295
309 public function saveRecurrence(
310 SyncEvent $recurrenceEvent,
311 SectionConnection $sectionConnection,
313 ): Result
314 {
315 $result = new Result();
316 $sectionId = $context->sync['vendorSectionId'];
317
318 $data = $this->getApiService()->saveRecurrence($sectionId, $recurrenceEvent);
319
320 if ($this->getApiService()->getError())
321 {
322 $this->processConnectionError($sectionConnection->getConnection(), $this->getApiService()->getError());
323 }
324
325 if ($data && is_array($data))
326 {
327 $masterEvent = $recurrenceEvent;
328
329 $this->prepareLink($masterEvent, $sectionConnection, $data['XML_ID'], $data['MODIFICATION_LABEL']);
330
332 foreach ($recurrenceEvent->getInstanceMap()->getCollection() as $instance)
333 {
334 $this->prepareLink($instance, $sectionConnection, $data['XML_ID']);
335 $instance->getEventConnection()->setRecurrenceId($data['XML_ID']);
336 }
337 }
338 else
339 {
340 $result->addError(new Error('Error while trying to save recurrence event'));
341 }
342
343 return $result;
344 }
345
358 public function createRecurrence(
359 SyncEvent $recurrenceEvent,
360 SectionConnection $sectionConnection,
362 ): Result
363 {
364 return $this->saveRecurrence($recurrenceEvent, $sectionConnection, $context);
365 }
366
379 public function updateRecurrence(
380 SyncEvent $recurrenceEvent,
381 SectionConnection $sectionConnection,
383 ): Result
384 {
385 return $this->saveRecurrence($recurrenceEvent, $sectionConnection, $context);
386 }
387
391 private function getApiService(): ApiService
392 {
393 if (!$this->apiService)
394 {
395 $this->apiService = new ApiService();
396 }
397
398 return $this->apiService;
399 }
400
409 private function prepareLink(
410 SyncEvent $event,
411 SectionConnection $connection,
412 string $vendorId,
413 ?string $entityTag = null
414 ): void
415 {
416 if ($event->getEventConnection())
417 {
418 $event->getEventConnection()
419 ->setLastSyncStatus(Calendar\Sync\Dictionary::SYNC_STATUS['success'])
420 ->setEntityTag($entityTag);
421 }
422 else
423 {
424 $link = (new EventConnection())
425 ->setId(null)
426 ->setEvent($event->getEvent())
427 ->setVersion($event->getEvent()->getVersion())
428 ->setConnection($connection->getConnection())
429 ->setVendorEventId($vendorId)
430 ->setEntityTag($entityTag)
431 ->setLastSyncStatus(Calendar\Sync\Dictionary::SYNC_STATUS['success'])
432 ;
433 $event->setEventConnection($link);
434 }
435 }
436
443 private function processConnectionError(Connection $connection, array $error): void
444 {
445 $parsedError = '[' . $error[0] . '] ' . $error[1];
446 \CDavConnection::SetLastResult($connection->getId(), $parsedError);
447 }
448}
$connection
Определения actionsdefinitions.php:38
updateRecurrence(SyncEvent $recurrenceEvent, SectionConnection $sectionConnection, Context $context)
Определения eventmanager.php:379
createRecurrence(SyncEvent $recurrenceEvent, SectionConnection $sectionConnection, Context $context)
Определения eventmanager.php:358
create(Event $event, EventContext $context)
Определения eventmanager.php:34
updateInstance(Event $event, EventContext $context)
Определения eventmanager.php:175
deleteInstance(Event $event, EventContext $context)
Определения eventmanager.php:249
createInstance(Event $event, EventContext $context)
Определения eventmanager.php:158
update(Event $event, EventContext $context)
Определения eventmanager.php:75
Определения error.php:15
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$context
Определения csv_new_setup.php:223
Определения culture.php:9
$event
Определения prolog_after.php:141
$instance
Определения ps_b24_final.php:14
$error
Определения subscription_card_product.php:20