1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
iblock.php
См. документацию.
1<?php
2namespace Bitrix\Iblock\Copy\Implement;
3
4use Bitrix\Iblock\Copy\Implement\Children\Child;
5use Bitrix\Iblock\Copy\Implement\Children\Element as ElementChild;
6use Bitrix\Iblock\Copy\Implement\Children\Field as FieldChild;
7use Bitrix\Iblock\Copy\Implement\Children\Section as SectionChild;
8use Bitrix\Main\Copy\Container;
9use Bitrix\Main\Copy\CopyImplementer;
10use Bitrix\Main\Error;
11use Bitrix\Main\Result;
12
14{
15 const IBLOCK_COPY_ERROR = "IBLOCK_COPIER_ERROR";
16
17 private $targetIblockTypeId = "";
18 private $targetSocnetGroupId = 0;
19
23 protected $cacheManager;
24
25 private $child = [];
26
32 public function setChild(Child $child)
33 {
34 $this->child[] = $child;
35 }
36
43 public function setTargetIblockTypeId($targetIblockTypeId)
44 {
45 $this->targetIblockTypeId = $targetIblockTypeId;
46 }
47
54 public function setTargetSocnetGroupId($targetSocnetGroupId)
55 {
56 $this->targetSocnetGroupId = $targetSocnetGroupId;
57 }
58
66 {
67 $this->cacheManager = $cacheManager;
68 }
69
77 public function add(Container $container, array $fields)
78 {
79 $iblockObject = new \CIBlock;
80 $iblockId = $iblockObject->add($fields);
81
82 if ($iblockId)
83 {
84 $this->cleanCache($iblockId);
85 }
86 else
87 {
88 $errorMessage = $iblockObject->getLastError();
89 if ($errorMessage)
90 {
91 $this->result->addError(new Error($errorMessage, self::IBLOCK_COPY_ERROR));
92 }
93 else
94 {
95 $this->result->addError(new Error('Unknown error', self::IBLOCK_COPY_ERROR));
96 }
97 }
98
99 return $iblockId;
100 }
101
109 public function getFields(Container $container, $entityId)
110 {
111 $query = \CIBlock::getList(
112 [],
113 [
114 'ID' => $entityId,
115 'CHECK_PERMISSIONS' => 'N',
116 ]
117 );
118 $iblock = $query->fetch();
119 if ($iblock)
120 {
121 $iblockMessage = \CIBlock::getMessages($entityId);
122 $iblock = array_merge($iblock, $iblockMessage);
123 }
124
125 if ($this->targetIblockTypeId)
126 {
127 $iblock["IBLOCK_TYPE_ID"] = $this->targetIblockTypeId;
128 }
129
130 if ($this->targetSocnetGroupId)
131 {
132 $iblock["SOCNET_GROUP_ID"] = $this->targetSocnetGroupId;
133 }
134
135 if (!empty($iblock["PICTURE"]))
136 {
137 $iblock["PICTURE"] = \CFile::makeFileArray($iblock["PICTURE"]);
138 }
139
140 $iblock["RIGHTS"] = $this->getRights(
141 $entityId,
142 $iblock["RIGHTS_MODE"],
143 $iblock["SOCNET_GROUP_ID"]
144 );
145
146 return $iblock;
147 }
148
156 public function prepareFieldsToCopy(Container $container, array $fields)
157 {
158 unset($fields["XML_ID"]);
159
160 return $fields;
161 }
162
171 public function copyChildren(Container $container, $entityId, $copiedEntityId)
172 {
173 $results = [];
174 $sectionsRatio = [];
175 $enumRatio = [];
176 $fieldRatio = [];
177 foreach ($this->child as $child)
178 {
179 if ($child instanceof ElementChild)
180 {
181 $child->setEnumRatio($enumRatio);
182 $child->setSectionsRatio($sectionsRatio);
183 $child->setFieldRatio($fieldRatio);
184 }
185
186 $results[] = $child->copy($entityId, $copiedEntityId);
187
188 if ($child instanceof FieldChild)
189 {
190 $enumRatio = $child->getEnumRatio();
191 $fieldRatio = $child->getFieldRatio();
192 }
193 if ($child instanceof SectionChild)
194 {
195 $sectionsRatio = $child->getSectionsRatio();
196 }
197 }
198
199 return $this->getResult($results);
200 }
201
202 protected function cleanCache(int $iblockId): void
203 {
204 if ($this->cacheManager)
205 {
206 $this->cacheManager->cleanDir("menu");
207 }
208 }
209
210 protected function getSocnetPermission($iblockId, $socnetGroupId): array
211 {
212 return [];
213 }
214
215 private function getRights($iblockId, $rightMode, $socnetGroupId = 0)
216 {
217 $rights = [];
218
219 if ($socnetGroupId)
220 {
221 $rights = $this->getSocnetPermission($iblockId, $socnetGroupId);
222 }
223
224 if ($rightMode == "E")
225 {
226 $rightObject = new \CIBlockRights($iblockId);
227 foreach ($rightObject->getRights() as $right)
228 {
229 if (mb_strpos($right["GROUP_CODE"], "SG") !== 0)
230 {
231 $rights["n".(count($rights))] = [
232 "GROUP_CODE" => $right["GROUP_CODE"],
233 "DO_CLEAN" => "N",
234 "TASK_ID" => $right["TASK_ID"],
235 ];
236 }
237 }
238 }
239 else
240 {
241 $groupPermissions = \CIBlock::getGroupPermissions($iblockId);
242 foreach ($groupPermissions as $groupId => $permission)
243 {
244 if ($permission > "W")
245 {
246 $rights["n".(count($rights))] = [
247 "GROUP_CODE" => "G".$groupId,
248 "IS_INHERITED" => "N",
249 "TASK_ID" => \CIBlockRights::letterToTask($permission),
250 ];
251 }
252 }
253 }
254
255 return $rights;
256 }
257}
cleanCache(int $iblockId)
Определения iblock.php:202
setChild(Child $child)
Определения iblock.php:32
getSocnetPermission($iblockId, $socnetGroupId)
Определения iblock.php:210
getFields(Container $container, $entityId)
Определения iblock.php:109
setTargetSocnetGroupId($targetSocnetGroupId)
Определения iblock.php:54
setCacheManager(\CCacheManager $cacheManager)
Определения iblock.php:65
add(Container $container, array $fields)
Определения iblock.php:77
setTargetIblockTypeId($targetIblockTypeId)
Определения iblock.php:43
const IBLOCK_COPY_ERROR
Определения iblock.php:15
copyChildren(Container $container, $entityId, $copiedEntityId)
Определения iblock.php:171
prepareFieldsToCopy(Container $container, array $fields)
Определения iblock.php:156
getResult(array $results=[])
Определения copyimplementer.php:119
Определения error.php:15
Определения cache_manager.php:15
$right
Определения options.php:8
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$query
Определения get_search.php:11
$iblockId
Определения iblock_catalog_edit.php:30
if(! $catalogEdit->isSuccess()) $iblock
Определения iblock_catalog_edit.php:38
while($arParentIBlockProperty=$dbParentIBlockProperty->Fetch()) $errorMessage
$entityId
Определения payment.php:4
$rights
Определения options.php:4
$fields
Определения yandex_run.php:501