Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
eventconnectionfactory.php
1<?php
2
4
7use Bitrix\Calendar\Internals\EO_EventConnection;
16
18{
30 public function getEventConnection(array $params): ?EventConnection
31 {
32 if (!Loader::includeModule('dav'))
33 {
34 return null;
35 }
36
37 $select = ['*'];
38 if (empty($params['event']))
39 {
40 $select[] = 'EVENT';
41 }
42 if (empty($params['connection']))
43 {
44 $select[] = 'CONNECTION';
45 }
46
47 $statement = EventConnectionTable::query();
48 $statement->setSelect($select);
49 if (!empty($params['filter']))
50 {
51 $statement->setFilter($params['filter']);
52 }
53
54 $link = $statement->exec()->fetchObject() ?: null;
55 if ($link === null)
56 {
57 return null;
58 }
59
60 $event = $params['event']
61 ?? (new EventBuilderFromEntityObject($link->getEvent()))->build();
62
63 $connection = $params['connection']
64 ?? (new BuilderConnectionFromDM($link->getConnection()))->build();
65
66 $result = new EventConnection();
67 $result
68 ->setId($link->getId())
69 ->setEvent($event)
70 ->setConnection($connection)
71 ->setVendorEventId($link->getVendorEventId())
72 ->setLastSyncStatus($link->getSyncStatus())
73 ->setEntityTag($link->getEntityTag())
74 ->setVersion($link->getVersion())
75 ->setData($link->getData())
76 ;
77
78 return $result;
79 }
80
91 public function getFromEventConnection(Event $event, Connection $connection): ?EventConnection
92 {
93 $statement = EventConnectionTable::query()
94 ->setSelect(['*'])
95 ->addFilter('EVENT_ID', $event->getId())
96 ->addFilter('CONNECTION_ID', $connection->getId())
97 ->exec()
98 ;
100 $link = $statement->fetchObject() ?: null;
101 if ($link === null)
102 {
103 return null;
104 }
105 $result = new EventConnection();
106 $result
107 ->setId($link->getId())
108 ->setEvent($event)
109 ->setConnection($connection)
110 ->setVendorEventId($link->getVendorEventId())
111 ->setLastSyncStatus($link->getSyncStatus())
112 ->setEntityTag($link->getEntityTag())
113 ->setVersion($link->getVersion())
114 ->setData($link->getData())
115 ;
116
117 return $result;
118 }
119}