33 $this->param = $param;
39 $this->listObject = new \CList($this->iblockId);
51 $this->param->checkRequiredInputParams([
"IBLOCK_CODE",
"IBLOCK_ID",
"ELEMENT_CODE",
"ELEMENT_ID"]);
52 if ($this->param->hasErrors())
54 $this->errorCollection->add($this->param->getErrors());
59 "ID" => $this->params[
"ELEMENT_ID"] ? $this->params[
"ELEMENT_ID"] :
"",
60 "IBLOCK_ID" => $this->iblockId,
61 "=CODE" => $this->params[
"ELEMENT_CODE"] ? $this->params[
"ELEMENT_CODE"] :
"",
62 "CHECK_PERMISSIONS" =>
"N",
64 $queryObject = \CIBlockElement::getList([], $filter,
false,
false, [
"ID"]);
65 return (
bool) $queryObject->fetch();
75 $this->param->checkRequiredInputParams(
87 if ($this->param->hasErrors())
89 $this->errorCollection->add($this->param->getErrors());
94 $this->setUrlTemplate();
96 $this->validateFields();
98 $isEnabledBp = $this->isEnabledBizproc($this->params[
"IBLOCK_TYPE_ID"]);
99 $hasBpTemplatesWithAutoStart =
false;
102 $hasBpTemplatesWithAutoStart = $this->hasBpTemplatesWithAutoStart(\CBPDocumentEventType::Create);
110 $elementFields = $this->getElementFields($this->elementId, $this->params[
"FIELDS"]);
112 $elementObject = new \CIBlockElement;
113 $this->elementId = $elementObject->add($elementFields,
false,
true,
true);
114 if ($this->elementId)
116 if ($isEnabledBp && $hasBpTemplatesWithAutoStart)
118 $this->startBp($this->elementId, \CBPDocumentEventType::Create);
121 return $this->elementId;
125 if ($elementObject->LAST_ERROR)
127 $this->errorCollection->setError(
128 new Error($elementObject->LAST_ERROR, self::ERROR_ADD_ELEMENT)
133 $this->errorCollection->setError(
134 new Error(
"Unknown error", self::ERROR_ADD_ELEMENT)
149 public function get(array $navData = [])
151 $this->param->checkRequiredInputParams([
"IBLOCK_TYPE_ID",
"IBLOCK_CODE",
"IBLOCK_ID"]);
152 if ($this->param->hasErrors())
154 $this->errorCollection->add($this->param->getErrors());
158 return $this->getElements($navData);
168 $this->param->checkRequiredInputParams(
177 if ($this->param->hasErrors())
179 $this->errorCollection->add($this->param->getErrors());
184 $this->validateFields();
186 $isEnabledBp = $this->isEnabledBizproc($this->params[
"IBLOCK_TYPE_ID"]);
187 $hasBpTemplatesWithAutoStart =
false;
190 $hasBpTemplatesWithAutoStart = $this->hasBpTemplatesWithAutoStart(\CBPDocumentEventType::Edit);
198 list($elementSelect, $elementFields, $elementProperty) = $this->getElementData();
200 $fields = $this->getElementFields($this->elementId, $this->params[
"FIELDS"]);
202 $elementObject = new \CIBlockElement;
203 $updateResult = $elementObject->update($this->elementId, $fields,
false,
true,
true);
206 if ($isEnabledBp && $hasBpTemplatesWithAutoStart)
208 $changedElementFields = \CLists::checkChangedFields(
216 $this->startBp($this->elementId, \CBPDocumentEventType::Edit, $changedElementFields);
228 if ($elementObject->LAST_ERROR)
230 $this->errorCollection->setError(
231 new Error($elementObject->LAST_ERROR, self::ERROR_UPDATE_ELEMENT)
236 $this->errorCollection->setError(
237 new Error(
"Unknown error", self::ERROR_UPDATE_ELEMENT)
250 public function delete()
252 $this->param->checkRequiredInputParams([
"IBLOCK_TYPE_ID",
"IBLOCK_CODE",
"IBLOCK_ID",
253 "ELEMENT_CODE",
"ELEMENT_ID"]);
254 if ($this->param->hasErrors())
256 $this->errorCollection->add($this->param->getErrors());
260 $elementObject = new \CIBlockElement;
262 global $DB, $APPLICATION;
263 $DB->startTransaction();
264 $APPLICATION->resetException();
266 if ($elementObject->delete($this->elementId))
274 if ($exception = $APPLICATION->getException())
275 $this->errorCollection->setError(
new Error($exception->getString(), self::ERROR_UPDATE_ELEMENT));
277 $this->errorCollection->setError(
new Error(
"Unknown error", self::ERROR_UPDATE_ELEMENT));
290 $this->param->checkRequiredInputParams([
"IBLOCK_CODE",
"IBLOCK_ID",
"ELEMENT_CODE",
"ELEMENT_ID",
"FIELD_ID"]);
291 if ($this->param->hasErrors())
293 $this->errorCollection->add($this->param->getErrors());
299 $sefFolder = $this->getSefFolder();
301 $queryProperty = \CIBlockElement::getProperty($this->iblockId, $this->elementId,
302 "SORT",
"ASC", array(
"ACTIVE"=>
"Y",
"EMPTY"=>
"N",
"ID" => $this->params[
"FIELD_ID"])
304 while ($property = $queryProperty->fetch())
306 if ($property[
"PROPERTY_TYPE"] ==
"F")
308 $file = new \CListFile($this->iblockId, 0, $this->elementId,
309 "PROPERTY_".$this->params[
"FIELD_ID"], $property[
"VALUE"]);
310 $file->SetSocnetGroup($this->params[
"SOCNET_GROUP_ID"]);
311 $urls[] = $file->GetImgSrc([
"url_template" => $sefFolder.
312 "#list_id#/file/#section_id#/#element_id#/#field_id#/#file_id#/"]);
314 elseif ($property[
"USER_TYPE"] ==
"DiskFile")
316 if (is_array($property[
"VALUE"]))
318 foreach ($property[
"VALUE"] as $attacheId)
320 $driver = \Bitrix\Disk\Driver::getInstance();
321 $urls[] = $driver->getUrlManager()->getUrlUfController(
322 "download", array(
"attachedId" => $attacheId));
337 $availableFields = array(
"ID",
"ACTIVE",
"NAME",
"TAGS",
"XML_ID",
"EXTERNAL_ID",
"PREVIEW_TEXT",
338 "PREVIEW_TEXT_TYPE",
"PREVIEW_PICTURE",
"DETAIL_TEXT",
"DETAIL_TEXT_TYPE",
"DETAIL_PICTURE",
339 "CHECK_PERMISSIONS",
"PERMISSIONS_BY",
"CATALOG_TYPE",
"MIN_PERMISSION",
"SEARCHABLE_CONTENT",
340 "SORT",
"TIMESTAMP_X",
"DATE_MODIFY_FROM",
"DATE_MODIFY_TO",
"MODIFIED_USER_ID",
"MODIFIED_BY",
341 "DATE_CREATE",
"CREATED_USER_ID",
"CREATED_BY",
"DATE_ACTIVE_FROM",
"DATE_ACTIVE_TO",
"ACTIVE_DATE",
342 "ACTIVE_FROM",
"ACTIVE_TO",
"SECTION_ID");
344 $listCustomFields = [];
346 $fields = $this->listObject->getFields();
348 foreach ($fields as $field)
350 if ($field[
"CODE"] <>
'')
352 $availableFields[] =
"PROPERTY_".$field[
"CODE"];
355 if ($this->isFieldDateType($field[
"TYPE"]))
357 $callback = $field[
"PROPERTY_USER_TYPE"][
"ConvertToDB"];
358 $listCustomFields[$field[
"FIELD_ID"]] =
function ($value) use ($callback) {
359 $regexDetectsIso8601 =
'/^([\+-]?\d{4}(?!\d{2}\b))'
360 .
'((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?'
361 .
'|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d'
362 .
'|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])'
363 .
'((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d'
364 .
'([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/';
365 if (preg_match($regexDetectsIso8601, $value) === 1)
367 return \CRestUtil::unConvertDateTime($value);
369 elseif (is_callable($callback))
371 return call_user_func_array($callback, [[], [
"VALUE" => $value]]);
381 $availableFields = array_merge($availableFields, array_keys($fields));
383 return array($availableFields, $listCustomFields);
386 private function isEnabledBizproc(
string $iblockTypeId): bool
388 return (Loader::includeModule(
"bizproc") && \CLists::isBpFeatureEnabled($iblockTypeId));
391 private function setUrlTemplate()
393 if (!empty($this->params[
"LIST_ELEMENT_URL"]))
395 $this->listObject->actualizeDocumentAdminPage(str_replace(
396 [
"#list_id#",
"#group_id#"],
397 [$this->iblockId, $this->params[
"SOCNET_GROUP_ID"]],
398 $this->params[
"LIST_ELEMENT_URL"])
403 private function validateFields()
405 $fields = $this->listObject->getFields();
406 foreach ($fields as $fieldId => $fieldData)
408 $fieldValue = $this->params[
"FIELDS"][$fieldId];
411 empty($this->params[
"FIELDS"][$fieldId])
412 && $fieldData[
"IS_REQUIRED"] ===
"Y"
413 && !is_numeric($this->params[
"FIELDS"][$fieldId])
416 $this->errorCollection->setError(
418 "The field \"".$fieldData[
"NAME"].
"\" is required",
419 self::ERROR_ELEMENT_FIELD_VALUE
424 if (!$this->listObject->is_field($fieldId))
426 if (!is_array($fieldValue))
428 $fieldValue = [$fieldValue];
431 switch ($fieldData[
"TYPE"])
434 foreach($fieldValue as $key => $value)
436 $value = str_replace(
" ",
"", str_replace(
",",
".", $value));
437 if ($value && !is_numeric($value))
439 $this->errorCollection->setError(
new Error(
440 "Value of the \"".$fieldData[
"NAME"].
"\" field is not correct",
441 self::ERROR_ELEMENT_FIELD_VALUE)
451 private function getElementFields($elementId, array $values)
454 "IBLOCK_ID" => $this->iblockId,
455 "CODE" => $this->params[
"ELEMENT_CODE"],
457 "PROPERTY_VALUES" => []
460 $fields = $this->listObject->getFields();
461 foreach ($fields as $fieldId => $fieldData)
463 $fieldValue = $values[$fieldId];
465 if ($this->listObject->is_field($fieldId))
467 if ($fieldId ==
"PREVIEW_PICTURE" || $fieldId ==
"DETAIL_PICTURE")
469 $this->setPictureValue($elementFields, $fieldId, $fieldValue, $values);
471 elseif ($fieldId ==
"PREVIEW_TEXT" || $fieldId ==
"DETAIL_TEXT")
473 $this->setTextValue($elementFields, $fieldId, $fieldValue, $fieldData);
477 $this->setBaseValue($elementFields, $fieldId, $fieldValue);
482 if (!is_array($fieldValue))
484 $fieldValue = [$fieldValue];
487 switch ($fieldData[
"TYPE"])
490 $this->setFileValue($elementFields, $fieldId, $fieldValue, $fieldData, $values);
493 $this->setIntegerValue($elementFields, $fieldValue, $fieldData);
496 $this->setFileDiskValue($elementFields, $fieldValue, $fieldData);
499 $this->setDateValue($elementFields, $fieldValue, $fieldData);
502 $this->setDateTimeValue($elementFields, $fieldValue, $fieldData);
505 $this->setHtmlValue($elementFields, $fieldValue, $fieldData);
508 $this->setPropertyValue($elementFields, $fieldValue, $fieldData);
514 if (empty($values[
"MODIFIED_BY"]) && isset($USER) && is_object($USER))
517 $elementFields[
"MODIFIED_BY"] =
$userId;
519 unset($elementFields[
"TIMESTAMP_X"]);
521 $elementFields[
"IBLOCK_SECTION_ID"] = (
522 is_numeric($values[
'IBLOCK_SECTION_ID'])
523 ? (int) $values[
'IBLOCK_SECTION_ID'] : 0
526 return $elementFields;
529 private function setPictureValue(&$elementFields, $fieldId, $fieldValue, array $values)
531 if (intval($fieldValue))
533 $elementFields[$fieldId] = \CFile::makeFileArray($fieldValue);
537 $elementFields[$fieldId] = \CRestUtil::saveFile($fieldValue);
540 if (!empty($values[$fieldId.
"_DEL"]))
542 $elementFields[$fieldId][
"del"] =
"Y";
546 private function setTextValue(&$elementFields, $fieldId, $fieldValue, $fieldData)
548 if (is_array($fieldValue))
550 $fieldValue = current($fieldValue);
553 if (!empty($fieldData[
"SETTINGS"][
"USE_EDITOR"]) && $fieldData[
"SETTINGS"][
"USE_EDITOR"] ==
"Y")
555 $elementFields[$fieldId.
"_TYPE"] =
"html";
559 $elementFields[$fieldId.
"_TYPE"] =
"text";
562 $elementFields[$fieldId] = $fieldValue;
565 private function setBaseValue(&$elementFields, $fieldId, $fieldValue)
567 if (is_array($fieldValue))
569 $fieldValue = current($fieldValue);
572 $elementFields[$fieldId] = $fieldValue;
575 private function setFileValue(&$elementFields, $fieldId, array $fieldValue, array $fieldData, array $values)
577 if (!empty($values[$fieldId.
"_DEL"]))
578 $delete = $values[$fieldId.
"_DEL"];
582 if (!Loader::includeModule(
"rest"))
587 foreach ($fieldValue as $key => $value)
589 if (is_array($value))
591 $elementFields[
"PROPERTY_VALUES"][$fieldData[
"ID"]][$key][
"VALUE"] = \CRestUtil::saveFile($value);
595 if (is_numeric($value))
597 $elementFields[
"PROPERTY_VALUES"][$fieldData[
"ID"]][$key][
"VALUE"] = \CFile::makeFileArray($value);
601 $elementFields[
"PROPERTY_VALUES"][$fieldData[
"ID"]][$key][
"VALUE"] = \CRestUtil::saveFile($fieldValue);
608 foreach ($delete as $elementPropertyId => $mark)
610 if (isset($elementFields[
"PROPERTY_VALUES"][$fieldData[
"ID"]][$elementPropertyId][
"VALUE"]))
611 $elementFields[
"PROPERTY_VALUES"][$fieldData[
"ID"]][$elementPropertyId][
"VALUE"][
"del"] =
"Y";
613 $elementFields[
"PROPERTY_VALUES"][$fieldData[
"ID"]][$elementPropertyId][
"del"] =
"Y";
618 private function setIntegerValue(&$elementFields, array $fieldValue, $fieldData)
620 foreach ($fieldValue as $key => $value)
622 $value = str_replace(
" ",
"", str_replace(
",",
".", $value));
623 $value = is_numeric($value) ? doubleval($value) :
'';
624 $elementFields[
"PROPERTY_VALUES"][$fieldData[
"ID"]][$key][
"VALUE"] = $value;
628 private function setFileDiskValue(&$elementFields, array $fieldValue, $fieldData)
630 foreach ($fieldValue as $key => $value)
632 if (is_array($value))
634 $elementFields[
"PROPERTY_VALUES"][$fieldData[
"ID"]][$key][
"VALUE"] = $value;
638 if (!is_array($elementFields[
"PROPERTY_VALUES"][$fieldData[
"ID"]][
"VALUE"]))
639 $elementFields[
"PROPERTY_VALUES"][$fieldData[
"ID"]][
"VALUE"] = [];
640 $elementFields[
"PROPERTY_VALUES"][$fieldData[
"ID"]][
"VALUE"][] = $value;
645 private function setDateValue(&$elementFields, array $fieldValue, $fieldData)
647 if (!Loader::includeModule(
"rest"))
652 foreach ($fieldValue as $key => $value)
654 if (is_array($value))
656 foreach($value as $k => $v)
658 $elementFields[
"PROPERTY_VALUES"][$fieldData[
"ID"]][$k][
"VALUE"] = \CRestUtil::unConvertDate($v);
663 $elementFields[
"PROPERTY_VALUES"][$fieldData[
"ID"]][$key][
"VALUE"] = \CRestUtil::unConvertDate($value);
668 private function setDateTimeValue(&$elementFields, array $fieldValue, $fieldData)
670 if (!Loader::includeModule(
"rest"))
675 foreach ($fieldValue as $key => $value)
677 if (is_array($value))
679 foreach($value as $k => $v)
681 $elementFields[
"PROPERTY_VALUES"][$fieldData[
"ID"]][$k][
"VALUE"] =
682 \CRestUtil::unConvertDateTime($v);
687 $elementFields[
"PROPERTY_VALUES"][$fieldData[
"ID"]][$key][
"VALUE"] =
688 \CRestUtil::unConvertDateTime($value);
693 private function setHtmlValue(&$elementFields, array $fieldValue, $fieldData)
695 foreach($fieldValue as $key => $value)
697 if (!is_array($value))
699 $value = [$key => $value];
702 foreach($value as $k => $v)
704 if (CheckSerializedData($v) && @unserialize($v, [
'allowed_classes' =>
false]))
706 $elementFields[
"PROPERTY_VALUES"][$fieldData[
"ID"]][$k][
"VALUE"] = unserialize($v, [
'allowed_classes' =>
false]);
710 $elementFields[
"PROPERTY_VALUES"][$fieldData[
"ID"]][$k][
"VALUE"][
"TYPE"] =
"html";
711 $elementFields[
"PROPERTY_VALUES"][$fieldData[
"ID"]][$k][
"VALUE"][
"TEXT"] = $v;
717 private function setPropertyValue(&$elementFields, array $fieldValue, $fieldData)
719 foreach($fieldValue as $key => $value)
723 foreach($value as $k => $v)
724 $elementFields[
"PROPERTY_VALUES"][$fieldData[
"ID"]][$k][
"VALUE"] = $v;
728 $elementFields[
"PROPERTY_VALUES"][$fieldData[
"ID"]][$key][
"VALUE"] = $value;
733 private function hasBpTemplatesWithAutoStart(
int $execType): bool
735 $documentType = \BizProcDocument::generateDocumentComplexType(
736 $this->params[
"IBLOCK_TYPE_ID"],
740 $bpTemplatesWithAutoStart = \CBPWorkflowTemplateLoader::searchTemplatesByDocumentType(
745 foreach ($bpTemplatesWithAutoStart as $template)
747 if (!\CBPWorkflowTemplateLoader::isConstantsTuned($template[
"ID"]))
749 $this->errorCollection->setError(
750 new Error(
"Workflow constants need to be configured", self::ERROR_ADD_ELEMENT)
755 return !empty($bpTemplatesWithAutoStart);
758 private function startBp(
int $elementId,
int $execType, $changedElementFields = []): void
760 $documentType = \BizprocDocument::generateDocumentComplexType(
761 $this->params[
"IBLOCK_TYPE_ID"],
764 $documentId = \BizProcDocument::getDocumentComplexId(
765 $this->params[
"IBLOCK_TYPE_ID"],
768 $documentStates = \CBPWorkflowTemplateLoader::getDocumentTypeStates(
773 if (is_array($documentStates) && !empty($documentStates))
779 $currentUserGroups = $USER->getUserGroupArray();
780 if ($this->params[
"CREATED_BY"] == $userId)
782 $currentUserGroups[] =
"author";
785 if ($execType === \CBPDocumentEventType::Create)
787 $canWrite = \CBPDocument::canUserOperateDocumentType(
788 \CBPCanUserOperateOperation::WriteDocument,
792 "AllUserGroups" => $currentUserGroups,
793 "DocumentStates" => $documentStates
799 $canWrite = \CBPDocument::canUserOperateDocument(
800 \CBPCanUserOperateOperation::WriteDocument,
804 "AllUserGroups" => $currentUserGroups,
805 "DocumentStates" => $documentStates
812 $this->errorCollection->setError(
813 new Error(
"You do not have enough permissions to edit this record in its current bizproc state")
821 foreach ($documentStates as $documentState)
823 $parameters = \CBPDocument::startWorkflowParametersValidate(
824 $documentState[
"TEMPLATE_ID"],
825 $documentState[
"TEMPLATE_PARAMETERS"],
830 \CBPDocument::startWorkflow(
831 $documentState[
"TEMPLATE_ID"],
832 \BizProcDocument::getDocumentComplexId($this->params[
"IBLOCK_TYPE_ID"], $elementId),
836 \CBPDocument::PARAM_TAGRET_USER =>
"user_" . intval($userId),
837 \CBPDocument::PARAM_MODIFIED_DOCUMENT_FIELDS => $changedElementFields,
844 foreach($errors as $message)
846 $this->errorCollection->setError(
new Error($message));
851 private function getElementData()
853 $elementSelect = [
"ID",
"IBLOCK_ID",
"NAME",
"IBLOCK_SECTION_ID",
"CREATED_BY",
"BP_PUBLISHED",
"CODE"];
855 $elementProperty = [];
857 $fields = $this->listObject->getFields();
858 $propertyFields = [];
859 foreach ($fields as $fieldId => $field)
861 if ($this->listObject->is_field($fieldId))
862 $elementSelect[] = $fieldId;
864 $propertyFields[] = $fieldId;
866 if ($fieldId ==
"CREATED_BY")
867 $elementSelect[] =
"CREATED_USER_NAME";
868 if ($fieldId ==
"MODIFIED_BY")
869 $elementSelect[] =
"USER_NAME";
873 "IBLOCK_TYPE" => $this->params[
"IBLOCK_TYPE_ID"],
874 "IBLOCK_ID" => $this->iblockId,
875 "ID" => $this->elementId,
876 "CHECK_PERMISSIONS" =>
"N"
878 $queryObject = \CIBlockElement::getList([], $filter,
false,
false, $elementSelect);
879 if ($result = $queryObject->fetch())
881 $elementFields = $result;
883 if (!empty($propertyFields))
885 $queryProperty = \CIBlockElement::getProperty(
887 $result[
"ID"],
"SORT",
"ASC",
888 array(
"ACTIVE"=>
"Y",
"EMPTY"=>
"N")
890 while ($property = $queryProperty->fetch())
892 $propertyId = $property[
"ID"];
893 if (!array_key_exists($propertyId, $elementProperty))
895 $elementProperty[$propertyId] = $property;
896 unset($elementProperty[$propertyId][
"DESCRIPTION"]);
897 unset($elementProperty[$propertyId][
"VALUE_ENUM_ID"]);
898 unset($elementProperty[$propertyId][
"VALUE_ENUM"]);
899 unset($elementProperty[$propertyId][
"VALUE_XML_ID"]);
900 $elementProperty[$propertyId][
"FULL_VALUES"] = [];
901 $elementProperty[$propertyId][
"VALUES_LIST"] = [];
903 $elementProperty[$propertyId][
"FULL_VALUES"][$property[
"PROPERTY_VALUE_ID"]] = [
904 "VALUE" => $property[
"VALUE"],
905 "DESCRIPTION" => $property[
"DESCRIPTION"],
907 $elementProperty[$propertyId][
"VALUES_LIST"][$property[
"PROPERTY_VALUE_ID"]] = $property[
"VALUE"];
912 return [$elementSelect, $elementFields, $elementProperty];
915 private function getElements($navData)
919 $fields = $this->listObject->getFields();
921 $elementSelect = [
"ID",
"IBLOCK_ID",
"NAME",
"IBLOCK_SECTION_ID",
"CREATED_BY",
"BP_PUBLISHED",
"CODE"];
922 $propertyFields = [];
923 $ignoreSortFields = [
"S:Money",
"PREVIEW_TEXT",
"DETAIL_TEXT",
"S:ECrm",
"S:map_yandex",
"PREVIEW_PICTURE",
924 "DETAIL_PICTURE",
"S:DiskFile",
"IBLOCK_SECTION_ID",
"BIZPROC",
"COMMENTS"];
926 $availableFieldsIdForSort = [
"ID"];
927 foreach ($fields as $fieldId => $field)
929 if ($this->listObject->is_field($fieldId))
930 $elementSelect[] = $fieldId;
932 $propertyFields[] = $fieldId;
934 if ($fieldId ==
"CREATED_BY")
935 $elementSelect[] =
"CREATED_USER_NAME";
936 if ($fieldId ==
"MODIFIED_BY")
937 $elementSelect[] =
"USER_NAME";
939 if (!($field[
"MULTIPLE"] ==
"Y" || in_array($field[
"TYPE"], $ignoreSortFields)))
941 $availableFieldsIdForSort[] = $fieldId;
945 $order = $this->getOrder($availableFieldsIdForSort);
948 "=IBLOCK_TYPE" => $this->params[
"IBLOCK_TYPE_ID"],
949 "IBLOCK_ID" => $this->iblockId,
950 "ID" => $this->params[
"ELEMENT_ID"] ? $this->params[
"ELEMENT_ID"] :
"",
951 "=CODE" => $this->params[
"ELEMENT_CODE"] ? $this->params[
"ELEMENT_CODE"] :
"",
952 "SHOW_NEW" => (!empty($this->params[
"CAN_FULL_EDIT"]) && $this->params[
"CAN_FULL_EDIT"] ==
"Y" ?
"Y" :
"N"),
953 "CHECK_PERMISSIONS" =>
"Y"
955 $filter = $this->getInputFilter($filter);
956 $queryObject = \CIBlockElement::getList($order, $filter,
false, $navData, $elementSelect);
957 while ($result = $queryObject->fetch())
959 $elements[$result[
"ID"]] = $result;
961 if (!empty($propertyFields))
963 $queryProperty = \CIBlockElement::getProperty(
965 $result[
"ID"],
"SORT",
"ASC",
966 array(
"ACTIVE" =>
"Y",
"EMPTY" =>
"N")
968 while ($property = $queryProperty->fetch())
970 $propertyId = $property[
"ID"];
971 $elements[$result[
"ID"]][
"PROPERTY_".$propertyId][
972 $property[
"PROPERTY_VALUE_ID"]] = $property[
"VALUE"];
977 return array($elements, $queryObject);
980 private function getOrder($availableFieldsIdForSort)
984 if (is_array($this->params[
"ELEMENT_ORDER"]))
987 $orderList = [
"nulls,asc",
"asc,nulls",
"nulls,desc",
"desc,nulls",
"asc",
"desc"];
988 foreach ($this->params[
"ELEMENT_ORDER"] as $fieldId => $orderParam)
990 $orderParam = mb_strtolower($orderParam);
991 if (!in_array($orderParam, $orderList) || !in_array($fieldId, $availableFieldsIdForSort))
995 $order[$fieldId] = $orderParam;
1001 $order = [
"ID" =>
"asc"];
1007 private function getInputFilter(array $filter)
1009 if (is_array($this->params[
"FILTER"]))
1011 foreach ($this->resultSanitizeFilter as $key => $value)
1013 $key = str_replace([
"ACTIVE_FROM",
"ACTIVE_TO"], [
"DATE_ACTIVE_FROM",
"DATE_ACTIVE_TO"], $key);
1014 $filter[$key] = $value;
1021 private function isFieldDateType($type)
1023 return (in_array($type, [
"DATE_CREATE",
"TIMESTAMP_X",
"DATE_MODIFY_FROM",
"DATE_MODIFY_TO",
"ACTIVE_DATE",
1024 "S:Date",
"S:DateTime",
"DATE_ACTIVE_FROM",
"DATE_ACTIVE_TO",
"ACTIVE_FROM",
"ACTIVE_TO"]));
1027 private function getSefFolder()
1029 $defaultSefFolder = [
1030 "lists" =>
"/company/lists/",
1031 "lists_socnet" =>
"/workgroups/group/#group_id#/lists/",
1032 "bitrix_processes" =>
"/bizproc/processes/",
1035 if (!empty($this->params[
"SEF_FOLDER"]))
1037 $sefFolder = $this->params[
"SEF_FOLDER"];
1039 elseif (!empty($defaultSefFolder[$this->params[
"IBLOCK_TYPE_ID"]]))
1041 $sefFolder = $defaultSefFolder[$this->params[
"IBLOCK_TYPE_ID"]];
1045 $sefFolder = $defaultSefFolder[
"lists"];