31 $documentId = intval($documentId);
33 throw new \CBPArgumentNullException(
'documentId');
37 $elementProperty = array();
39 $queryElement = \CIBlockElement::getList(array(),
40 array(
'ID' => $documentId,
'SHOW_NEW'=>
'Y',
'SHOW_HISTORY' =>
'Y'));
41 while($queryResult= $queryElement->fetch())
43 $element = $queryResult;
44 $queryProperty = \CIBlockElement::getProperty(
45 $queryResult[
'IBLOCK_ID'],
47 array(
'sort'=>
'asc',
'id'=>
'asc',
'enum_sort'=>
'asc',
'value_id'=>
'asc'),
48 array(
'ACTIVE'=>
'Y',
'EMPTY'=>
'N')
50 while($property = $queryProperty->fetch())
52 $propertyKey =
'PROPERTY_'.$property[
'ID'];
53 if($property[
'MULTIPLE'] ==
'Y')
55 if(!array_key_exists($propertyKey, $elementProperty))
57 $elementProperty[$propertyKey] = $property;
58 $elementProperty[$propertyKey][
'VALUE'] = array();
60 $elementProperty[$propertyKey][
'VALUE'][] = $property[
'VALUE'];
64 $elementProperty[$propertyKey] = $property;
69 foreach($element as $fieldId => $fieldValue)
71 $result[$fieldId] = $fieldValue;
72 if (in_array($fieldId, array(
'MODIFIED_BY',
'CREATED_BY')))
74 $result[$fieldId] =
'user_'.$fieldValue;
75 $result[$fieldId.
'_PRINTABLE'] = $element[($fieldId ==
'MODIFIED_BY')
76 ?
'USER_NAME' :
'CREATED_USER_NAME'];
78 elseif (in_array($fieldId, array(
'PREVIEW_TEXT',
'DETAIL_TEXT')))
80 if ($element[$fieldId.
'_TYPE'] ==
'html')
81 $result[$fieldId] = HTMLToTxt($fieldValue);
84 foreach($elementProperty as $propertyId => $property)
86 if(trim($property[
'CODE']) <>
'')
87 $propertyId = $property[
'CODE'];
89 $propertyId = $property[
'ID'];
91 if(!empty($property[
'USER_TYPE']))
93 if ($property[
'USER_TYPE'] ==
'UserID' || $property[
'USER_TYPE'] ==
'employee' &&
94 (\COption::getOptionString(
'bizproc',
'employee_compatible_mode',
'N') !=
'Y'))
96 if(empty($property[
'VALUE']))
98 if(!is_array($property[
'VALUE']))
99 $property[
'VALUE'] = array($property[
'VALUE']);
101 $listUsers = implode(
' | ', $property[
'VALUE']);
102 $userQuery = \CUser::getList(
'ID',
'ASC',
103 array(
'ID' => $listUsers) ,
104 array(
'FIELDS' => array(
'ID' ,
'LOGIN',
'NAME',
'LAST_NAME')));
105 while($user = $userQuery->fetch())
107 if($property[
'MULTIPLE'] ==
'Y')
110 $result =
self::setArray($result,
'PROPERTY_'.$propertyId.
'_PRINTABLE');
111 $result[
'PROPERTY_'.$propertyId][] =
'user_'.intval($user[
'ID']);
112 $result[
'PROPERTY_'.$propertyId.
'_PRINTABLE'][] =
'('.$user[
'LOGIN'].
')'.
113 (($user[
'NAME'] <>
'' || $user[
'LAST_NAME'] <>
'') ?
' ' :
'').$user[
'NAME'].
114 (($user[
'NAME'] <>
'' && $user[
'LAST_NAME'] <>
'') ?
' ' :
'').$user[
'LAST_NAME'];
118 $result[
'PROPERTY_'.$propertyId] =
'user_'.intval($user[
'ID']);
119 $result[
'PROPERTY_'.$propertyId.
'_PRINTABLE'] =
'('.$user[
'LOGIN'].
')'.
120 (($user[
'NAME'] <>
'' || $user[
'LAST_NAME'] <>
'') ?
' ' :
'').$user[
'NAME'].
121 (($user[
'NAME'] <>
'' && $user[
'LAST_NAME'] <>
'') ?
' ' :
'').$user[
'LAST_NAME'];
125 elseif($property[
'USER_TYPE'] ==
'DiskFile')
127 if (is_array($property[
'VALUE']))
129 $diskValues = current($property[
'VALUE']);
130 $userType = \CIBlockProperty::getUserType($property[
'USER_TYPE']);
132 $result =
self::setArray($result,
'PROPERTY_'.$propertyId.
'_PRINTABLE');
133 foreach($diskValues as $attachedId)
136 if (array_key_exists(
'GetObjectId', $userType))
137 $fileId = call_user_func_array($userType[
'GetObjectId'], array($attachedId));
141 if (array_key_exists(
'GetUrlAttachedFileElement', $userType))
142 $printableUrl = call_user_func_array($userType[
'GetUrlAttachedFileElement'],
143 array($documentId, $fileId));
145 $result[
'PROPERTY_'.$propertyId][$attachedId] = $fileId;
146 $result[
'PROPERTY_'.$propertyId.
'_PRINTABLE'][$attachedId] = $printableUrl;
154 elseif($property[
'USER_TYPE'] ==
'HTML')
156 if(\CBPHelper::isAssociativeArray($property[
'VALUE']))
158 if($property[
'VALUE'][
'TYPE'] ==
'HTML')
160 $result[
'PROPERTY_'.$propertyId] = HTMLToTxt($property[
'VALUE'][
'TEXT']);
164 $result[
'PROPERTY_'.$propertyId] = $property[
'VALUE'][
'TEXT'];
170 foreach($property[
'VALUE'] as $htmlValue)
172 if($htmlValue[
'TYPE'] ==
'HTML')
174 $result[
'PROPERTY_'.$propertyId][] = HTMLToTxt($htmlValue[
'TEXT']);
178 $result[
'PROPERTY_'.$propertyId][] = $htmlValue[
'TEXT'];
183 elseif($property[
'USER_TYPE'] ==
'Money')
185 $userType = \CIBlockProperty::getUserType($property[
'USER_TYPE']);
186 if(is_array($property[
'VALUE']))
189 $result =
self::setArray($result,
'PROPERTY_'.$propertyId.
'_PRINTABLE');
190 foreach($property[
'VALUE'] as $moneyValue)
192 $result[
'PROPERTY_'.$propertyId][] = $moneyValue;
193 if(array_key_exists(
'GetPublicViewHTML', $userType))
195 $result[
'PROPERTY_'.$propertyId.
'_PRINTABLE'][] = call_user_func_array(
196 $userType[
'GetPublicViewHTML'],
197 array($property, array(
'VALUE' => $moneyValue), array())
204 $result[
'PROPERTY_'.$propertyId] = $property[
'VALUE'];
205 if(array_key_exists(
'GetPublicViewHTML', $userType))
207 $result[
'PROPERTY_'.$propertyId.
'_PRINTABLE'] = call_user_func_array(
208 $userType[
'GetPublicViewHTML'],
209 array($property, array(
'VALUE' => $property[
'VALUE']), array())
216 $result[
'PROPERTY_'.$propertyId] = $property[
'VALUE'];
219 elseif ($property[
'PROPERTY_TYPE'] ==
'L')
223 $propertyArray = array();
224 $propertyKeyArray = array();
225 if(!is_array($property[
'VALUE']))
226 $property[
'VALUE'] = array($property[
'VALUE']);
227 foreach($property[
'VALUE'] as $enumId)
229 $enumsObject = \CIBlockProperty::getPropertyEnum(
231 array(
'SORT' =>
'asc'),
232 array(
'ID' => $enumId)
234 while($enums = $enumsObject->fetch())
236 $propertyArray[] = $enums[
'VALUE'];
237 $propertyKeyArray[] = (self::getVersion() > 1) ? $enums[
'XML_ID'] : $enums[
'ID'];
240 for ($i = 0, $cnt = count($propertyArray); $i < $cnt; $i++)
241 $result[
'PROPERTY_'.$propertyId][$propertyKeyArray[$i]] = $propertyArray[$i];
243 elseif ($property[
'PROPERTY_TYPE'] ==
'F')
246 $result =
self::setArray($result,
'PROPERTY_'.$propertyId.
'_PRINTABLE');
247 $propertyArray = $property[
'VALUE'];
248 if (!is_array($propertyArray))
249 $propertyArray = array($propertyArray);
251 foreach ($propertyArray as $v)
253 $fileArray = \CFile::getFileArray($v);
256 $result[
'PROPERTY_'.$propertyId][] = intval($v);
257 $result[
'PROPERTY_'.$propertyId.
'_PRINTABLE'][] =
258 "[url=/bitrix/tools/bizproc_show_file.php?f=".
259 urlencode($fileArray[
"FILE_NAME"]).
"&i=".$v.
"&h=".md5($fileArray[
"SUBDIR"]).
"]".
260 htmlspecialcharsbx($fileArray[
"ORIGINAL_NAME"]).
"[/url]";
266 $result[
'PROPERTY_'.$propertyId] = $property[
'VALUE'];
272 $documentFields = static::getDocumentFields(static::getDocumentType($documentId));
273 foreach ($documentFields as $fieldKey => $field)
275 if (!array_key_exists($fieldKey, $result))
276 $result[$fieldKey] =
null;
290 $iblockId = intval(mb_substr($documentType, mb_strlen(
"iblock_")));
292 throw new \CBPArgumentOutOfRangeException(
"documentType", $documentType);
294 $documentFieldTypes = self::getDocumentFieldTypes($documentType);
298 $propertyObject = \CIBlockProperty::getList(
299 array(
"sort" =>
"asc",
"name" =>
"asc"),
300 array(
"IBLOCK_ID" => $iblockId,
'ACTIVE' =>
'Y')
302 $ignoreProperty = array();
303 while ($property = $propertyObject->fetch())
305 if (trim($property[
"CODE"]) <>
'')
307 $key =
"PROPERTY_".$property[
"CODE"];
308 $ignoreProperty[
"PROPERTY_".$property[
"ID"]] =
"PROPERTY_".$property[
"CODE"];
312 $key =
"PROPERTY_".$property[
"ID"];
313 $ignoreProperty[
"PROPERTY_".$property[
"ID"]] = 0;
316 $result[$key] = array(
317 "Name" => $property[
"NAME"],
318 "Filterable" => ($property[
"FILTRABLE"] ==
"Y"),
320 "Required" => ($property[
"IS_REQUIRED"] ==
"Y"),
321 "Multiple" => ($property[
"MULTIPLE"] ==
"Y"),
322 "TypeReal" => $property[
"PROPERTY_TYPE"],
323 "UserTypeSettings" => $property[
"USER_TYPE_SETTINGS"]
326 if(trim($property[
"CODE"]) <>
'')
327 $result[$key][
"Alias"] =
"PROPERTY_".$property[
"ID"];
329 if ($property[
"USER_TYPE"] <>
'')
331 $result[$key][
"TypeReal"] = $property[
"PROPERTY_TYPE"].
":".$property[
"USER_TYPE"];
333 if ($property[
"USER_TYPE"] ==
"UserID"
334 || $property[
"USER_TYPE"] ==
"employee" && (\COption::getOptionString(
"bizproc",
"employee_compatible_mode",
"N") !=
"Y"))
336 $result[$key][
"Type"] =
"user";
337 $result[$key.
"_PRINTABLE"] = array(
338 "Name" => $property[
"NAME"].GetMessage(
"IBD_FIELD_USERNAME_PROPERTY"),
339 "Filterable" =>
false,
342 "Multiple" => ($property[
"MULTIPLE"] ==
"Y"),
346 elseif ($property[
"USER_TYPE"] ==
"DateTime")
348 $result[$key][
"Type"] =
"datetime";
350 elseif ($property[
"USER_TYPE"] ==
"Date")
352 $result[$key][
"Type"] =
"date";
354 elseif ($property[
"USER_TYPE"] ==
"EList")
356 $result[$key][
"Type"] =
"E:EList";
357 $result[$key][
"Options"] = $property[
"LINK_IBLOCK_ID"];
359 elseif ($property[
"USER_TYPE"] ==
"ECrm")
361 $result[$key][
"Type"] =
"E:ECrm";
362 $result[$key][
"DefaultValue"] = $property[
"DEFAULT_VALUE"];
363 $result[$key][
"Options"] = $property[
"USER_TYPE_SETTINGS"];
365 elseif ($property[
"USER_TYPE"] ==
"Money")
367 $result[$key][
"Type"] =
"S:Money";
368 $result[$key][
"DefaultValue"] = $property[
"DEFAULT_VALUE"];
369 $result[$key.
"_PRINTABLE"] = array(
370 "Name" => $property[
"NAME"].GetMessage(
"IBD_FIELD_USERNAME_PROPERTY"),
371 "Filterable" =>
false,
374 "Multiple" => ($property[
"MULTIPLE"] ==
"Y"),
378 elseif ($property[
"USER_TYPE"] ==
"Sequence")
380 $result[$key][
"Type"] =
"N:Sequence";
381 $result[$key][
"DefaultValue"] = $property[
"DEFAULT_VALUE"];
382 $result[$key][
"Options"] = $property[
"USER_TYPE_SETTINGS"];
384 elseif ($property[
"USER_TYPE"] ==
"DiskFile")
386 $result[$key][
"Type"] =
"S:DiskFile";
387 $result[$key.
"_PRINTABLE"] = array(
388 "Name" => $property[
"NAME"].GetMessage(
"IBD_FIELD_USERNAME_PROPERTY"),
389 "Filterable" =>
false,
392 "Multiple" => ($property[
"MULTIPLE"] ==
"Y"),
396 elseif ($property[
"USER_TYPE"] ==
"HTML")
398 $result[$key][
"Type"] =
"S:HTML";
402 $result[$key][
"Type"] =
"string";
405 elseif ($property[
"PROPERTY_TYPE"] ==
"L")
407 $result[$key][
"Type"] =
"select";
409 $result[$key][
"Options"] = array();
410 $dbPropertyEnums = \CIBlockProperty::getPropertyEnum($property[
"ID"]);
411 while ($listPropertyEnum = $dbPropertyEnums->getNext())
413 $result[$key][
"Options"][(self::getVersion() > 1) ?
414 $listPropertyEnum[
"XML_ID"] : $listPropertyEnum[
"ID"]] = $listPropertyEnum[
"~VALUE"];
417 elseif ($property[
"PROPERTY_TYPE"] ==
"N")
419 $result[$key][
"Type"] =
"double";
421 elseif ($property[
"PROPERTY_TYPE"] ==
"F")
423 $result[$key][
"Type"] =
"file";
424 $result[$key.
"_PRINTABLE"] = array(
425 "Name" => $property[
"NAME"].GetMessage(
"IBD_FIELD_USERNAME_PROPERTY"),
426 "Filterable" =>
false,
429 "Multiple" => ($property[
"MULTIPLE"] ==
"Y"),
433 elseif ($property[
"PROPERTY_TYPE"] ==
"S")
435 $result[$key][
"Type"] =
"string";
437 elseif ($property[
"PROPERTY_TYPE"] ==
"E")
439 $result[$key][
"Type"] =
"E:EList";
440 $result[$key][
"Options"] = $property[
"LINK_IBLOCK_ID"];
441 $result[$key][
"DefaultValue"] = $property[
"DEFAULT_VALUE"];
445 $result[$key][
"Type"] =
"string";
449 $list = new \CList($iblockId);
450 $fields = $list->getFields();
451 foreach($fields as $fieldId => $field)
453 if(empty($field[
"SETTINGS"]))
454 $field[
"SETTINGS"] = array(
"SHOW_ADD_FORM" =>
'Y',
"SHOW_EDIT_FORM"=>
'Y');
456 if(array_key_exists($fieldId, $ignoreProperty))
458 $ignoreProperty[$fieldId] ? $key = $ignoreProperty[$fieldId] : $key = $fieldId;
459 $result[$key][
"sort"] = $field[
"SORT"];
460 $result[$key][
"settings"] = $field[
"SETTINGS"];
461 $result[$key][
"active"] =
true;
462 $result[$key][
"DefaultValue"] = $field[
"DEFAULT_VALUE"];
463 if (isset($field[
'ROW_COUNT'], $field[
'COL_COUNT']) && $field[
'ROW_COUNT'] && $field[
'COL_COUNT'])
465 $result[$key][
"row_count"] = $field[
"ROW_COUNT"];
466 $result[$key][
"col_count"] = $field[
"COL_COUNT"];
471 $result[$fieldId] = array(
472 "Name" => $field[
'NAME'],
473 "Filterable" => !empty($result[$fieldId][
'Filterable']) ? $result[$fieldId][
'Filterable'] :
false,
474 "Editable" => !empty($result[$fieldId][
'Editable']) ? $result[$fieldId][
'Editable'] :
true,
475 "Required" => ($field[
'IS_REQUIRED'] ==
'Y'),
476 "Multiple" => ($field[
'MULTIPLE'] ==
'Y'),
477 "Type" => !empty($result[$fieldId][
'Type']) ? $result[$fieldId][
'Type'] : $field[
'TYPE'],
478 "sort" => $field[
"SORT"],
479 "settings" => $field[
"SETTINGS"],
481 "active_type" => $field[
'TYPE'],
482 "DefaultValue" => $field[
"DEFAULT_VALUE"],
484 if (isset($field[
'ROW_COUNT'], $field[
'COL_COUNT']) && $field[
'ROW_COUNT'] && $field[
'COL_COUNT'])
486 $result[$fieldId][
"row_count"] = $field[
"ROW_COUNT"];
487 $result[$fieldId][
"col_count"] = $field[
"COL_COUNT"];
492 $keys = array_keys($result);
493 foreach ($keys as $k)
495 $result[$k][
"BaseType"] = $documentFieldTypes[$result[$k][
"Type"]][
"BaseType"] ??
null;
496 $result[$k][
"Complex"] = $documentFieldTypes[$result[$k][
"Type"]][
"Complex"] ??
null;