Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
bizprocdocumentlists.php
1<?php
2
3namespace Bitrix\Lists;
4
7
8Loc::loadMessages(__FILE__);
9
10if (!Loader::includeModule('bizproc'))
11{
12 return;
13}
14
16{
17 public static function getEntityName()
18 {
19 return Loc::getMessage('LISTS_BIZPROC_ENTITY_LISTS_NAME');
20 }
21
29 public static function getDocument($documentId)
30 {
31 $documentId = intval($documentId);
32 if ($documentId <= 0)
33 throw new \CBPArgumentNullException('documentId');
34
35 $result = array();
36 $element = array();
37 $elementProperty = array();
38
39 $queryElement = \CIBlockElement::getList(array(),
40 array('ID' => $documentId, 'SHOW_NEW'=>'Y', 'SHOW_HISTORY' => 'Y'));
41 while($queryResult= $queryElement->fetch())
42 {
43 $element = $queryResult;
44 $queryProperty = \CIBlockElement::getProperty(
45 $queryResult['IBLOCK_ID'],
46 $queryResult['ID'],
47 array('sort'=>'asc', 'id'=>'asc', 'enum_sort'=>'asc', 'value_id'=>'asc'),
48 array('ACTIVE'=>'Y', 'EMPTY'=>'N')
49 );
50 while($property = $queryProperty->fetch())
51 {
52 $propertyKey = 'PROPERTY_'.$property['ID'];
53 if($property['MULTIPLE'] == 'Y')
54 {
55 if(!array_key_exists($propertyKey, $elementProperty))
56 {
57 $elementProperty[$propertyKey] = $property;
58 $elementProperty[$propertyKey]['VALUE'] = array();
59 }
60 $elementProperty[$propertyKey]['VALUE'][] = $property['VALUE'];
61 }
62 else
63 {
64 $elementProperty[$propertyKey] = $property;
65 }
66 }
67 }
68
69 foreach($element as $fieldId => $fieldValue)
70 {
71 $result[$fieldId] = $fieldValue;
72 if (in_array($fieldId, array('MODIFIED_BY', 'CREATED_BY')))
73 {
74 $result[$fieldId] = 'user_'.$fieldValue;
75 $result[$fieldId.'_PRINTABLE'] = $element[($fieldId == 'MODIFIED_BY')
76 ? 'USER_NAME' : 'CREATED_USER_NAME'];
77 }
78 elseif (in_array($fieldId, array('PREVIEW_TEXT', 'DETAIL_TEXT')))
79 {
80 if ($element[$fieldId.'_TYPE'] == 'html')
81 $result[$fieldId] = HTMLToTxt($fieldValue);
82 }
83 }
84 foreach($elementProperty as $propertyId => $property)
85 {
86 if(trim($property['CODE']) <> '')
87 $propertyId = $property['CODE'];
88 else
89 $propertyId = $property['ID'];
90
91 if(!empty($property['USER_TYPE']))
92 {
93 if ($property['USER_TYPE'] == 'UserID' || $property['USER_TYPE'] == 'employee' &&
94 (\COption::getOptionString('bizproc', 'employee_compatible_mode', 'N') != 'Y'))
95 {
96 if(empty($property['VALUE']))
97 continue;
98 if(!is_array($property['VALUE']))
99 $property['VALUE'] = array($property['VALUE']);
100
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())
106 {
107 if($property['MULTIPLE'] == 'Y')
108 {
109 $result = self::setArray($result, 'PROPERTY_'.$propertyId);
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'];
115 }
116 else
117 {
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'];
122 }
123 }
124 }
125 elseif($property['USER_TYPE'] == 'DiskFile')
126 {
127 if (is_array($property['VALUE']))
128 {
129 $diskValues = current($property['VALUE']);
130 $userType = \CIBlockProperty::getUserType($property['USER_TYPE']);
131 $result = self::setArray($result, 'PROPERTY_'.$propertyId);
132 $result = self::setArray($result, 'PROPERTY_'.$propertyId.'_PRINTABLE');
133 foreach($diskValues as $attachedId)
134 {
135 $fileId = null;
136 if (array_key_exists('GetObjectId', $userType))
137 $fileId = call_user_func_array($userType['GetObjectId'], array($attachedId));
138 if(!$fileId)
139 continue;
140 $printableUrl = '';
141 if (array_key_exists('GetUrlAttachedFileElement', $userType))
142 $printableUrl = call_user_func_array($userType['GetUrlAttachedFileElement'],
143 array($documentId, $fileId));
144
145 $result['PROPERTY_'.$propertyId][$attachedId] = $fileId;
146 $result['PROPERTY_'.$propertyId.'_PRINTABLE'][$attachedId] = $printableUrl;
147 }
148 }
149 else
150 {
151 continue;
152 }
153 }
154 elseif($property['USER_TYPE'] == 'HTML')
155 {
156 if(\CBPHelper::isAssociativeArray($property['VALUE']))
157 {
158 if($property['VALUE']['TYPE'] == 'HTML')
159 {
160 $result['PROPERTY_'.$propertyId] = HTMLToTxt($property['VALUE']['TEXT']);
161 }
162 else
163 {
164 $result['PROPERTY_'.$propertyId] = $property['VALUE']['TEXT'];
165 }
166 }
167 else
168 {
169 $result = self::setArray($result, 'PROPERTY_'.$propertyId);
170 foreach($property['VALUE'] as $htmlValue)
171 {
172 if($htmlValue['TYPE'] == 'HTML')
173 {
174 $result['PROPERTY_'.$propertyId][] = HTMLToTxt($htmlValue['TEXT']);
175 }
176 else
177 {
178 $result['PROPERTY_'.$propertyId][] = $htmlValue['TEXT'];
179 }
180 }
181 }
182 }
183 elseif($property['USER_TYPE'] == 'Money')
184 {
185 $userType = \CIBlockProperty::getUserType($property['USER_TYPE']);
186 if(is_array($property['VALUE']))
187 {
188 $result = self::setArray($result, 'PROPERTY_'.$propertyId);
189 $result = self::setArray($result, 'PROPERTY_'.$propertyId.'_PRINTABLE');
190 foreach($property['VALUE'] as $moneyValue)
191 {
192 $result['PROPERTY_'.$propertyId][] = $moneyValue;
193 if(array_key_exists('GetPublicViewHTML', $userType))
194 {
195 $result['PROPERTY_'.$propertyId.'_PRINTABLE'][] = call_user_func_array(
196 $userType['GetPublicViewHTML'],
197 array($property, array('VALUE' => $moneyValue), array())
198 );
199 }
200 }
201 }
202 else
203 {
204 $result['PROPERTY_'.$propertyId] = $property['VALUE'];
205 if(array_key_exists('GetPublicViewHTML', $userType))
206 {
207 $result['PROPERTY_'.$propertyId.'_PRINTABLE'] = call_user_func_array(
208 $userType['GetPublicViewHTML'],
209 array($property, array('VALUE' => $property['VALUE']), array())
210 );
211 }
212 }
213 }
214 else
215 {
216 $result['PROPERTY_'.$propertyId] = $property['VALUE'];
217 }
218 }
219 elseif ($property['PROPERTY_TYPE'] == 'L')
220 {
221 $result = self::setArray($result, 'PROPERTY_'.$propertyId);
222 //$result = self::setArray($result, 'PROPERTY_'.$propertyId.'_PRINTABLE');
223 $propertyArray = array();
224 $propertyKeyArray = array();
225 if(!is_array($property['VALUE']))
226 $property['VALUE'] = array($property['VALUE']);
227 foreach($property['VALUE'] as $enumId)
228 {
229 $enumsObject = \CIBlockProperty::getPropertyEnum(
230 $property['ID'],
231 array('SORT' => 'asc'),
232 array('ID' => $enumId)
233 );
234 while($enums = $enumsObject->fetch())
235 {
236 $propertyArray[] = $enums['VALUE'];
237 $propertyKeyArray[] = (self::getVersion() > 1) ? $enums['XML_ID'] : $enums['ID'];
238 }
239 }
240 for ($i = 0, $cnt = count($propertyArray); $i < $cnt; $i++)
241 $result['PROPERTY_'.$propertyId][$propertyKeyArray[$i]] = $propertyArray[$i];
242 }
243 elseif ($property['PROPERTY_TYPE'] == 'F')
244 {
245 $result = self::setArray($result, 'PROPERTY_'.$propertyId);
246 $result = self::setArray($result, 'PROPERTY_'.$propertyId.'_PRINTABLE');
247 $propertyArray = $property['VALUE'];
248 if (!is_array($propertyArray))
249 $propertyArray = array($propertyArray);
250
251 foreach ($propertyArray as $v)
252 {
253 $fileArray = \CFile::getFileArray($v);
254 if ($fileArray)
255 {
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]";
261 }
262 }
263 }
264 else
265 {
266 $result['PROPERTY_'.$propertyId] = $property['VALUE'];
267 }
268 }
269
270 if(!empty($result))
271 {
272 $documentFields = static::getDocumentFields(static::getDocumentType($documentId));
273 foreach ($documentFields as $fieldKey => $field)
274 {
275 if (!array_key_exists($fieldKey, $result))
276 $result[$fieldKey] = null;
277 }
278 }
279
280 return $result;
281 }
282
288 public static function getDocumentFields($documentType)
289 {
290 $iblockId = intval(mb_substr($documentType, mb_strlen("iblock_")));
291 if ($iblockId <= 0)
292 throw new \CBPArgumentOutOfRangeException("documentType", $documentType);
293
294 $documentFieldTypes = self::getDocumentFieldTypes($documentType);
295
296 $result = self::getSystemIblockFields();
297
298 $propertyObject = \CIBlockProperty::getList(
299 array("sort" => "asc", "name" => "asc"),
300 array("IBLOCK_ID" => $iblockId, 'ACTIVE' => 'Y')
301 );
302 $ignoreProperty = array();
303 while ($property = $propertyObject->fetch())
304 {
305 if (trim($property["CODE"]) <> '')
306 {
307 $key = "PROPERTY_".$property["CODE"];
308 $ignoreProperty["PROPERTY_".$property["ID"]] = "PROPERTY_".$property["CODE"];
309 }
310 else
311 {
312 $key = "PROPERTY_".$property["ID"];
313 $ignoreProperty["PROPERTY_".$property["ID"]] = 0;
314 }
315
316 $result[$key] = array(
317 "Name" => $property["NAME"],
318 "Filterable" => ($property["FILTRABLE"] == "Y"),
319 "Editable" => true,
320 "Required" => ($property["IS_REQUIRED"] == "Y"),
321 "Multiple" => ($property["MULTIPLE"] == "Y"),
322 "TypeReal" => $property["PROPERTY_TYPE"],
323 "UserTypeSettings" => $property["USER_TYPE_SETTINGS"]
324 );
325
326 if(trim($property["CODE"]) <> '')
327 $result[$key]["Alias"] = "PROPERTY_".$property["ID"];
328
329 if ($property["USER_TYPE"] <> '')
330 {
331 $result[$key]["TypeReal"] = $property["PROPERTY_TYPE"].":".$property["USER_TYPE"];
332
333 if ($property["USER_TYPE"] == "UserID"
334 || $property["USER_TYPE"] == "employee" && (\COption::getOptionString("bizproc", "employee_compatible_mode", "N") != "Y"))
335 {
336 $result[$key]["Type"] = "user";
337 $result[$key."_PRINTABLE"] = array(
338 "Name" => $property["NAME"].GetMessage("IBD_FIELD_USERNAME_PROPERTY"),
339 "Filterable" => false,
340 "Editable" => false,
341 "Required" => false,
342 "Multiple" => ($property["MULTIPLE"] == "Y"),
343 "Type" => "string",
344 );
345 }
346 elseif ($property["USER_TYPE"] == "DateTime")
347 {
348 $result[$key]["Type"] = "datetime";
349 }
350 elseif ($property["USER_TYPE"] == "Date")
351 {
352 $result[$key]["Type"] = "date";
353 }
354 elseif ($property["USER_TYPE"] == "EList")
355 {
356 $result[$key]["Type"] = "E:EList";
357 $result[$key]["Options"] = $property["LINK_IBLOCK_ID"];
358 }
359 elseif ($property["USER_TYPE"] == "ECrm")
360 {
361 $result[$key]["Type"] = "E:ECrm";
362 $result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
363 $result[$key]["Options"] = $property["USER_TYPE_SETTINGS"];
364 }
365 elseif ($property["USER_TYPE"] == "Money")
366 {
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,
372 "Editable" => false,
373 "Required" => false,
374 "Multiple" => ($property["MULTIPLE"] == "Y"),
375 "Type" => "string",
376 );
377 }
378 elseif ($property["USER_TYPE"] == "Sequence")
379 {
380 $result[$key]["Type"] = "N:Sequence";
381 $result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
382 $result[$key]["Options"] = $property["USER_TYPE_SETTINGS"];
383 }
384 elseif ($property["USER_TYPE"] == "DiskFile")
385 {
386 $result[$key]["Type"] = "S:DiskFile";
387 $result[$key."_PRINTABLE"] = array(
388 "Name" => $property["NAME"].GetMessage("IBD_FIELD_USERNAME_PROPERTY"),
389 "Filterable" => false,
390 "Editable" => false,
391 "Required" => false,
392 "Multiple" => ($property["MULTIPLE"] == "Y"),
393 "Type" => "int",
394 );
395 }
396 elseif ($property["USER_TYPE"] == "HTML")
397 {
398 $result[$key]["Type"] = "S:HTML";
399 }
400 else
401 {
402 $result[$key]["Type"] = "string";
403 }
404 }
405 elseif ($property["PROPERTY_TYPE"] == "L")
406 {
407 $result[$key]["Type"] = "select";
408
409 $result[$key]["Options"] = array();
410 $dbPropertyEnums = \CIBlockProperty::getPropertyEnum($property["ID"]);
411 while ($listPropertyEnum = $dbPropertyEnums->getNext())
412 {
413 $result[$key]["Options"][(self::getVersion() > 1) ?
414 $listPropertyEnum["XML_ID"] : $listPropertyEnum["ID"]] = $listPropertyEnum["~VALUE"];
415 }
416 }
417 elseif ($property["PROPERTY_TYPE"] == "N")
418 {
419 $result[$key]["Type"] = "double";
420 }
421 elseif ($property["PROPERTY_TYPE"] == "F")
422 {
423 $result[$key]["Type"] = "file";
424 $result[$key."_PRINTABLE"] = array(
425 "Name" => $property["NAME"].GetMessage("IBD_FIELD_USERNAME_PROPERTY"),
426 "Filterable" => false,
427 "Editable" => false,
428 "Required" => false,
429 "Multiple" => ($property["MULTIPLE"] == "Y"),
430 "Type" => "string",
431 );
432 }
433 elseif ($property["PROPERTY_TYPE"] == "S")
434 {
435 $result[$key]["Type"] = "string";
436 }
437 elseif ($property["PROPERTY_TYPE"] == "E")
438 {
439 $result[$key]["Type"] = "E:EList";
440 $result[$key]["Options"] = $property["LINK_IBLOCK_ID"];
441 $result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
442 }
443 else
444 {
445 $result[$key]["Type"] = "string";
446 }
447 }
448
449 $list = new \CList($iblockId);
450 $fields = $list->getFields();
451 foreach($fields as $fieldId => $field)
452 {
453 if(empty($field["SETTINGS"]))
454 $field["SETTINGS"] = array("SHOW_ADD_FORM" => 'Y', "SHOW_EDIT_FORM"=>'Y');
455
456 if(array_key_exists($fieldId, $ignoreProperty))
457 {
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'])
464 {
465 $result[$key]["row_count"] = $field["ROW_COUNT"];
466 $result[$key]["col_count"] = $field["COL_COUNT"];
467 }
468 }
469 else
470 {
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"],
480 "active" => true,
481 "active_type" => $field['TYPE'],
482 "DefaultValue" => $field["DEFAULT_VALUE"],
483 );
484 if (isset($field['ROW_COUNT'], $field['COL_COUNT']) && $field['ROW_COUNT'] && $field['COL_COUNT'])
485 {
486 $result[$fieldId]["row_count"] = $field["ROW_COUNT"];
487 $result[$fieldId]["col_count"] = $field["COL_COUNT"];
488 }
489 }
490 }
491
492 $keys = array_keys($result);
493 foreach ($keys as $k)
494 {
495 $result[$k]["BaseType"] = $documentFieldTypes[$result[$k]["Type"]]["BaseType"] ?? null;
496 $result[$k]["Complex"] = $documentFieldTypes[$result[$k]["Type"]]["Complex"] ?? null;
497 }
498
499 return $result;
500 }
501
502 public static function isFeatureEnabled($documentType, $feature)
503 {
504 return in_array($feature, array(\CBPDocumentService::FEATURE_MARK_MODIFIED_FIELDS));
505 }
506
507 public static function getDocumentAdminPage($documentId)
508 {
509 $documentId = intval($documentId);
510 if ($documentId <= 0)
511 throw new \CBPArgumentNullException("documentId");
512
513 $db = \CIBlockElement::getList(
514 array(),
515 array("ID" => $documentId, "SHOW_NEW"=>"Y", "SHOW_HISTORY" => "Y"),
516 false,
517 false,
518 array("ID", "IBLOCK_ID", "IBLOCK_TYPE_ID", "DETAIL_PAGE_URL")
519 );
520 if ($ar = $db->fetch())
521 {
522 foreach(GetModuleEvents("iblock", "CIBlockDocument_OnGetDocumentAdminPage", true) as $arEvent)
523 {
524 $url = ExecuteModuleEventEx($arEvent, array($ar));
525 if($url)
526 return $url;
527 }
528 return "/bitrix/admin/iblock_element_edit.php?view=Y&ID=".$documentId."&IBLOCK_ID=".
529 $ar["IBLOCK_ID"]."&type=".$ar["IBLOCK_TYPE_ID"];
530 }
531
532 return null;
533 }
534}
static isFeatureEnabled($documentType, $feature)
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getSystemIblockFields()
static setArray(array $result, $value)