1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
sectionconnection.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Core\Mappers;
4
5use Bitrix\Calendar\Core;
6use Bitrix\Calendar\Core\Base\BaseException;
7use Bitrix\Calendar\Internals\EO_SectionConnection;
8use Bitrix\Calendar\Internals\SectionConnectionTable;
9use Bitrix\Calendar\Sync;
10use Bitrix\Main\ArgumentException;
11use Bitrix\Main\Loader;
12use Bitrix\Main\LoaderException;
13use Bitrix\Main\ObjectException;
14use Bitrix\Main\ObjectPropertyException;
15use Bitrix\Main\ORM\Query\Result;
16use Bitrix\Main\SystemException;
17use Exception;
18
20{
32 public function patch(
33 Sync\Connection\SectionConnection $sectionConnection,
36 {
37 $sectionConnectionFields = $this->convertToArray($sectionConnection);
38
39 $result = SectionConnectionTable::update(
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 }
115 $link = SectionConnectionTable::query()
116 ->setFilter($filter)
117 ->setSelect([
118 '*',
119 'SECTION',
120 'CONNECTION',
121 'SERVER_PASSWORD' => 'CONNECTION.SERVER_PASSWORD',
122 'SERVER_USERNAME' => 'CONNECTION.SERVER_USERNAME'
123 ])
124 ->exec()->fetchObject();
125
126 if ($link !== null)
127 {
128 return $this->convertToObject($link);
129 }
130
131 return null;
132 }
133
141 protected function convertToObject($objectEO): ?Sync\Connection\SectionConnection
142 {
143 $section = $objectEO->getSection();
144 if ($section !== null)
145 {
146 $section = $this->prepareSection($section);
147 }
148 else
149 {
150 $objectEO->delete();
151
152 return null;
153 }
154
155 $connection = $objectEO->getConnection();
156 if ($connection !== null)
157 {
159 }
160 else
161 {
162 $objectEO->delete();
163
164 return null;
165 }
166
168 $item
169 ->setId($objectEO->getId())
170 ->setSection($section)
171 ->setConnection($connection)
172 ->setVendorSectionId($objectEO->getVendorSectionId())
173 ->setSyncToken($objectEO->getSyncToken())
174 ->setPageToken($objectEO->getPageToken())
175 ->setActive($objectEO->getActive())
176 ->setLastSyncDate(new Core\Base\Date($objectEO->getLastSyncDate()))
177 ->setLastSyncStatus($objectEO->getLastSyncStatus())
178 ->setVersionId($objectEO->get('VERSION_ID'))
179 ->setPrimary($objectEO->getIsPrimary())
180 ;
181
182 return $item;
183 }
184
195 {
196 $data = $this->convertToArray($entity);
197
198 $result = SectionConnectionTable::add($data);
199
200 if ($result->isSuccess())
201 {
202 return $entity->setId($result->getId());
203 }
204
205 throw new BaseException('Error of create SectionConnection: '
206 . implode('; ', $result->getErrorMessages()),
207 400);
208 }
209
220 {
221 $data = $this->convertToArray($entity);
222
223 $result = SectionConnectionTable::update($entity->getId(), $data);
224
225 if ($result->isSuccess())
226 {
227 return $entity;
228 }
229
230 throw new BaseException('Error of update SectionConnection: '
231 . implode('; ', $result->getErrorMessages()),
232 400);
233 }
234
244 protected function deleteEntity(
246 array $params = ['softDelete' => true]
248 {
249 if (!empty($params['softDelete']))
250 {
251 $entity->setActive(false);
252 return $this->updateEntity($entity, $params);
253 }
254
255 $result = SectionConnectionTable::delete($entity->getId());
256
257 if ($result->isSuccess())
258 {
259 return null;
260 }
261
262 throw new BaseException('Error of delete SectionConnection: '
263 . implode('; ', $result->getErrorMessages()),
264 400);
265 }
266
278 {
279 Loader::includeModule('dav');
280 if ($params['select'] === self::DEFAULT_SELECT)
281 {
282 $params['select'] = [
283 "*",
284 'SECTION',
285 'CONNECTION',
286 'SERVER_PASSWORD' => 'CONNECTION.SERVER_PASSWORD',
287 'SERVER_USERNAME' => 'CONNECTION.SERVER_USERNAME'
288 ];
289 }
290
291 return SectionConnectionTable::getList($params);
292 }
293
297 protected function getEntityClass(): string
298 {
299 return Sync\Connection\SectionConnection::class;
300 }
301}
$connection
Определения actionsdefinitions.php:38
prepareSection(EO_Section $sectionEO)
Определения complex.php:33
prepareConnection(EO_DavConnection $connectionEO)
Определения complex.php:22
updateEntity($entity, array $params=[])
Определения sectionconnection.php:219
convertToArray(Sync\Connection\SectionConnection $sectionConnection)
Определения sectionconnection.php:60
deleteEntity(Core\Base\EntityInterface $entity, array $params=['softDelete'=> true])
Определения sectionconnection.php:244
createEntity($entity, array $params=[])
Определения sectionconnection.php:194
patch(Sync\Connection\SectionConnection $sectionConnection, array $fields)
Определения sectionconnection.php:32
Определения date.php:9
$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
$entity
$filter
Определения iblock_catalog_list.php:54
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$fields
Определения yandex_run.php:501