Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
manager.php
1<?php
2namespace Bitrix\Iblock\Copy;
3
9use Bitrix\Iblock\Copy\Implement\Iblock as IblockImplementer;
15
17{
18 protected $iblockTypeId;
20 protected $socnetGroupId;
21
22 protected $targetIblockTypeId = "";
23 protected $targetSocnetGroupId = 0;
24
25 private $iblockImplementer;
26 private $fieldImplementer;
27 private $workflowImplementer;
28
29 protected $features = [
30 "field",
31 "section",
32 "element",
33 "workflow"
34 ];
35
36 private $mapIdsCopiedIblock = [];
37
41 private $dictionary;
42
44 {
45 $this->iblockTypeId = $iblockTypeId;
46 $this->iblockIdsToCopy = $iblockIdsToCopy;
47 $this->socnetGroupId = $socnetGroupId;
48 }
49
58 {
59 $this->targetIblockTypeId = $targetIblockTypeId;
60 $this->targetSocnetGroupId = $targetSocnetGroupId;
61 }
62
68 public function removeFeature($feature)
69 {
70 if (($key = array_search($feature, $this->features)) !== false)
71 {
72 unset($this->features[$key]);
73 }
74 }
75
79 public function setDictionary(Dictionary $dictionary): void
80 {
81 $this->dictionary = $dictionary;
82 }
83
84 public function setIblockImplementer(IblockImplementer $implementer)
85 {
86 $this->iblockImplementer = $implementer;
87 }
88
89 public function setFieldImplementer(Child $implementer)
90 {
91 $this->fieldImplementer = $implementer;
92 }
93
94 public function setWorkflowImplementer(Child $implementer)
95 {
96 $this->workflowImplementer = $implementer;
97 }
98
99 public function startCopy()
100 {
101 $containerCollection = $this->getContainerCollection();
102
103 $iblockCopier = $this->getIblockCopier();
104
105 $result = $iblockCopier->copy($containerCollection);
106
107 $this->mapIdsCopiedIblock = $iblockCopier->getMapIdsCopiedEntity();
108
109 return $result;
110 }
111
117 public function getMapIdsCopiedEntity()
118 {
119 return $this->mapIdsCopiedIblock;
120 }
121
122 private function getContainerCollection()
123 {
124 $containerCollection = new ContainerCollection();
125
126 foreach ($this->iblockIdsToCopy as $iblockId)
127 {
128 $container = new Container($iblockId);
129 if ($this->dictionary)
130 {
131 $container->setDictionary($this->dictionary);
132 }
133 $containerCollection[] = $container;
134 }
135
136 return $containerCollection;
137 }
138
139 private function getIblockCopier()
140 {
141 global $CACHE_MANAGER;
142
143 $iblockImplementer = ($this->iblockImplementer ? $this->iblockImplementer : new IblockImplementer());
144
145 $iblockImplementer->setTargetIblockTypeId($this->targetIblockTypeId);
146 $iblockImplementer->setTargetSocnetGroupId($this->targetSocnetGroupId);
147 if (is_object($CACHE_MANAGER))
148 {
149 $iblockImplementer->setCacheManager($CACHE_MANAGER);
150 }
151
152 $sectionImplementer = null;
153 if (in_array("field", $this->features))
154 {
155 if (!$this->fieldImplementer)
156 {
157 $this->fieldImplementer = new FieldImplementer();
158 }
159 $iblockImplementer->setChild($this->fieldImplementer);
160 }
161 if (in_array("section", $this->features))
162 {
163 $sectionImplementer = new SectionImplementer();
164 $iblockImplementer->setChild($sectionImplementer);
165 }
166 if (in_array("element", $this->features))
167 {
168 $elementImplementer = new ElementImplementer(ElementImplementer::IBLOCK_COPY_MODE);
169 $iblockImplementer->setChild($elementImplementer);
170 }
171 if (in_array("workflow", $this->features) && Loader::includeModule("bizproc"))
172 {
173 if (!$this->workflowImplementer)
174 {
175 $this->workflowImplementer = new WorkflowImplementer($this->iblockTypeId);
176 }
177 $iblockImplementer->setChild($this->workflowImplementer);
178 }
179
180 return new EntityCopier($iblockImplementer);
181 }
182}
setFieldImplementer(Child $implementer)
Definition manager.php:89
setWorkflowImplementer(Child $implementer)
Definition manager.php:94
setTargetLocation($targetIblockTypeId, $targetSocnetGroupId=0)
Definition manager.php:57
setIblockImplementer(IblockImplementer $implementer)
Definition manager.php:84
__construct($iblockTypeId, array $iblockIdsToCopy, $socnetGroupId=0)
Definition manager.php:43
setDictionary(Dictionary $dictionary)
Definition manager.php:79