31 Loader::includeModule(
'dav');
33 $mapperHelper = ServiceLocator::getInstance()->get(
'calendar.service.mappers.factory');
34 $this->sectionConnectionMapper = $mapperHelper->getSectionConnection();
35 $this->sectionMapper = $mapperHelper->getSection();
46 $connectionId = $connection->getId();
47 $ownerId = $connection->getOwner()->getId();
48 $this->getLocalSyncSectionMapByUserId(
53 $this->getExternalSyncSectionMapByUserId(
60 return $syncSectionMap;
75 public function getLocalSyncSectionMapByUserId(
81 $sectionDb = SectionTable::query()
82 ->where(
'OWNER_ID', $userId)
83 ->where(
'EXTERNAL_TYPE', Core\Mappers\Section::SECTION_TYPE_LOCAL)
84 ->where(
'CAL_TYPE', Core\Role\User::TYPE)
85 ->registerRuntimeField(
'SECTION_CONNECTION',
88 SectionConnectionTable::getEntity(),
89 Join::on(
'ref.SECTION_ID',
'this.ID')->where(
'ref.CONNECTION_ID', $connectionId),
90 [
'join_type' => Join::TYPE_LEFT]
93 ->registerRuntimeField(
'CONNECTION',
96 DavConnectionTable::getEntity(),
97 Join::on(
'ref.ID',
'this.SECTION_CONNECTION.CONNECTION_ID'),
98 [
'join_type' => Join::TYPE_LEFT]
111 'CONNECTION.ACCOUNT_TYPE',
112 'SECTION_CONNECTION.*',
113 'SECTION_CONNECTION.SECTION',
114 'SECTION_CONNECTION.CONNECTION',
119 while ($sectionDM = $sectionDb->fetchObject())
126 ->setSection($section)
127 ->setAction(
'success')
131 if ($sectionConnectionDM = $sectionDM->get(
'SECTION_CONNECTION'))
135 $sectionConnection->setSection($section);
136 $syncSection->setSectionConnection($sectionConnection);
137 $sectionId = $sectionConnection->getVendorSectionId();
141 if ($sectionDM->getExternalType() !== Section::SECTION_TYPE_LOCAL && ($connectionDM = $sectionDM->get(
'CONNECTION')))
143 $syncSection->setVendorName($connectionDM->getAccountType());
147 $syncSection->setVendorName($sectionDM->getExternalType() ?? Section::SECTION_TYPE_LOCAL);
150 $sectionId = $sectionId ?? (string)$section->getId();
152 $syncSectionMap->add($syncSection, $sectionId);
167 public function getExternalSyncSectionMapByUserId(
170 Sync\Entities\SyncSectionMap $syncSectionMap,
174 $sectionDb = SectionTable::query()
175 ->where(
'OWNER_ID', $userId)
176 ->whereIn(
'EXTERNAL_TYPE', $externalType)
177 ->where(
'CAL_TYPE', Core\Role\User::TYPE)
178 ->registerRuntimeField(
'SECTION_CONNECTION',
181 SectionConnectionTable::getEntity(),
182 Join::on(
'ref.SECTION_ID',
'this.ID'),
183 [
'join_type' => Join::TYPE_LEFT]
186 ->registerRuntimeField(
'CONNECTION',
189 DavConnectionTable::getEntity(),
190 Join::on(
'ref.ID',
'this.SECTION_CONNECTION.CONNECTION_ID'),
191 [
'join_type' => Join::TYPE_LEFT]
204 'CONNECTION.ACCOUNT_TYPE',
205 'SECTION_CONNECTION.*',
206 'SECTION_CONNECTION.SECTION',
207 'SECTION_CONNECTION.CONNECTION',
212 while ($sectionDM = $sectionDb->fetchObject())
215 $syncSection =
new Sync\Entities\SyncSection();
217 $section = (
new SectionBuilderFromDataManager($sectionDM))->build();
219 ->setSection($section)
220 ->setAction(
'success')
224 if ($sectionConnectionDM = $sectionDM->get(
'SECTION_CONNECTION'))
226 $sectionConnection = (
new Sync\Builders\BuilderSectionConnectionFromDM($sectionConnectionDM))->build();
228 ($sectionConnection->getConnection() !==
null)
229 && ($sectionConnection->getConnection()->getId() !== $connectionId)
235 $sectionConnection->setSection($section);
236 $syncSection->setSectionConnection($sectionConnection);
237 $sectionId = $sectionConnection->getVendorSectionId();
245 if ($sectionDM->getExternalType() !== Section::SECTION_TYPE_LOCAL && ($connectionDM = $sectionDM->get(
'CONNECTION')))
247 $syncSection->setVendorName($connectionDM->getAccountType());
251 $syncSection->setVendorName($sectionDM->getExternalType() ?? Section::SECTION_TYPE_LOCAL);
256 $syncSectionMap->add($syncSection, $sectionId);