1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
syncsectionfactory.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Sync\Factories;
4
5use Bitrix\Calendar\Core\Builders\SectionBuilderFromDataManager;
6use Bitrix\Calendar\Core\Mappers\Section;
7use Bitrix\Calendar\Internals\EO_SectionConnection;
8use Bitrix\Calendar\Internals\SectionConnectionTable;
9use Bitrix\Calendar\Internals\SectionTable;
10use Bitrix\Calendar\Sync\Entities\SyncSectionMap;
11use Bitrix\Dav\Internals\DavConnectionTable;
12use Bitrix\Dav\Internals\EO_DavConnection;
13use Bitrix\Main\ArgumentException;
14use Bitrix\Main\DI\ServiceLocator;
15use Bitrix\Calendar\Core;
16use Bitrix\Calendar\Sync;
17use Bitrix\Main\Entity\ReferenceField;
18use Bitrix\Main\Loader;
19use Bitrix\Main\ObjectException;
20use Bitrix\Main\ObjectPropertyException;
21use Bitrix\Main\ORM\Query\Join;
22use Bitrix\Main\SystemException;
23
25{
28
29 public function __construct()
30 {
31 Loader::includeModule('dav');
33 $mapperHelper = ServiceLocator::getInstance()->get('calendar.service.mappers.factory');
34 $this->sectionConnectionMapper = $mapperHelper->getSectionConnection();
35 $this->sectionMapper = $mapperHelper->getSection();
36 }
37
43 {
44 $syncSectionMap = new SyncSectionMap();
45 $connection = $factory->getConnection();
46 $connectionId = $connection->getId();
47 $ownerId = $connection->getOwner()->getId();
48 $this->getLocalSyncSectionMapByUserId(
49 $ownerId,
50 $connectionId,
51 $syncSectionMap
52 );
53 $this->getExternalSyncSectionMapByUserId(
54 $ownerId,
55 $connectionId,
56 $syncSectionMap,
57 $factory->getSectionManager()->getAvailableExternalType()
58 );
59
60 return $syncSectionMap;
61 }
62
75 public function getLocalSyncSectionMapByUserId(
76 int $userId,
77 int $connectionId,
78 Sync\Entities\SyncSectionMap $syncSectionMap
79 ): void
80 {
81 $sectionDb = SectionTable::query()
82 ->setSelect([
83 'ID',
84 'NAME',
85 'XML_ID',
86 'ACTIVE',
87 'DESCRIPTION',
88 'COLOR',
89 'CAL_TYPE',
90 'OWNER_ID',
91 'EXTERNAL_TYPE',
92 'CONNECTION.ACCOUNT_TYPE',
93 'SECTION_CONNECTION.*',
94 'SECTION_CONNECTION.SECTION',
95 'SECTION_CONNECTION.CONNECTION',
96 ])
97 ->where('OWNER_ID', $userId)
98 ->where('EXTERNAL_TYPE', Core\Mappers\Section::SECTION_TYPE_LOCAL)
99 ->where('CAL_TYPE', Core\Role\User::TYPE)
100 ->registerRuntimeField('SECTION_CONNECTION',
101 new ReferenceField(
102 'SYNC_DATA',
103 SectionConnectionTable::getEntity(),
104 Join::on('ref.SECTION_ID', 'this.ID')->where('ref.CONNECTION_ID', $connectionId),
105 ['join_type' => Join::TYPE_LEFT]
106 )
107 )
108 ->registerRuntimeField('CONNECTION',
109 new ReferenceField(
110 'CONNECTION',
111 DavConnectionTable::getEntity(),
112 Join::on('ref.ID', 'this.SECTION_CONNECTION.CONNECTION_ID'),
113 ['join_type' => Join::TYPE_LEFT]
114 )
115 )
116 ->exec()
117 ;
118
119 while ($sectionDM = $sectionDb->fetchObject())
120 {
121 $sectionId = null;
122 $syncSection = new Sync\Entities\SyncSection();
123
124 $section = (new SectionBuilderFromDataManager($sectionDM))->build();
125 $syncSection
126 ->setSection($section)
127 ->setAction('success')
128 ;
129
131 if ($sectionConnectionDM = $sectionDM->get('SECTION_CONNECTION'))
132 {
133 $sectionConnection = (new Sync\Builders\BuilderSectionConnectionFromDM($sectionConnectionDM))->build();
134
135 $sectionConnection->setSection($section);
136 $syncSection->setSectionConnection($sectionConnection);
137 $sectionId = $sectionConnection->getVendorSectionId();
138 }
139
141 if ($sectionDM->getExternalType() !== Section::SECTION_TYPE_LOCAL && ($connectionDM = $sectionDM->get('CONNECTION')))
142 {
143 $syncSection->setVendorName($connectionDM->getAccountType());
144 }
145 else
146 {
147 $syncSection->setVendorName($sectionDM->getExternalType() ?? Section::SECTION_TYPE_LOCAL);
148 }
149
150 $sectionId = $sectionId ?? (string)$section->getId();
151
152 $syncSectionMap->add($syncSection, $sectionId);
153 }
154 }
155
167 public function getExternalSyncSectionMapByUserId(
168 int $userId,
169 int $connectionId,
170 Sync\Entities\SyncSectionMap $syncSectionMap,
171 array $externalType
172 ): void
173 {
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',
179 new ReferenceField(
180 'SYNC_DATA',
181 SectionConnectionTable::getEntity(),
182 Join::on('ref.SECTION_ID', 'this.ID'),
183 ['join_type' => Join::TYPE_LEFT]
184 )
185 )
186 ->registerRuntimeField('CONNECTION',
187 new ReferenceField(
188 'CONNECTION',
189 DavConnectionTable::getEntity(),
190 Join::on('ref.ID', 'this.SECTION_CONNECTION.CONNECTION_ID'),
191 ['join_type' => Join::TYPE_LEFT]
192 )
193 )
194 ->setSelect([
195 'ID',
196 'NAME',
197 'XML_ID',
198 'ACTIVE',
199 'DESCRIPTION',
200 'COLOR',
201 'CAL_TYPE',
202 'OWNER_ID',
203 'EXTERNAL_TYPE',
204 'CONNECTION.ACCOUNT_TYPE',
205 'SECTION_CONNECTION.*',
206 'SECTION_CONNECTION.SECTION',
207 'SECTION_CONNECTION.CONNECTION',
208 ])
209 ->exec()
210 ;
211
212 while ($sectionDM = $sectionDb->fetchObject())
213 {
214 $sectionId = null;
215 $syncSection = new Sync\Entities\SyncSection();
216
217 $section = (new SectionBuilderFromDataManager($sectionDM))->build();
218 $syncSection
219 ->setSection($section)
220 ->setAction('success')
221 ;
222
224 if ($sectionConnectionDM = $sectionDM->get('SECTION_CONNECTION'))
225 {
226 $sectionConnection = (new Sync\Builders\BuilderSectionConnectionFromDM($sectionConnectionDM))->build();
227 if (
228 ($sectionConnection->getConnection() !== null)
229 && ($sectionConnection->getConnection()->getId() !== $connectionId)
230 )
231 {
232 continue;
233 }
234
235 $sectionConnection->setSection($section);
236 $syncSection->setSectionConnection($sectionConnection);
237 $sectionId = $sectionConnection->getVendorSectionId();
238 }
239 else
240 {
241 continue;
242 }
243
245 if ($sectionDM->getExternalType() !== Section::SECTION_TYPE_LOCAL && ($connectionDM = $sectionDM->get('CONNECTION')))
246 {
247 $syncSection->setVendorName($connectionDM->getAccountType());
248 }
249 else
250 {
251 $syncSection->setVendorName($sectionDM->getExternalType() ?? Section::SECTION_TYPE_LOCAL);
252 }
253
254 $sectionId = $sectionId ?? (string)$section->getId();
255
256 $syncSectionMap->add($syncSection, $sectionId);
257 }
258 }
259}
$connection
Определения actionsdefinitions.php:38
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
getSyncSectionMapByFactory(FactoryBase $factory)
Определения syncsectionfactory.php:42
Core Mappers SectionConnection $sectionConnectionMapper
Определения syncsectionfactory.php:26
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
string $sectionId
Определения columnfields.php:71