23 $elementObject = new \CIBlockElement;
24 $elementId = $elementObject->add(
$fields,
false,
true,
true);
31 $error = $elementObject->getLastError();
34 $this->result->addError(
new Error(
$error, self::ELEMENT_COPY_ERROR));
38 $this->result->addError(
new Error(
"Unknown error", self::ELEMENT_COPY_ERROR));
58 "CHECK_PERMISSIONS" =>
"N"
60 $queryObject = \CIBlockElement::getList([],
$filter,
false,
false);
61 if ($element = $queryObject->fetch())
64 $propertyValuesObject = \CIblockElement::getPropertyValues(
65 $element[
"IBLOCK_ID"], [
"ID" =>
$entityId]);
66 while ($propertyValues = $propertyValuesObject->fetch())
70 if ($propertyId ==
"IBLOCK_ELEMENT_ID")
90 "PROPERTY_VALUES" => []
93 foreach ($inputFields as $fieldId => $fieldValue)
95 if (mb_substr($fieldId, 0, 9) ==
"PROPERTY_")
97 $propertyId = mb_substr($fieldId, mb_strlen(
"PROPERTY_"));
98 $fields[
"PROPERTY_VALUES"][$propertyId] = $this->getPropertyFieldValue(
106 $fields[$fieldId] = $this->getFieldValue($fieldId, $fieldValue);
116 if (array_key_exists(
$fields[
"IBLOCK_SECTION_ID"], $dictionary[
"sectionsRatio"]))
118 $fields[
"IBLOCK_SECTION_ID"] = $dictionary[
"sectionsRatio"][
$fields[
"IBLOCK_SECTION_ID"]];
123 if (!empty($dictionary[
"targetIblockId"]))
125 $fields[
"IBLOCK_ID"] = $dictionary[
"targetIblockId"];
145 private function getFieldValue($fieldId, $fieldValue)
149 case "PREVIEW_PICTURE":
150 case "DETAIL_PICTURE":
151 return $this->getPictureValue($fieldValue);
154 return $this->getBaseValue($fieldValue);
158 private function getPropertyFieldValue(Container $container, $fieldId, $fieldValue)
160 $propertyId = mb_substr($fieldId, mb_strlen(
"PROPERTY_"));
161 $fieldValue = (is_array($fieldValue) ? $fieldValue : [$fieldValue]);
163 $queryObject = \CIBlockProperty::getList([], [
"ID" => $propertyId]);
164 if ($property = $queryObject->fetch())
166 if (!empty($property[
"USER_TYPE"]))
168 $userType = \CIBlockProperty::getUserType($property[
"USER_TYPE"]);
169 if (isset($userType[
"ConvertFromDB"]) && is_callable($userType[
"ConvertFromDB"]))
171 $fieldValue = $this->getValueFromPropertyClass($fieldValue, $userType[
"ConvertFromDB"]);
175 $fieldValue = $this->getPropertyValue($fieldValue);
180 switch ($property[
"PROPERTY_TYPE"])
183 $fieldValue = $this->getFileValue($fieldValue);
186 $fieldValue = $this->getIntegerValue($fieldValue);
189 $fieldValue = $this->getListValue($container, $fieldValue);
192 $fieldValue = $this->getPropertyValue($fieldValue);
200 private function getPictureValue($fieldValue)
202 return \CFile::makeFileArray($fieldValue);
205 private function getBaseValue($fieldValue)
207 return (is_array($fieldValue) ? current($fieldValue) : $fieldValue);
210 private function getFileValue(
array $fieldValue)
217 'VALUE' => \CFile::makeFileArray($value),
225 private function getListValue(Container $container,
array $inputValue)
229 $dictionary = $container->getDictionary();
230 $enumRatio = $dictionary[
"enumRatio"];
234 foreach ($inputValue as $value)
236 if ($value && array_key_exists($value, $enumRatio))
238 $values[] = $enumRatio[
$value];
246 private function getPropertyValue(
array $inputValue)
249 foreach ($inputValue as
$key => $value)
251 if (is_array($value))
253 foreach ($value as
$k => $v)
254 $values[
$k][
"VALUE"] = $v;
264 private function getIntegerValue(
array $fieldValue)
274 : (float)(str_replace(
" ",
"", str_replace(
",",
".", $value)))
285 $fieldRatio = $dictionary->get(
'fieldRatio');
290 if (isset($fieldRatio[$propertyId]))
292 $newPropertyId = $fieldRatio[$propertyId];
297 $fields[
'PROPERTY_VALUES'] = $values;
302 private function getValueFromPropertyClass(
array $fieldValue, $callback)
305 foreach ($fieldValue as $value)
307 $listValues[] = call_user_func_array($callback, [[], [
"VALUE" => $value]]);
309 $fieldValue = $listValues;
314 private function getRights(
int $iblockId,
int $elementId)
318 $objectRights = new \CIBlockElementRights(
$iblockId, $elementId);
320 $groupCodeIgnoreList = $this->getGroupCodeIgnoreList(
$iblockId);
322 foreach ($objectRights->getRights() as
$right)
324 if (!in_array(
$right[
"GROUP_CODE"], $groupCodeIgnoreList))
327 "GROUP_CODE" =>
$right[
"GROUP_CODE"],
329 "TASK_ID" =>
$right[
"TASK_ID"],
339 $groupCodeIgnoreList = [];
341 $rightObject = new \CIBlockRights(
$iblockId);
342 foreach ($rightObject->getRights() as
$right)
344 $groupCodeIgnoreList[] =
$right[
"GROUP_CODE"];
347 return $groupCodeIgnoreList;
getResult(array $results=[])