29 public function __construct()
31 Loader::includeModule(
'dav');
33 $mapperHelper = ServiceLocator::getInstance()->get(
'calendar.service.mappers.factory');
34 $this->sectionConnectionMapper = $mapperHelper->getSectionConnection();
35 $this->sectionMapper = $mapperHelper->getSection();
48 $this->getLocalSyncSectionMapByUserId(
53 $this->getExternalSyncSectionMapByUserId(
60 return $syncSectionMap;
75 public function getLocalSyncSectionMapByUserId(
81 $sectionDb = SectionTable::query()
92 'CONNECTION.ACCOUNT_TYPE',
93 'SECTION_CONNECTION.*',
94 'SECTION_CONNECTION.SECTION',
95 'SECTION_CONNECTION.CONNECTION',
98 ->where(
'EXTERNAL_TYPE',
Core\
Mappers\Section::SECTION_TYPE_LOCAL)
99 ->where(
'CAL_TYPE',
Core\
Role\User::TYPE)
100 ->registerRuntimeField(
'SECTION_CONNECTION',
103 SectionConnectionTable::getEntity(),
104 Join::on(
'ref.SECTION_ID',
'this.ID')->where(
'ref.CONNECTION_ID', $connectionId),
105 [
'join_type' => Join::TYPE_LEFT]
108 ->registerRuntimeField(
'CONNECTION',
111 DavConnectionTable::getEntity(),
112 Join::on(
'ref.ID',
'this.SECTION_CONNECTION.CONNECTION_ID'),
113 [
'join_type' => Join::TYPE_LEFT]
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()
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);