1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
factoriescollection.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Sync\Factories;
4
5use Bitrix\Calendar\Core\Base\Collection;
6use Bitrix\Calendar\Core\Base\Map;
7use Bitrix\Calendar\Core\Event\Event;
8use Bitrix\Calendar\Core\Section\Section;
9use Bitrix\Calendar\Core\Section\SectionMap;
10use Bitrix\Calendar\Internals\EO_SectionConnection;
11use Bitrix\Calendar\Internals\EventConnectionTable;
12use Bitrix\Calendar\Internals\SectionConnectionTable;
13use Bitrix\Calendar\Sync\Builders\BuilderEventConnectionFromDM;
14use Bitrix\Calendar\Sync\Connection\Connection;
15use Bitrix\Calendar\Sync\Connection\Server;
16use Bitrix\Calendar\Sync;
17use Bitrix\Calendar\Sync\Util\Context;
18use Bitrix\Dav\Internals\DavConnectionTable;
19use Bitrix\Main\ArgumentException;
20use Bitrix\Main\Loader;
21use Bitrix\Main\ObjectException;
22use Bitrix\Main\ObjectPropertyException;
23use Bitrix\Main\ORM\Query\Query;
24use Bitrix\Main\SystemException;
25
27{
34 public static function createBySectionId(Section $section, array $availableService = null): FactoriesCollection
35 {
36 $collection = [];
37
38 if (!Loader::includeModule('dav'))
39 {
40 return new self($collection);
41 }
42 // $links = self::getLinks($section, $availableService);
43 $links = SectionConnectionTable::query()
44 ->setSelect([
45 '*',
46 'CONNECTION',
47 ])
48 ->addFilter('=SECTION_ID', $section->getId())
49 ->addFilter('=CONNECTION.IS_DELETED', 'N')
50 ;
51
52 if ($availableService)
53 {
54 $links->addFilter('ACCOUNT_TYPE', $availableService);
55 }
56
57 $queryResult = $links->exec();
58
59 while ($link = $queryResult->fetchObject())
60 {
61 $connection = (new Sync\Builders\BuilderConnectionFromDM($link->getConnection()))->build();
62 $sectionConnection = (new Sync\Builders\BuilderSectionConnectionFromDM($link))->build();
63
64 $context = self::prepareContextForSection($connection, $sectionConnection, $section);
65
66 $collection[] = FactoryBuilder::create(
67 $connection->getVendor()->getCode(),
70 );
71 }
72
73 return new self($collection);
74 }
75
82 public static function createByEvent(Event $event, array $availableService = null)
83 {
84 $collection = [];
85 $links = self::getLinks($event->getSection(), $availableService);
86 $eventLinks = self::getEventLinksByConnectionId($event);
87
89 while ($link = $links->fetchObject())
90 {
91 $connection = (new Sync\Builders\BuilderConnectionFromDM($link->getConnection()))->build();
92 $sectionConnection = (new Sync\Builders\BuilderSectionConnectionFromDM($link))->build();
93
94 $context = self::prepareContextForSection($connection, $sectionConnection, $event->getSection());
95 $context->add('sync', 'eventConnections', $eventLinks->getItem($connection->getId()));
96
97 $collection[] = FactoryBuilder::create(
98 $connection->getVendor()->getCode(),
101 );
102 }
103
104 return new self($collection);
105 }
106
118 public static function createByUserId(int $userId, array $availableService = []): FactoriesCollection
119 {
120 $collection = [];
121 if (!Loader::includeModule('dav'))
122 {
123 return new self($collection);
124 }
125
126 if (!$availableService)
127 {
128 $availableService = [
132 ];
133 }
134
135 $sectionConnection = DavConnectionTable::query()
136 ->setSelect(['*'])
137 ->where('ENTITY_ID', $userId)
138 ->where('ENTITY_TYPE', 'user')
139 ->where('IS_DELETED', 'N')
140 ->whereIn('ACCOUNT_TYPE', $availableService)
141 ->exec()
142 ;
143 $context = new Context([]);
144
145 while ($connectionDM = $sectionConnection->fetchObject())
146 {
147 $connection = (new Sync\Builders\BuilderConnectionFromDM($connectionDM))->build();
148
149 $collection[] = FactoryBuilder::create(
150 $connection->getVendor()->getCode(),
153 );
154 }
155
156 return new self($collection);
157 }
158
169 public static function createBySection(Section $section): FactoriesCollection
170 {
171 $collection = [];
172
173 if (!Loader::includeModule('dav'))
174 {
175 return new self($collection);
176 }
177
178 $links = SectionConnectionTable::query()
179 ->setSelect([
180 '*',
181 'CONNECTION',
182 ])
183 ->where('SECTION_ID', $section->getId())
184 ->where('CONNECTION.IS_DELETED', 'N')
185 ->whereIn('CONNECTION.ACCOUNT_TYPE', [
186 Sync\Google\Factory::SERVICE_NAME,
187 Sync\Icloud\Factory::SERVICE_NAME,
188 Sync\Office365\Factory::SERVICE_NAME,
189 ])
190 ->exec()
191 ;
192
193 while ($link = $links->fetchObject())
194 {
195 $connection = (new Sync\Builders\BuilderConnectionFromDM($link->getConnection()))->build();
196 $context = new Context([
197 'section_sync_data' => $link,
198 ]);
199
200 $collection[] = FactoryBuilder::create(
201 $connection->getVendor()->getCode(),
204 );
205 }
206
207 return new self(array_filter($collection));
208 }
209
219 private static function prepareContextForSection(
221 Sync\Connection\SectionConnection $sectionConnection,
222 Section $section
223 ): Context
224 {
225 $connectionsMap = new Sync\Connection\ConnectionMap();
226 $connectionsMap->add($connection, $connection->getId());
227
228 $sectionConnectionsMap = new Sync\Connection\SectionConnectionMap();
229 $sectionConnectionsMap->add($sectionConnection, $section->getId());
230
231 $sectionsMap = new SectionMap();
232 $sectionsMap->add($section, $section->getId());
233
234 return new Context([
235 'sections' => $sectionsMap,
236 'sectionConnections' => $sectionConnectionsMap,
237 'connections' => $connectionsMap
238 ]);
239 }
240
247 {
248 $context = new Context([
249 'connection_data' => $connection,
250 ]);
251 $factory = FactoryBuilder::create($connection->getVendor()->getCode(), $connection, $context);
252
253 return new self([$factory]);
254 }
255
264 private static function getLinks(
265 Section $section,
266 ?array $availableService
267 ): Query
268 {
269 Loader::includeModule('dav');
270 $links = SectionConnectionTable::query()
271 ->setSelect([
272 '*',
273 'CONNECTION',
274 ])
275 ->addFilter('SECTION_ID', $section->getId())
276 ->addFilter('=CONNECTION.IS_DELETED', 'N')
277 ;
278
279 if ($availableService)
280 {
281 $links->addFilter('ACCOUNT_TYPE', $availableService);
282 }
283
284 return $links;
285 }
286
287 private static function getServer($connection): Server
288 {
289 return new Server($connection);
290 }
291
300 private static function getEventLinksByConnectionId(Event $event): Map
301 {
302 $links = EventConnectionTable::query()
303 ->setSelect(['*'])
304 ->addFilter('EVENT_ID', $event->getId())
305 ->exec()
306 ;
307
308 $map = new Sync\Connection\EventConnectionMap();
309
310 while ($link = $links->fetchObject())
311 {
312 $map->add((new BuilderEventConnectionFromDM($link))->build(), $link->getConnectionId());
313 }
314
315 return $map;
316 }
317}
$connection
Определения actionsdefinitions.php:38
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static createBySectionId(Section $section, array $availableService=null)
Определения factoriescollection.php:34
static createByUserId(int $userId, array $availableService=[])
Определения factoriescollection.php:118
static createBySection(Section $section)
Определения factoriescollection.php:169
static createByConnection(Connection $connection)
Определения factoriescollection.php:246
static create(string $accountType, Sync\Connection\Connection $connection, Sync\Util\Context $context)
Определения factorybuilder.php:24
Определения server.php:11
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$context
Определения csv_new_setup.php:223
$map
Определения config.php:5
Определения culture.php:9
Определения chain.php:3
$event
Определения prolog_after.php:141