1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
vendorsyncservice.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Sync\Office365;
4
5use Bitrix\Calendar\Core\Base\BaseException;
6use Bitrix\Calendar\Sync\Exceptions\ApiException;
7use Bitrix\Calendar\Sync\Exceptions\AuthException;
8use Bitrix\Calendar\Sync\Exceptions\ConflictException;
9use Bitrix\Calendar\Sync\Exceptions\GoneException;
10use Bitrix\Calendar\Sync\Exceptions\NotFoundException;
11use Bitrix\Calendar\Sync\Exceptions\RemoteAccountException;
12use Bitrix\Calendar\Sync\Internals\HasContextTrait;
13use Bitrix\Calendar\Sync\Office365\Dto\DateTimeDto;
14use Bitrix\Calendar\Sync\Office365\Dto\EventDto;
15use Bitrix\Calendar\Sync\Office365\Dto\SectionDto;
16use Bitrix\Calendar\Sync\Connection\SectionConnection;
17use Bitrix\Main\ArgumentException;
18use Bitrix\Main\ArgumentNullException;
19use Bitrix\Main\LoaderException;
20use Generator;
21
23{
24 use HasContextTrait;
25
29 private ApiService $apiService;
30
40 {
41 $this->context = $context;
42 $this->apiService = $context->getApiService();
43 }
44
57 public function getSections(array $params = []): array
58 {
59 $result = $this->apiService->getCalendarList($params);
60 return array_map(function ($row){
61 return new SectionDto($row);
62 }, $result);
63 }
64
77 public function getEvents(array $params): array
78 {
79 $result = $this->apiService->getEventList($params);
80
81 return array_map(function ($row){
82 return new EventDto($row);
83 }, $result);
84 }
85
98 public function getEvent(array $params): array
99 {
100 $result = $this->apiService->getEvent($params);
101
102 return array_map(function ($row){
103 return new EventDto($row);
104 }, $result);
105 }
106
119 public function createSection(SectionDto $sectionDto): SectionDto
120 {
121 $newSection = $this->apiService->createSection($sectionDto);
122
123 return new SectionDto($newSection);
124 }
125
138 public function updateSection(SectionDto $sectionDto): SectionDto
139 {
140 $newSection = $this->apiService->updateSection($sectionDto);
141
142 return new SectionDto($newSection);
143 }
144
158 public function createEvent(EventDto $dto, string $sectionId): ?EventDto
159 {
160 if ($newEvent = $this->apiService->createEvent($dto, $sectionId))
161 {
162 return new EventDto($newEvent);
163 }
164
165 return null;
166 }
167
180 public function getCalendarDelta(SectionConnection $sectionLink): Generator
181 {
182 foreach ($this->apiService->getCalendarDelta($sectionLink) as $batch)
183 {
184 $events = [];
185 foreach ($batch as $item) {
186 if (!empty($item['@removed']))
187 {
188 $events[$item['id']][Helper::EVENT_TYPES['deleted']] = new EventDto($item);
189 }
190 elseif ($item['type'] === Helper::EVENT_TYPES['single'])
191 {
192 $events[$item['id']][$item['type']] = new EventDto($item);
193 }
194 elseif ($item['type'] === Helper::EVENT_TYPES['series'])
195 {
196 $events[$item['id']][$item['type']] = new EventDto($item);
197 }
198 elseif ($item['type'] === Helper::EVENT_TYPES['exception'])
199 {
200 $events[$item['seriesMasterId']][Helper::EVENT_TYPES['exception']][$item['id']] = new EventDto($item);
201 $events[$item['seriesMasterId']][Helper::EVENT_TYPES['occurrence']][] = new DateTimeDto($item['start']);
202 }
203 elseif ($item['type'] === Helper::EVENT_TYPES['occurrence'])
204 {
205 $events[$item['seriesMasterId']][Helper::EVENT_TYPES['occurrence']][] = new DateTimeDto($item['start']);
206 }
207 }
208 foreach ($events as $id => $eventDelta)
209 {
210 yield $id => $eventDelta;
211 }
212 }
213 }
214
228 public function updateEvent(string $vendorEventId, EventDto $eventDto): ?EventDto
229 {
230 if ($event = $this->apiService->updateEvent($eventDto, $vendorEventId))
231 {
232 return new EventDto($event);
233 }
234
235 return null;
236 }
237
251 {
252 $result = $this->apiService->getEventInstances($params);
253
254 if (!empty($result['value']))
255 {
256 return array_map(function ($row){
257 return new EventDto($row);
258 }, $result['value']) ?? [];
259 }
260
261 return [];
262 }
263
276 public function deleteEvent(string $vendorEventId)
277 {
278 $this->apiService->deleteEvent($vendorEventId);
279 }
280
293 public function deleteSection(SectionDto $dto)
294 {
295 $this->apiService->deleteSection($dto->id);
296 }
297
310 public function subscribeSection(SectionConnection $link): ?array
311 {
312 $channelId = $this->getChannelId($link);
313 $result = $this->apiService->addSectionSubscription(
314 $link->getVendorSectionId(),
316 );
317
318 if ($result)
319 {
320 $result['channelId'] = $channelId;
321 }
322
323 return $result;
324 }
325
338 public function resubscribe(string $subscribeId): array
339 {
340 return $this->apiService->renewSectionSubscription($subscribeId);
341 }
342
354 public function unsubscribe(string $subscribeId): array
355 {
356 return $this->apiService->deleteSectionSubscription($subscribeId);
357 }
358
363 private function getChannelId(SectionConnection $link): string
364 {
365 return 'BX_OFFICE_SC_' . $link->getConnection()->getOwner()->getId() . '_' . md5($link->getId() . time());
366 }
367}
if(empty( $fields)) foreach($fields as $field) $channelId
Определения push.php:23
updateEvent(string $vendorEventId, EventDto $eventDto)
Определения vendorsyncservice.php:228
getCalendarDelta(SectionConnection $sectionLink)
Определения vendorsyncservice.php:180
createSection(SectionDto $sectionDto)
Определения vendorsyncservice.php:119
deleteEvent(string $vendorEventId)
Определения vendorsyncservice.php:276
updateSection(SectionDto $sectionDto)
Определения vendorsyncservice.php:138
__construct(Office365Context $context)
Определения vendorsyncservice.php:39
createEvent(EventDto $dto, string $sectionId)
Определения vendorsyncservice.php:158
subscribeSection(SectionConnection $link)
Определения vendorsyncservice.php:310
</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
$context
Определения csv_new_setup.php:223
$event
Определения prolog_after.php:141
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799