Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
eventconnection.php
1<?php
2
4
5use Bitrix\Calendar\Core;
7use Bitrix\Calendar\Internals\EO_EventConnection;
16use Exception;
17
19{
30 protected function getOneEntityByFilter(array $filter): ?object
31 {
32 if (!Loader::includeModule('dav'))
33 {
34 return null;
35 }
36
37 $link = EventConnectionTable::query()
38 ->setFilter($filter)
39 ->setSelect(['*', 'EVENT', 'CONNECTION'])
40 ->exec()->fetchObject();
41
42 if ($link === null)
43 {
44 return null;
45 }
46
47 return $this->convertToObject($link);
48 }
49
53 protected function getEntityName(): string
54 {
55 return 'event connection link';
56 }
57
67 protected function createEntity($entity, array $params = []): ?Core\Base\EntityInterface
68 {
69 $data = $this->convertToArray($entity);
70
71 $result = EventConnectionTable::add($data);
72 if ($result->isSuccess())
73 {
74 return $entity->setId($result->getId());
75 }
76
77 throw new BaseException('Error of create EventConnection: '
78 . implode('; ', $result->getErrorMessages()),
79 400);
80 }
81
93 protected function updateEntity($entity, array $params = []): ?Core\Base\EntityInterface
94 {
95 $data = $this->convertToArray($entity);
96
97 $result = EventConnectionTable::update($entity->getId(), $data);
98
99 if ($result->isSuccess())
100 {
101 return $entity;
102 }
103
104 throw new BaseException('Error of update EventConnection: '
105 . implode('; ', $result->getErrorMessages()),
106 400);
107 }
108
120 protected function deleteEntity(
121 Core\Base\EntityInterface $entity,
122 array $params = ['softDelete' => true]
123 ): ?Core\Base\EntityInterface
124 {
125// if (!empty($params['softDelete']))
126// {
127// $entity->setActive(false);
128// return $this->updateEntity($entity, $params);
129// }
130
131 $result = EventConnectionTable::delete($entity->getId());
132
133 if ($result->isSuccess())
134 {
135 return null;
136 }
137
138 throw new BaseException('Error of delete EventConnection: '
139 . implode('; ', $result->getErrorMessages()),
140 400);
141 }
142
146 protected function getMapClass(): string
147 {
148 return Sync\Connection\EventConnectionMap::class;
149 }
150
157 protected function convertToObject($objectEO): ?Sync\Connection\EventConnection
158 {
159 if ($objectEO->getEvent() === null || $objectEO->getConnection() === null)
160 {
161 $objectEO->delete();
162
163 return null;
164 }
165
166 $event = $this->prepareEvent($objectEO->getEvent());
167 $connection = $this->prepareConnection($objectEO->getConnection());
168
169 return (new Sync\Connection\EventConnection())
170 ->setLastSyncStatus($objectEO->getSyncStatus())
171 ->setRetryCount($objectEO->getRetryCount())
172 ->setVersion((int)$objectEO->getVersion())
173 ->setVendorEventId($objectEO->getVendorEventId())
174 ->setEntityTag($objectEO->getEntityTag())
175 ->setRecurrenceId($objectEO->getRecurrenceId())
176 ->setVendorVersionId($objectEO->getVendorVersionId())
177 ->setId($objectEO->getId())
178 ->setData($objectEO->getData())
179 ->setEvent($event)
180 ->setConnection($connection)
181 ;
182 }
183
189 private function convertToArray(Sync\Connection\EventConnection $entity): array
190 {
191 return [
192 'EVENT_ID' => $entity->getEvent()->getId(),
193 'CONNECTION_ID' => $entity->getConnection()->getId(),
194 'VENDOR_EVENT_ID' => $entity->getVendorEventId(),
195 'SYNC_STATUS' => $entity->getLastSyncStatus(),
196 'RETRY_COUNT' => $entity->getRetryCount(),
197 'ENTITY_TAG' => $entity->getEntityTag(),
198 'VENDOR_VERSION_ID' => $entity->getVendorVersionId(),
199 'VERSION' => $entity->getVersion(),
200 'DATA' => $entity->getData(),
201 'RECURRENCE_ID' => $entity->getRecurrenceId(),
202 ];
203 }
204
215 protected function getDataManagerResult(array $params): Result
216 {
217 Loader::includeModule('dav');
218 if ($params['select'] === self::DEFAULT_SELECT)
219 {
220 $params['select'] = ["*", 'EVENT', 'CONNECTION'];
221 }
222
223 return EventConnectionTable::getList($params);
224 }
225
229 protected function getEntityClass(): string
230 {
231 return Sync\Connection\EventConnection::class;
232 }
233}
prepareConnection(EO_DavConnection $connectionEO)
Definition complex.php:22
prepareEvent(EO_Event $eventEO)
Definition complex.php:44
deleteEntity(Core\Base\EntityInterface $entity, array $params=['softDelete'=> true])
delete(Core\Base\EntityInterface $entity, array $params=['softDelete'=> true])
Definition mapper.php:122