32 $args = func_get_args();
34 $documentId = (int)$documentId;
37 throw new \CBPArgumentNullException(
'documentId');
42 $elementProperty = [];
46 $select = array_filter(
$select, fn($field) => !str_starts_with($field,
'PROPERTY_'));
49 if (in_array(
'CREATED_BY',
$select) && !in_array(
'CREATED_USER_NAME',
$select))
51 $select[] =
'CREATED_USER_NAME';
53 if (in_array(
'MODIFIED_BY',
$select) && !in_array(
'USER_NAME',
$select))
60 'CREATED_BY_PRINTABLE' =>
'CREATED_USER_NAME',
61 'MODIFIED_BY_PRINTABLE' =>
'USER_NAME',
64 $select = array_map(
static fn($selectField) => $userNameFields[$selectField] ?? $selectField,
$select);
66 $queryElement = \CIBlockElement::getList(
68 [
'ID' => $documentId,
'SHOW_NEW'=>
'Y',
'SHOW_HISTORY' =>
'Y'],
71 while($queryResult= $queryElement->fetch())
73 $element = $queryResult;
74 $queryProperty = \CIBlockElement::getProperty(
75 $queryResult[
'IBLOCK_ID'],
77 array(
'sort'=>
'asc',
'id'=>
'asc',
'enum_sort'=>
'asc',
'value_id'=>
'asc'),
78 array(
'ACTIVE'=>
'Y',
'EMPTY'=>
'N')
80 while($property = $queryProperty->fetch())
82 $propertyKey =
'PROPERTY_'.$property[
'ID'];
83 if($property[
'MULTIPLE'] ==
'Y')
85 if(!array_key_exists($propertyKey, $elementProperty))
87 $elementProperty[$propertyKey] = $property;
88 $elementProperty[$propertyKey][
'VALUE'] =
array();
90 $elementProperty[$propertyKey][
'VALUE'][] = $property[
'VALUE'];
94 $elementProperty[$propertyKey] = $property;
99 foreach($element as $fieldId => $fieldValue)
101 $result[$fieldId] = $fieldValue;
102 if (in_array($fieldId,
array(
'MODIFIED_BY',
'CREATED_BY')))
104 $result[$fieldId] =
'user_'.$fieldValue;
105 $result[$fieldId.
'_PRINTABLE'] = $element[($fieldId ==
'MODIFIED_BY')
106 ?
'USER_NAME' :
'CREATED_USER_NAME'];
108 elseif (in_array($fieldId,
array(
'PREVIEW_TEXT',
'DETAIL_TEXT')))
110 if ($element[$fieldId.
'_TYPE'] ==
'html')
114 foreach($elementProperty as $propertyId => $property)
116 if(trim($property[
'CODE']) <>
'')
117 $propertyId = $property[
'CODE'];
119 $propertyId = $property[
'ID'];
121 if(!empty($property[
'USER_TYPE']))
123 if ($property[
'USER_TYPE'] ==
'UserID' || $property[
'USER_TYPE'] ==
'employee' &&
124 (\COption::getOptionString(
'bizproc',
'employee_compatible_mode',
'N') !=
'Y'))
126 if(empty($property[
'VALUE']))
128 if(!is_array($property[
'VALUE']))
129 $property[
'VALUE'] =
array($property[
'VALUE']);
131 $listUsers = implode(
' | ', $property[
'VALUE']);
132 $userQuery = \CUser::getList(
'ID',
'ASC',
133 array(
'ID' => $listUsers) ,
134 array(
'FIELDS' =>
array(
'ID' ,
'LOGIN',
'NAME',
'LAST_NAME')));
135 while(
$user = $userQuery->fetch())
137 if($property[
'MULTIPLE'] ==
'Y')
141 $result[
'PROPERTY_'.$propertyId][] =
'user_'.intval(
$user[
'ID']);
142 $result[
'PROPERTY_'.$propertyId.
'_PRINTABLE'][] =
'('.$user[
'LOGIN'].
')'.
143 ((
$user[
'NAME'] <>
'' ||
$user[
'LAST_NAME'] <>
'') ?
' ' :
'').
$user[
'NAME'].
144 ((
$user[
'NAME'] <>
'' &&
$user[
'LAST_NAME'] <>
'') ?
' ' :
'').$user[
'LAST_NAME'];
148 $result[
'PROPERTY_'.$propertyId] =
'user_'.intval(
$user[
'ID']);
149 $result[
'PROPERTY_'.$propertyId.
'_PRINTABLE'] =
'('.$user[
'LOGIN'].
')'.
150 ((
$user[
'NAME'] <>
'' ||
$user[
'LAST_NAME'] <>
'') ?
' ' :
'').
$user[
'NAME'].
151 ((
$user[
'NAME'] <>
'' &&
$user[
'LAST_NAME'] <>
'') ?
' ' :
'').$user[
'LAST_NAME'];
155 elseif($property[
'USER_TYPE'] ==
'DiskFile')
157 if (is_array($property[
'VALUE']))
159 $diskValues = current($property[
'VALUE']);
160 $userType = \CIBlockProperty::getUserType($property[
'USER_TYPE']);
163 foreach($diskValues as $attachedId)
166 if (array_key_exists(
'GetObjectId', $userType))
167 $fileId = call_user_func_array($userType[
'GetObjectId'],
array($attachedId));
171 if (array_key_exists(
'GetUrlAttachedFileElement', $userType))
172 $printableUrl = call_user_func_array($userType[
'GetUrlAttachedFileElement'],
173 array($documentId, $fileId));
175 $result[
'PROPERTY_'.$propertyId][$attachedId] = $fileId;
176 $result[
'PROPERTY_'.$propertyId.
'_PRINTABLE'][$attachedId] = $printableUrl;
184 elseif($property[
'USER_TYPE'] ==
'HTML')
186 if(\CBPHelper::isAssociativeArray($property[
'VALUE']))
188 if($property[
'VALUE'][
'TYPE'] ==
'HTML')
194 $result[
'PROPERTY_'.$propertyId] = $property[
'VALUE'][
'TEXT'];
200 foreach($property[
'VALUE'] as $htmlValue)
202 if($htmlValue[
'TYPE'] ==
'HTML')
208 $result[
'PROPERTY_'.$propertyId][] = $htmlValue[
'TEXT'];
213 elseif($property[
'USER_TYPE'] ==
'Money')
215 $userType = \CIBlockProperty::getUserType($property[
'USER_TYPE']);
216 if(is_array($property[
'VALUE']))
220 foreach($property[
'VALUE'] as $moneyValue)
222 $result[
'PROPERTY_'.$propertyId][] = $moneyValue;
223 if(array_key_exists(
'GetPublicViewHTML', $userType))
225 $result[
'PROPERTY_'.$propertyId.
'_PRINTABLE'][] = call_user_func_array(
226 $userType[
'GetPublicViewHTML'],
234 $result[
'PROPERTY_'.$propertyId] = $property[
'VALUE'];
235 if(array_key_exists(
'GetPublicViewHTML', $userType))
237 $result[
'PROPERTY_'.$propertyId.
'_PRINTABLE'] = call_user_func_array(
238 $userType[
'GetPublicViewHTML'],
246 $result[
'PROPERTY_'.$propertyId] = $property[
'VALUE'];
249 elseif ($property[
'PROPERTY_TYPE'] ==
'L')
253 $propertyArray =
array();
254 $propertyKeyArray =
array();
255 if(!is_array($property[
'VALUE']))
256 $property[
'VALUE'] =
array($property[
'VALUE']);
257 foreach($property[
'VALUE'] as $enumId)
259 $enumsObject = \CIBlockProperty::getPropertyEnum(
261 array(
'SORT' =>
'asc'),
262 array(
'ID' => $enumId)
264 while($enums = $enumsObject->fetch())
266 $propertyArray[] = $enums[
'VALUE'];
267 $propertyKeyArray[] = (self::getVersion() > 1) ? $enums[
'XML_ID'] : $enums[
'ID'];
270 for (
$i = 0, $cnt =
count($propertyArray);
$i < $cnt;
$i++)
271 $result[
'PROPERTY_'.$propertyId][$propertyKeyArray[
$i]] = $propertyArray[
$i];
273 elseif ($property[
'PROPERTY_TYPE'] ==
'F')
277 $propertyArray = $property[
'VALUE'];
278 if (!is_array($propertyArray))
279 $propertyArray =
array($propertyArray);
281 foreach ($propertyArray as $v)
283 $fileArray = \CFile::getFileArray($v);
286 $result[
'PROPERTY_'.$propertyId][] = intval($v);
287 $result[
'PROPERTY_'.$propertyId.
'_PRINTABLE'][] =
288 "[url=/bitrix/tools/bizproc_show_file.php?f=".
289 urlencode($fileArray[
"FILE_NAME"]).
"&i=".$v.
"&h=".md5($fileArray[
"SUBDIR"]).
"]".
296 $result[
'PROPERTY_'.$propertyId] = $property[
'VALUE'];
302 $documentFields = static::getDocumentFields(static::getDocumentType($documentId));
303 foreach ($documentFields as $fieldKey => $field)
305 if (!array_key_exists($fieldKey,
$result))
320 $iblockId = intval(mb_substr($documentType, mb_strlen(
"iblock_")));
322 throw new \CBPArgumentOutOfRangeException(
"documentType", $documentType);
324 $documentFieldTypes = self::getDocumentFieldTypes($documentType);
328 $propertyObject = \CIBlockProperty::getList(
329 array(
"sort" =>
"asc",
"name" =>
"asc"),
332 $ignoreProperty =
array();
333 while ($property = $propertyObject->fetch())
335 if (trim($property[
"CODE"]) <>
'')
337 $key =
"PROPERTY_".$property[
"CODE"];
338 $ignoreProperty[
"PROPERTY_".$property[
"ID"]] =
"PROPERTY_".$property[
"CODE"];
342 $key =
"PROPERTY_".$property[
"ID"];
343 $ignoreProperty[
"PROPERTY_".$property[
"ID"]] = 0;
347 "Name" => $property[
"NAME"],
348 "Filterable" => ($property[
"FILTRABLE"] ==
"Y"),
350 "Required" => ($property[
"IS_REQUIRED"] ==
"Y"),
351 "Multiple" => ($property[
"MULTIPLE"] ==
"Y"),
352 "TypeReal" => $property[
"PROPERTY_TYPE"],
353 "UserTypeSettings" => $property[
"USER_TYPE_SETTINGS"]
356 if(trim($property[
"CODE"]) <>
'')
357 $result[
$key][
"Alias"] =
"PROPERTY_".$property[
"ID"];
359 if ($property[
"USER_TYPE"] <>
'')
361 $result[
$key][
"TypeReal"] = $property[
"PROPERTY_TYPE"].
":".$property[
"USER_TYPE"];
363 if ($property[
"USER_TYPE"] ==
"UserID"
364 || $property[
"USER_TYPE"] ==
"employee" && (\COption::getOptionString(
"bizproc",
"employee_compatible_mode",
"N") !=
"Y"))
368 "Name" => $property[
"NAME"].
GetMessage(
"IBD_FIELD_USERNAME_PROPERTY"),
369 "Filterable" =>
false,
372 "Multiple" => ($property[
"MULTIPLE"] ==
"Y"),
376 elseif ($property[
"USER_TYPE"] ==
"DateTime")
380 elseif ($property[
"USER_TYPE"] ==
"Date")
384 elseif ($property[
"USER_TYPE"] ==
"EList")
387 $result[
$key][
"Options"] = $property[
"LINK_IBLOCK_ID"];
389 elseif ($property[
"USER_TYPE"] ==
"ECrm")
392 $result[
$key][
"DefaultValue"] = $property[
"DEFAULT_VALUE"];
393 $result[
$key][
"Options"] = $property[
"USER_TYPE_SETTINGS"];
395 elseif ($property[
"USER_TYPE"] ==
"Money")
398 $result[
$key][
"DefaultValue"] = $property[
"DEFAULT_VALUE"];
400 "Name" => $property[
"NAME"].
GetMessage(
"IBD_FIELD_USERNAME_PROPERTY"),
401 "Filterable" =>
false,
404 "Multiple" => ($property[
"MULTIPLE"] ==
"Y"),
408 elseif ($property[
"USER_TYPE"] ==
"Sequence")
411 $result[
$key][
"DefaultValue"] = $property[
"DEFAULT_VALUE"];
412 $result[
$key][
"Options"] = $property[
"USER_TYPE_SETTINGS"];
414 elseif ($property[
"USER_TYPE"] ==
"DiskFile")
418 "Name" => $property[
"NAME"].
GetMessage(
"IBD_FIELD_USERNAME_PROPERTY"),
419 "Filterable" =>
false,
422 "Multiple" => ($property[
"MULTIPLE"] ==
"Y"),
426 elseif ($property[
"USER_TYPE"] ==
"HTML")
435 elseif ($property[
"PROPERTY_TYPE"] ==
"L")
440 $dbPropertyEnums = \CIBlockProperty::getPropertyEnum($property[
"ID"]);
441 while ($listPropertyEnum = $dbPropertyEnums->getNext())
443 $result[
$key][
"Options"][(self::getVersion() > 1) ?
444 $listPropertyEnum[
"XML_ID"] : $listPropertyEnum[
"ID"]] = $listPropertyEnum[
"~VALUE"];
447 elseif ($property[
"PROPERTY_TYPE"] ==
"N")
451 elseif ($property[
"PROPERTY_TYPE"] ==
"F")
455 "Name" => $property[
"NAME"].
GetMessage(
"IBD_FIELD_USERNAME_PROPERTY"),
456 "Filterable" =>
false,
459 "Multiple" => ($property[
"MULTIPLE"] ==
"Y"),
463 elseif ($property[
"PROPERTY_TYPE"] ==
"S")
467 elseif ($property[
"PROPERTY_TYPE"] ==
"E")
470 $result[
$key][
"Options"] = $property[
"LINK_IBLOCK_ID"];
471 $result[
$key][
"DefaultValue"] = $property[
"DEFAULT_VALUE"];
481 foreach(
$fields as $fieldId => $field)
483 if(empty($field[
"SETTINGS"]))
484 $field[
"SETTINGS"] =
array(
"SHOW_ADD_FORM" =>
'Y',
"SHOW_EDIT_FORM"=>
'Y');
486 if(array_key_exists($fieldId, $ignoreProperty))
488 $ignoreProperty[$fieldId] ?
$key = $ignoreProperty[$fieldId] :
$key = $fieldId;
492 $result[
$key][
"DefaultValue"] = $field[
"DEFAULT_VALUE"];
493 if (isset($field[
'ROW_COUNT'], $field[
'COL_COUNT']) && $field[
'ROW_COUNT'] && $field[
'COL_COUNT'])
502 "Name" => $field[
'NAME'],
503 "Filterable" => !empty(
$result[$fieldId][
'Filterable']) ?
$result[$fieldId][
'Filterable'] :
false,
504 "Editable" => !empty(
$result[$fieldId][
'Editable']) ?
$result[$fieldId][
'Editable'] :
true,
505 "Required" => ($field[
'IS_REQUIRED'] ==
'Y'),
506 "Multiple" => ($field[
'MULTIPLE'] ==
'Y'),
507 "Type" => !empty(
$result[$fieldId][
'Type']) ?
$result[$fieldId][
'Type'] : $field[
'TYPE'],
508 "sort" => $field[
"SORT"],
509 "settings" => $field[
"SETTINGS"],
511 "active_type" => $field[
'TYPE'],
512 "DefaultValue" => $field[
"DEFAULT_VALUE"],
514 if (isset($field[
'ROW_COUNT'], $field[
'COL_COUNT']) && $field[
'ROW_COUNT'] && $field[
'COL_COUNT'])
516 $result[$fieldId][
"row_count"] = $field[
"ROW_COUNT"];
517 $result[$fieldId][
"col_count"] = $field[
"COL_COUNT"];
523 foreach ($keys as
$k)
525 $result[
$k][
"BaseType"] = $documentFieldTypes[
$result[
$k][
"Type"]][
"BaseType"] ??
null;