Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
buildersyncsectionfromexternaldata.php
1<?php
2
4
8use Bitrix\Calendar\Core\User\Creator;
9use Bitrix\Calendar\Core;
16
18{
19 private array $item;
20 private Connection $connection;
21
22 public function __construct(array $item, Connection $connection)
23 {
24 $this->item = $item;
25 $this->connection = $connection;
26 }
27
32 public function build()
33 {
34 if ($this->connection->getOwner() === null)
35 {
36 throw new Core\Base\BaseException('The connection must have an owner');
37 }
38
39 $section = (new Section())
40 ->setName($this->item['summary'])
41 ->setColor($this->item['backgroundColor'])
42 ->setOwner($this->connection->getOwner())
43 ->setCreator($this->connection->getOwner())
44 ->setExternalType(Google\Dictionary::ACCESS_ROLE_TO_EXTERNAL_TYPE[$this->item['accessRole']])
45 ->setType(Core\Event\Tools\Dictionary::EVENT_TYPE[Core\Role\User::TYPE])
46 ->setIsActive(true)
47 ->setDescription($this->item['description'] ?? null)
48 ;
49
50 $sectionConnection = (new SectionConnection())
51 ->setVendorSectionId($this->item['id'])
52 ->setActive(true)
53 ->setLastSyncDate(null)
54 ->setPrimary($this->item['primary'] ?? false)
55 ->setSection($section)
56 ->setOwner($this->connection->getOwner())
57 ->setLastSyncStatus(Dictionary::SYNC_STATUS['success'])
58 ->setConnection($this->connection)
59 ->setVersionId($this->item['etag'])
60 ;
61
62 $syncSection = (new SyncSection())
63 ->setSection($section)
64 ->setSectionConnection($sectionConnection)
65 ->setVendorName(Factory::SERVICE_NAME)
66 ;
67
68 if (!empty($this->item['deleted']))
69 {
70 $syncSection->setAction(Dictionary::SYNC_SECTION_ACTION['delete']);
71 }
72 else
73 {
74 $syncSection->setAction(Dictionary::SYNC_SECTION_ACTION['success']);
75 }
76
77 return $syncSection;
78 }
79}