Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
sectionconnection.php
1<?php
2
4
5use Bitrix\Calendar\Core;
7use Bitrix\Calendar\Internals\EO_SectionConnection;
17use Exception;
18
20{
32 public function patch(
33 Sync\Connection\SectionConnection $sectionConnection,
34 array $fields
36 {
37 $sectionConnectionFields = $this->convertToArray($sectionConnection);
38
40 $sectionConnection->getId(),
41 array_intersect_key($sectionConnectionFields, array_flip($fields))
42 );
43
44 if ($result->isSuccess())
45 {
46 return $sectionConnection;
47 }
48
49 throw new BaseException('Error of delete SectionConnection: '
50 . implode('; ', $result->getErrorMessages()),
51 400);
52 }
53
60 public function convertToArray(Sync\Connection\SectionConnection $sectionConnection): array
61 {
62 if (!$sectionConnection->getConnection())
63 {
64 throw new BaseException('The sectionConnection must have an connection');
65 }
66
67 return [
68 'SECTION_ID' => $sectionConnection->getSection()->getId(),
69 'CONNECTION_ID' => $sectionConnection->getConnection()->getId(),
70 'VENDOR_SECTION_ID' => $sectionConnection->getVendorSectionId(),
71 'SYNC_TOKEN' => $sectionConnection->getSyncToken(),
72 'PAGE_TOKEN' => $sectionConnection->getPageToken(),
73 'ACTIVE' => $sectionConnection->isActive() ? self::POSITIVE_ANSWER : self::NEGATIVE_ANSWER,
74 'LAST_SYNC_DATE' => $sectionConnection->getLastSyncDate()
75 ? $sectionConnection->getLastSyncDate()->getDate()
76 : null,
77 'LAST_SYNC_STATUS' => $sectionConnection->getLastSyncStatus(),
78 'VERSION_ID' => $sectionConnection->getVersionId(),
79 'IS_PRIMARY' => $sectionConnection->isPrimary() ? self::POSITIVE_ANSWER : self::NEGATIVE_ANSWER,
80 ];
81 }
82
86 protected function getMapClass(): string
87 {
88 return Sync\Connection\SectionConnectionMap::class;
89 }
90
94 protected function getEntityName(): string
95 {
96 return 'section connection link';
97 }
98
108 protected function getOneEntityByFilter(array $filter): ?object
109 {
110 if (!Loader::includeModule('dav'))
111 {
112 return null;
113 }
116 ->setFilter($filter)
117 ->setSelect(['*', 'SECTION', 'CONNECTION'])
118 ->exec()->fetchObject();
119
120 if ($link !== null)
121 {
122 return $this->convertToObject($link);
123 }
124
125 return null;
126 }
127
135 protected function convertToObject($objectEO): ?Sync\Connection\SectionConnection
136 {
137 $section = $objectEO->getSection();
138 if ($section !== null)
139 {
140 $section = $this->prepareSection($section);
141 }
142 else
143 {
144 $objectEO->delete();
145
146 return null;
147 }
148
149 $connection = $objectEO->getConnection();
150 if ($connection !== null)
151 {
152 $connection = $this->prepareConnection($connection);
153 }
154 else
155 {
156 $objectEO->delete();
157
158 return null;
159 }
160
162 $item
163 ->setId($objectEO->getId())
164 ->setSection($section)
165 ->setConnection($connection)
166 ->setVendorSectionId($objectEO->getVendorSectionId())
167 ->setSyncToken($objectEO->getSyncToken())
168 ->setPageToken($objectEO->getPageToken())
169 ->setActive($objectEO->getActive())
170 ->setLastSyncDate(new Core\Base\Date($objectEO->getLastSyncDate()))
171 ->setLastSyncStatus($objectEO->getLastSyncStatus())
172 ->setVersionId($objectEO->get('VERSION_ID'))
173 ->setPrimary($objectEO->getIsPrimary())
174 ;
175
176 return $item;
177 }
178
188 protected function createEntity($entity, array $params = []): ?Core\Base\EntityInterface
189 {
190 $data = $this->convertToArray($entity);
191
192 $result = SectionConnectionTable::add($data);
193
194 if ($result->isSuccess())
195 {
196 return $entity->setId($result->getId());
197 }
198
199 throw new BaseException('Error of create SectionConnection: '
200 . implode('; ', $result->getErrorMessages()),
201 400);
202 }
203
213 protected function updateEntity($entity, array $params = []): ?Core\Base\EntityInterface
214 {
215 $data = $this->convertToArray($entity);
216
217 $result = SectionConnectionTable::update($entity->getId(), $data);
218
219 if ($result->isSuccess())
220 {
221 return $entity;
222 }
223
224 throw new BaseException('Error of update SectionConnection: '
225 . implode('; ', $result->getErrorMessages()),
226 400);
227 }
228
238 protected function deleteEntity(
239 Core\Base\EntityInterface $entity,
240 array $params = ['softDelete' => true]
241 ): ?Core\Base\EntityInterface
242 {
243 if (!empty($params['softDelete']))
244 {
245 $entity->setActive(false);
246 return $this->updateEntity($entity, $params);
247 }
248
249 $result = SectionConnectionTable::delete($entity->getId());
250
251 if ($result->isSuccess())
252 {
253 return null;
254 }
255
256 throw new BaseException('Error of delete SectionConnection: '
257 . implode('; ', $result->getErrorMessages()),
258 400);
259 }
260
271 protected function getDataManagerResult(array $params): Result
272 {
273 Loader::includeModule('dav');
274 if ($params['select'] === self::DEFAULT_SELECT)
275 {
276 $params['select'] = ["*", 'SECTION', 'CONNECTION'];
277 }
278
279 return SectionConnectionTable::getList($params);
280 }
281
285 protected function getEntityClass(): string
286 {
287 return Sync\Connection\SectionConnection::class;
288 }
289}
prepareSection(EO_Section $sectionEO)
Definition complex.php:33
prepareConnection(EO_DavConnection $connectionEO)
Definition complex.php:22
convertToArray(Sync\Connection\SectionConnection $sectionConnection)
deleteEntity(Core\Base\EntityInterface $entity, array $params=['softDelete'=> true])
patch(Sync\Connection\SectionConnection $sectionConnection, array $fields)
static getList(array $parameters=array())
static update($primary, array $data)