Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
syncevent.php
1<?php
2
4
10
12{
16 private Event $eventMapper;
20 private EventConnection $eventConnectionMapper;
21
22 public function __construct()
23 {
24 $helper = ServiceLocator::getInstance()->get('calendar.service.mappers.factory');
25 $this->eventMapper = $helper->getEvent();
26 $this->eventConnectionMapper = $helper->getEventConnection();
27 }
28
33 public function getSyncEventCollectionByIdCollection(array $collection): Sync\Entities\SyncEventMap
34 {
35 $filter = ['VENDOR_EVENT_ID' => $collection];
36 $eventConnectionMap = $this->eventConnectionMapper->getMap($filter);
37
38 $syncEventMap = new Sync\Entities\SyncEventMap();
40 foreach ($eventConnectionMap as $item)
41 {
42 $syncEventMap->add($item, $item->getVendorEventId());
43 }
44
45 return $syncEventMap;
46 }
47
48 public function getSyncEventWithVendorId(string $vendorId): Sync\Entities\SyncEvent
49 {
50 $eventConnectionDM = EventConnectionTable::query()
51 ->addFilter('VENDOR_EVENT_ID', $vendorId)
52 ->setSelect(['*'])
53 ->exec()
54 ->fetchObject()
55 ;
56
57 if ($eventConnectionDM)
58 {
59 $syncEvent = new Sync\Entities\SyncEvent();
60 $eventConnection = (new Sync\Builders\BuilderEventConnectionFromDM($eventConnectionDM))->build();
61 $syncEvent
62 ->setEventConnection($eventConnection)
63 ->setEvent((new EventBuilderFromEntityObject($eventConnectionDM->getEvent()))->build())
64 ;
65
66 return $syncEvent;
67 }
68
69 throw new BaseException('do not get SyncEvent');
70 }
71
78 public function delete(Sync\Entities\SyncEvent $syncEvent): Sync\Entities\SyncEvent
79 {
80 try
81 {
82 $event = $this->eventMapper->delete($syncEvent->getEvent());
83 $eventConnection = $syncEvent->getEventConnection();
84
85 if ($eventConnection === null)
86 {
87 throw new BaseException('you should send eventConnection property');
88 }
89
90 $eventConnection->setEvent($event);
91 $syncEvent->setEventConnection($this->eventConnectionMapper->delete($eventConnection));
92 $syncEvent->setEvent($event);
93
94 return $syncEvent;
95 }
96 catch (BaseException $exception)
97 {
98 throw new BaseException($exception->getMessage());
99 }
100 }
101}
delete(Sync\Entities\SyncEvent $syncEvent)
Definition syncevent.php:78
getSyncEventWithVendorId(string $vendorId)
Definition syncevent.php:48