35 $controlSettings = !empty($field[
'CONTROL_SETTINGS']) ? $field[
'CONTROL_SETTINGS'] : array();
37 if(!empty($field[
'DEFAULT']))
39 $field[
'VALUE'] = $field[
'DEFAULT_VALUE'];
40 if(in_array($field[
'TYPE'], array(
'S:DiskFile')))
42 $renderMethod =
'renderCustomDefaultValue'.$field[
'PROPERTY_USER_TYPE'][
'USER_TYPE'];
43 return self::$renderMethod($field);
47 if(!empty($field[
'SEPARATOR']))
49 self::$separator = $field[
'SEPARATOR'];
52 if(self::$renderForForm && isset($field[
'CURRENT_VALUE']))
54 $field[
'VALUE'] = $field[
'CURRENT_VALUE'];
57 if(isset($field[
'PROPERTY_USER_TYPE'][
'USER_TYPE'])
58 && method_exists(__CLASS__,
'renderFieldByUserType'.$field[
'PROPERTY_USER_TYPE'][
'USER_TYPE']))
60 $renderMethod =
'renderFieldByUserType'.$field[
'PROPERTY_USER_TYPE'][
'USER_TYPE'];
61 $result = self::$renderMethod($field);
63 elseif(isset($field[
'PROPERTY_USER_TYPE'][
'GetPublicViewHTMLMulty']))
65 $result = call_user_func_array(
66 $field[
'PROPERTY_USER_TYPE'][
'GetPublicViewHTMLMulty'], array($field, $field, $controlSettings));
68 elseif(isset($field[
'PROPERTY_USER_TYPE'][
'GetPublicViewHTML']))
70 if($field[
'MULTIPLE'] ===
'Y' && is_array($field[
'VALUE']))
73 if(\CLists::isAssociativeArray($field[
'VALUE']))
75 $result = call_user_func_array(
76 $field[
'PROPERTY_USER_TYPE'][
'GetPublicViewHTML'], array($field, $field, $controlSettings));
80 foreach($field[
'VALUE'] as $value)
82 $fieldParam = array(
'VALUE' => $value);
83 $results[] = call_user_func_array($field[
'PROPERTY_USER_TYPE'][
'GetPublicViewHTML'],
84 array($field, $fieldParam, $controlSettings));
86 $result = implode(self::$separator, $results);
91 $result = call_user_func_array(
92 $field[
'PROPERTY_USER_TYPE'][
'GetPublicViewHTML'], array($field, $field, $controlSettings));
95 if ($field[
'TYPE'] ==
'S:DiskFile' && ($field[
'READ'] ??
'') ==
'Y')
97 $field[
'VALUE'] = array_filter((is_array($field[
'VALUE']) ? $field[
'VALUE'] : array($field[
'VALUE'])));
98 foreach ($field[
'VALUE'] as $key => $value)
100 $result .=
'<input type="hidden" name="'.$field[
'FIELD_ID'].
'[n'.$key.
'][VALUE][]" value="'.HtmlFilter::encode($value).
'">';
104 elseif($field[
'PROPERTY_TYPE'] !=
'')
106 $renderMethod =
'renderFieldByType'.$field[
'PROPERTY_TYPE'];
107 if(method_exists(__CLASS__, $renderMethod))
109 $result = self::$renderMethod($field);
112 elseif($field[
'TYPE'] !=
'')
114 $renderMethod =
'renderFieldByField'.str_replace(
'_',
'', $field[
'TYPE']);
115 if(method_exists(__CLASS__, $renderMethod))
117 $result = self::$renderMethod($field);
369 public static function prepareFieldDataForFilter(array $field)
371 $customEntityType = array('employee');
372 if($field['TYPE'] == 'SORT' || $field['TYPE'] == 'N')
375 'id' => $field['FIELD_ID'],
376 'name' => $field['NAME'],
381 elseif($field['TYPE'] == 'ACTIVE_FROM' || $field['TYPE'] == 'ACTIVE_TO')
384 'id' => 'DATE_'.$field['FIELD_ID'],
385 'name' => $field['NAME'],
391 elseif($field['TYPE'] == 'DATE_CREATE' || $field['TYPE'] == 'TIMESTAMP_X')
394 'id' => $field['FIELD_ID'],
395 'name' => $field['NAME'],
401 elseif($field['TYPE'] == 'CREATED_BY' || $field['TYPE'] == 'MODIFIED_BY')
404 'id' => $field['FIELD_ID'],
405 'name' => $field['NAME'],
406 'type' => 'custom_entity',
410 elseif($field['TYPE'] == 'L')
413 $queryObject = \CIBlockProperty::getPropertyEnum($field['ID'], array('SORT' => 'ASC', 'NAME' => 'ASC'));
414 while($queryResult = $queryObject->fetch())
415 $items[$queryResult['ID']] = $queryResult['VALUE'];
418 'id' => $field['FIELD_ID'],
419 'name' => $field['NAME'],
422 'params' => array('multiple' => 'Y'),
426 elseif($field['TYPE'] == 'E')
429 'id' => $field['FIELD_ID'],
430 'name' => $field['NAME'],
431 'type' => 'custom_entity',
433 'customFilter' => array('Bitrix\Iblock\Helpers\Filter\Property', 'addFilter')
436 elseif($field['TYPE'] == 'E:EList')
439 $queryObject = \CIBlockElement::getList(
440 array('SORT' => 'ASC'),
441 array('IBLOCK_ID' => $field['LINK_IBLOCK_ID']),
444 array('ID', 'NAME', 'SORT')
446 while($queryResult = $queryObject->fetch())
447 $items[$queryResult['ID']] = $queryResult['NAME'];
450 'id' => $field['FIELD_ID'],
451 'name' => $field['NAME'],
454 'params' => array('multiple' => 'Y'),
458 elseif($field['TYPE'] == 'G')
461 $queryObject = \CIBlockSection::getList(
462 array('LEFT_MARGIN' => 'ASC'),
463 array('IBLOCK_ID' => $field['LINK_IBLOCK_ID']),
465 array('ID', 'IBLOCK_ID', 'NAME', 'DEPTH_LEVEL', 'LEFT_MARGIN')
467 while($queryResult = $queryObject->fetch())
468 $items[$queryResult['ID']] = str_repeat('. ', $queryResult['DEPTH_LEVEL'] - 1).$queryResult['NAME'];
471 'id' => $field['FIELD_ID'],
472 'name' => $field['NAME'],
475 'params' => array('multiple' => 'Y'),
479 elseif(is_array($field['PROPERTY_USER_TYPE']) && !empty($field['PROPERTY_USER_TYPE']['USER_TYPE']))
481 $type = $field['PROPERTY_USER_TYPE']['USER_TYPE'];
485 'id' => $field['FIELD_ID'],
486 'name' => $field['NAME'],
492 elseif($type == 'DateTime')
495 'id' => $field['FIELD_ID'],
496 'name' => $field['NAME'],
503 elseif($type == 'Sequence')
506 'id' => $field['FIELD_ID'],
507 'name' => $field['NAME'],
512 elseif($type === 'ECrm')
515 'id' => $field['FIELD_ID'],
516 'name' => $field['NAME'],
517 'type' => 'dest_selector',
518 'params' => ElementType::getDestSelectorParametersForFilter(
519 $field['USER_TYPE_SETTINGS'],
520 $isMultiple = (isset($field['MULTIPLE']) && $field['MULTIPLE'] === 'Y')
525 elseif(in_array($type, $customEntityType))
528 'id' => $field['FIELD_ID'],
529 'name' => $field['NAME'],
530 'type' => 'custom_entity',
536 if(array_key_exists('GetPublicFilterHTML', $field['PROPERTY_USER_TYPE']))
539 'id' => $field['FIELD_ID'],
540 'name' => $field['NAME'],
542 'enable_settings' => false,
543 'value' => call_user_func_array(
544 $field['PROPERTY_USER_TYPE']['GetPublicFilterHTML'],
548 'VALUE' => $field['FIELD_ID'],
549 'FORM_NAME'=>'filter_'.$field['GRID_ID'],
550 'GRID_ID' => $field['GRID_ID']
559 $listLikeProperty = array('S:HTML');
561 'id' => $field['FIELD_ID'],
562 'name' => $field['NAME'],
563 'filterable' => in_array($field['TYPE'], $listLikeProperty) ? '?' : ''
567 if(array_key_exists('AddFilterFields', $field['PROPERTY_USER_TYPE']))
568 $result['customFilter'] = $field['PROPERTY_USER_TYPE']['AddFilterFields'];
572 $listLikeField = array('NAME', 'DETAIL_TEXT', 'PREVIEW_TEXT', 'S');
574 'id' => $field['FIELD_ID'],
575 'name' => $field['NAME'],
576 'filterable' => in_array($field['TYPE'], $listLikeField) ? '?' : ''
578 if($field['FIELD_ID'] == 'NAME')
580 $result['default'] = true;
626 protected static function renderFieldByTypeL(array $field)
628 if(!empty(self::$cache[$field['ID']]))
630 $items = self::$cache[$field['ID']];
635 if(empty($field['DEFAULT']))
636 $items[] = Loc::getMessage('LISTS_FIELD_NO_VALUE');
637 $listElements = \CIBlockProperty::getPropertyEnum($field['ID']);
638 while($listElement = $listElements->fetch())
640 if(!empty($field['DEFAULT']))
642 if($listElement['DEF'] == 'Y')
644 $items[$listElement['ID']] = HtmlFilter::encode($listElement['VALUE']);
649 $items[$listElement['ID']] = HtmlFilter::encode($listElement['VALUE']);
651 if ($listElement['DEF'] == 'Y')
653 $field['DEFAULT_VALUE'] = HtmlFilter::encode($listElement['VALUE']);
657 self::$cache[$field['ID']] = $items;
660 if (is_array($field['VALUE']) && empty($field['VALUE']))
662 $result = $items[0] ?? null;
664 elseif (is_array($field['VALUE']))
666 foreach ($items as $itemKey => $itemValue)
668 if (!in_array($itemKey, $field['VALUE']))
670 unset($items[$itemKey]);
673 $result = implode(self::$separator, $items);
677 $result = $items[$field['VALUE']] ?? null;
680 return ($result ?: $field['DEFAULT_VALUE']);
683 protected static function renderFieldByTypeF(array $field)
685 if((empty($field['VALUE']) || !empty($field['DEFAULT'])) && !self::$renderForForm)
688 $iblockId = !empty($field['IBLOCK_ID']) ? intval($field['IBLOCK_ID']) : 0;
689 $sectionId = !empty($field['SECTION_ID']) ? intval($field['SECTION_ID']) : 0;
690 $elementId = !empty($field['ELEMENT_ID']) ? intval($field['ELEMENT_ID']) : 0;
691 $fieldId = !empty($field['FIELD_ID']) ? $field['FIELD_ID'] : '';
692 $socnetGroupId = !empty($field['SOCNET_GROUP_ID']) ? intval($field['SOCNET_GROUP_ID']) : 0;
693 $urlTemplate = !empty($field['LIST_FILE_URL']) ? $field['LIST_FILE_URL'] : '';
694 $downloadUrl = !empty($field['DOWNLOAD_FILE_URL']) ? $field['DOWNLOAD_FILE_URL'] : '';
697 'max_size' => 2024000,
700 'url_template' => $urlTemplate,
701 'download_url' => $downloadUrl,
702 'download_text' => Loc::getMessage('LISTS_FIELD_FILE_DOWNLOAD'),
703 'show_input' => false
705 if(!empty($field['READ']) && $field['READ'] == 'N')
706 $params['show_input'] = true;
708 if($field['MULTIPLE'] == 'Y' && is_array($field['VALUE']))
711 foreach($field['VALUE'] as $key => $value)
713 $file = new \CListFile($iblockId, $sectionId, $elementId, $fieldId,
714 is_array($value) && isset($value['VALUE']) ? $value['VALUE'] : $value);
715 $file->setSocnetGroup($socnetGroupId);
716 $fieldControlId = $field['TYPE'] == 'F' && self::$renderForForm ?
717 $fieldId.'['.$key.'][VALUE]' : $fieldId;
718 $fileControl = new \CListFileControl($file, $fieldControlId);
719 $results[] = $fileControl->getHTML($params);
721 $result = implode(self::$separator, $results);
725 if(is_array($field['VALUE']))
728 foreach($field['VALUE'] as $key => $value)
730 $file = new \CListFile($iblockId, $sectionId, $elementId, $fieldId,
731 is_array($value) && isset($value['VALUE']) ? $value['VALUE'] : $value);
732 $file->setSocnetGroup($socnetGroupId);
733 $fieldControlId = $field['TYPE'] == 'F' && self::$renderForForm ?
734 $fieldId.'['.$key.'][VALUE]' : $fieldId;
735 $fileControl = new \CListFileControl($file, $fieldControlId);
736 $results[] = $fileControl->getHTML($params);
738 $result = implode(self::$separator, $results);
742 $file = new \CListFile($iblockId, $sectionId, $elementId, $fieldId, $field['VALUE']);
743 $file->setSocnetGroup($socnetGroupId);
744 $fileControl = new \CListFileControl($file, $fieldId);
745 $result = $fileControl->getHTML($params);
757 protected static function renderFieldByTypeG(array $field)
759 if(empty($field['VALUE']))
760 return Loc::getMessage('LISTS_FIELD_NOT_DATA');
762 if(!is_array($field['VALUE']))
763 $field['VALUE'] = array($field['VALUE']);
765 $urlTemplate = !empty($field['LIST_URL']) ? $field['LIST_URL'] : '';
766 $socnetGroupId = !empty($field['SOCNET_GROUP_ID']) ? intval($field['SOCNET_GROUP_ID']) : 0;
770 foreach($field['VALUE'] as $value)
772 if(!empty(self::$cache[$field['TYPE']][$value]))
773 $result[] = self::$cache[$field['TYPE']][$value];
775 $filter['ID'][] = $value;
778 if(!empty($result) && (count($result) == count($field['VALUE'])))
779 return implode(self::$separator, $result);
783 $queryObject = \CIBlockSection::getList(array(),
784 array('=ID' => $field['VALUE']), false, array('ID', 'IBLOCK_ID', 'NAME'));
785 while($section = $queryObject->getNext())
789 $sectionUrl = \CHTTP::URN2URI(\CHTTP::urlAddParams(
790 str_replace(array("#list_id#
", "#section_id#
", "#group_id#
"),
791 array($section['IBLOCK_ID'], 0, $socnetGroupId),
792 $urlTemplate), array('list_section_id' => $section['ID'])));
794 $html = '<a href="'.HtmlFilter::encode($sectionUrl).'" target="_blank
">'.
795 HtmlFilter::encode($section['~NAME']).'</a>';
799 $html = HtmlFilter::encode($section['~NAME']);
803 self::$cache[$field['TYPE']][$section['ID']] = $html;
806 return implode(self::$separator, $result);