11 private $enumRatio = [];
12 private $enumTmpMap = [];
21 $this->result =
new Result();
26 return $this->enumRatio;
31 $fields = $this->getFieldsToCopy($iblockId);
32 $this->addFields($copiedIblockId, $fields);
34 $properties = $this->getProperty($iblockId);
35 $this->addProperties($copiedIblockId, $properties);
40 private function getFieldsToCopy($iblockId)
42 return \CIBlock::getFields($iblockId);
45 private function addFields($copiedIblockId, $fields)
47 \CIBlock::setFields($copiedIblockId, $fields);
49 global $stackCacheManager;
50 if (is_object($stackCacheManager))
52 $stackCacheManager->clear(
"b_iblock");
56 private function getProperty($iblockId)
60 $queryObject = \CIBlock::getProperties($iblockId);
61 while ($property = $queryObject->fetch())
63 $fields[] = $property;
69 private function addProperties($copiedIblockId, array $properties)
71 foreach ($properties as $propertyField)
73 $propertyField[
"IBLOCK_ID"] = $copiedIblockId;
75 $property = new \CIBlockProperty;
76 $propertyId = $property->add($propertyField);
79 if ($propertyField[
"PROPERTY_TYPE"] ==
"L" && is_array($propertyField[
"LIST"]))
81 $this->addPropertyList($propertyId, $propertyField[
"LIST"]);
85 if (!empty($property->LAST_ERROR))
87 $this->result->addError(
new Error($property->LAST_ERROR, self::FIELD_COPY_ERROR));
92 private function addPropertyList($propertyId, $list)
94 foreach ($list as $id => $enum)
98 $value = trim($enum[
"VALUE"],
" \t\n\r");
101 $enum[
"PROPERTY_ID"] = $propertyId;
102 \CIBlockPropertyEnum::add($enum);
112 $this->enumTmpMap[$fieldId] = [];
114 $propertyId = mb_substr($fieldId, mb_strlen(
"PROPERTY_"));
115 $enum = \CIBlockPropertyEnum::getList([], [
"PROPERTY_ID" => $propertyId]);
116 while ($listData = $enum->fetch())
119 "VALUE" => $listData[
"VALUE"],
120 "DEF" => $listData[
"DEF"],
121 "SORT" => $listData[
"SORT"]
124 $this->enumTmpMap[$fieldId][$listData[
"VALUE"]] = $listData[
"ID"];
132 if (array_key_exists($fieldId, $this->enumTmpMap))
134 $enumTmpMap = $this->enumTmpMap[$fieldId];
135 if (!is_array($this->enumRatio[$iblockId]))
137 $this->enumRatio[$iblockId] = [];
139 $propertyId = mb_substr($copiedFieldId, mb_strlen(
"PROPERTY_"));
140 $enum = \CIBlockPropertyEnum::getList([], [
"PROPERTY_ID" => $propertyId]);
141 while ($listData = $enum->fetch())
143 if (array_key_exists($listData[
"VALUE"], $enumTmpMap))
145 $this->enumRatio[$iblockId][$enumTmpMap[$listData[
"VALUE"]]] = $listData[
"ID"];