Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
sectionmanager.php
1<?php
2
4
9use Bitrix\Calendar\Core;
16
18{
27 public function create(Section $section, SectionContext $context): Result
28 {
29 $result = new Result();
30 $path = $this->connection->getServer()->getBasePath() . VendorSyncService::generateUuid();
31 $data = $this->getApiService()->createSection($path, $section);
32
33 if ($this->getApiService()->getError())
34 {
35 $this->processConnectionError($this->connection, $this->getApiService()->getError());
36 }
37
38 if ($data)
39 {
40 $result->setData([
41 'id' => $data['XML_ID'],
42 'version' => $data['MODIFICATION_LABEL']
43 ]);
44 }
45 else
46 {
47 $result->addError(new Error('Error while trying to save section'));
48 }
49
50 return $result;
51 }
52
61 public function update(Section $section, SectionContext $context): Result
62 {
63 $result = new Result();
64 $data = $this->getApiService()->updateSection($context->getSectionConnection()->getVendorSectionId(), $section);
65
66 if ($this->getApiService()->getError())
67 {
68 $this->processConnectionError($this->connection, $this->getApiService()->getError());
69 }
70
71 if ($data['XML_ID'])
72 {
73 $result->setData([
74 'id' => $data['XML_ID'],
75 'version' => $data['MODIFICATION_LABEL']
76 ]);
77 }
78 else
79 {
80 if ($data['ERROR'])
81 {
82 $result->setData([
83 'error' => $data['ERROR']
84 ]);
85 }
86
87 $result->addError(new Error('Error while trying to update section'));
88 }
89
90 return $result;
91 }
92
101 public function delete(Section $section, SectionContext $context): Result
102 {
103 $result = new Result();
104 $data = $this->getApiService()->deleteSection($context->getSectionConnection()->getVendorSectionId());
105
106 if ($this->getApiService()->getError())
107 {
108 $this->processConnectionError($this->connection, $this->getApiService()->getError());
109 }
110
111 if (!$data)
112 {
113 $result->addError(new Error('Error while trying to delete section'));
114 }
115
116 return $result;
117 }
118
122 private function getApiService(): ApiService
123 {
124 if (!$this->apiService)
125 {
126 $this->apiService = new ApiService();
127 }
128
129 return $this->apiService;
130 }
131
137 public function subscribe(SectionConnection $link): Result
138 {
139 return new Result();
140 }
141
147 public function resubscribe(Push $push): Result
148 {
149 return new Result();
150 }
151
158 public function getSections(Connection $connection): array
159 {
160 $result = [];
161 $server = $this->prepareServerData($connection->getServer());
162 $data = $this->getApiService($server)->getSectionsList($connection->getServer()->getBasePath());
163 if ($data && is_array($data))
164 {
165 foreach ($data as $section)
166 {
167 if ($section['supported-calendar-component-set'] === 'VEVENT')
168 {
169 $result[] = [
170 'XML_ID' => $section['href'],
171 'NAME' => $section['displayname'],
172 'DESCRIPTION' => $section['calendar-description'],
173 'TYPE' => $section['supported-calendar-component-set'],
174 'COLOR' => $section['calendar-color'],
175 'MODIFICATION_LABEL' => $section['getctag'],
176 ];
177 }
178 }
179 }
180
181 return $result;
182 }
183
184 public function getAvailableExternalType(): array
185 {
186 return [Helper::ACCOUNT_TYPE];
187 }
188
195 private function processConnectionError(Connection $connection, array $error): void
196 {
197 $parsedError = '[' . $error[0] . '] ' . $error[1];
198 \CDavConnection::SetLastResult($connection->getId(), $parsedError);
199 }
200}
create(Section $section, SectionContext $context)
update(Section $section, SectionContext $context)