38 if (!Loader::includeModule(
'dav'))
43 $links = SectionConnectionTable::query()
44 ->setSelect([
'*',
'CONNECTION'])
45 ->addFilter(
'=SECTION_ID', $section->getId())
46 ->addFilter(
'=CONNECTION.IS_DELETED',
'N')
49 if ($availableService)
51 $links->addFilter(
'ACCOUNT_TYPE', $availableService);
54 $queryResult = $links->exec();
56 while ($link = $queryResult->fetchObject())
61 $context = self::prepareContextForSection($connection, $sectionConnection, $section);
64 $connection->getVendor()->getCode(),
79 public static function createByEvent(
Event $event, array $availableService =
null)
82 $links = self::getLinks($event->
getSection(), $availableService);
83 $eventLinks = self::getEventLinksByConnectionId($event);
86 while ($link = $links->fetchObject())
91 $context = self::prepareContextForSection($connection, $sectionConnection, $event->
getSection());
92 $context->add(
'sync',
'eventConnections', $eventLinks->getItem($connection->getId()));
95 $connection->getVendor()->getCode(),
118 if (!Loader::includeModule(
'dav'))
123 if (!$availableService)
125 $availableService = [
126 Sync\Google\Factory::SERVICE_NAME,
127 Sync\Icloud\Factory::SERVICE_NAME,
128 Sync\Office365\Factory::SERVICE_NAME,
132 $sectionConnection = DavConnectionTable::query()
134 ->where(
'ENTITY_ID', $userId)
135 ->where(
'ENTITY_TYPE',
'user')
136 ->where(
'IS_DELETED',
'N')
137 ->whereIn(
'ACCOUNT_TYPE', $availableService)
142 while ($connectionDM = $sectionConnection->fetchObject())
147 $connection->getVendor()->getCode(),
170 if (!Loader::includeModule(
'dav'))
175 $links = SectionConnectionTable::query()
176 ->setSelect([
'*',
'CONNECTION'])
177 ->where(
'SECTION_ID', $section->getId())
178 ->where(
'CONNECTION.IS_DELETED',
'N')
179 ->whereIn(
'CONNECTION.ACCOUNT_TYPE', [
180 Sync\Google\Factory::SERVICE_NAME,
181 Sync\Icloud\Factory::SERVICE_NAME,
182 Sync\Office365\Factory::SERVICE_NAME,
187 while ($link = $links->fetchObject())
191 'section_sync_data' => $link,
195 $connection->getVendor()->getCode(),
213 private static function prepareContextForSection(
220 $connectionsMap->add($connection, $connection->getId());
223 $sectionConnectionsMap->add($sectionConnection, $section->getId());
226 $sectionsMap->add($section, $section->getId());
229 'sections' => $sectionsMap,
230 'sectionConnections' => $sectionConnectionsMap,
231 'connections' => $connectionsMap
243 'connection_data' => $connection,
247 return new self([$factory]);
258 private static function getLinks(
260 ?array $availableService
263 Loader::includeModule(
'dav');
264 $links = SectionConnectionTable::query()
265 ->setSelect([
'*',
'CONNECTION'])
266 ->addFilter(
'SECTION_ID', $section->getId())
267 ->addFilter(
'=CONNECTION.IS_DELETED',
'N')
270 if ($availableService)
272 $links->addFilter(
'ACCOUNT_TYPE', $availableService);
278 private static function getServer($connection):
Server
280 return new Server($connection);
291 private static function getEventLinksByConnectionId(Event $event): Map
293 $links = EventConnectionTable::query()
295 ->addFilter(
'EVENT_ID', $event->getId())
299 $map =
new Sync\Connection\EventConnectionMap();
301 while ($link = $links->fetchObject())
303 $map->add((
new BuilderEventConnectionFromDM($link))->build(), $link->getConnectionId());