Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
usertypepropertyelist.php
1<?php
2
4
8use Bitrix\Main\Page\Asset;
10
11Loc::loadMessages(__FILE__);
12
13if (Loader::requireModule('bizproc'))
14{
15 class UserTypePropertyElist extends UserTypeProperty
16 {
17 private static $controlIsRendered = false;
18
25 public static function renderControlOptions(FieldType $fieldType, $callbackFunctionName, $value)
26 {
27 if (is_array($value))
28 {
29 reset($value);
30 $valueTmp = (int) current($value);
31 }
32 else
33 {
34 $valueTmp = (int) $value;
35 }
36
37 $iblockId = 0;
38 if ($valueTmp > 0)
39 {
40 $elementIterator = \CIBlockElement::getList(array(), array('ID' => $valueTmp), false, false, array('ID', 'IBLOCK_ID'));
41 if ($element = $elementIterator->fetch())
42 $iblockId = $element['IBLOCK_ID'];
43 }
44 if ($iblockId <= 0 && (int) $fieldType->getOptions() > 0)
45 $iblockId = (int) $fieldType->getOptions();
46
48
49 $result = '<select id="WFSFormOptionsX" onchange="'.Main\Text\HtmlFilter::encode($callbackFunctionName).'(this.options[this.selectedIndex].value)">';
50 $iblockTypeIterator = \CIBlockParameters::getIBlockTypes();
51 foreach ($iblockTypeIterator as $iblockTypeId => $iblockTypeName)
52 {
53 $result .= '<optgroup label="'.Main\Text\HtmlFilter::encode($iblockTypeName).'">';
54
55 $iblockIterator = \CIBlock::getList(array('SORT' => 'ASC'), array('TYPE' => $iblockTypeId, 'ACTIVE' => 'Y'));
56 while ($iblock = $iblockIterator->fetch())
57 {
58 $result .= '<option value="'.$iblock['ID'].'"'.(($iblock['ID'] == $iblockId) ? ' selected' : '').'>'
59 .Main\Text\HtmlFilter::encode($iblock['NAME']).'</option>';
60 if (($defaultIBlockId <= 0) || ($iblock['ID'] == $iblockId))
61 $defaultIBlockId = $iblock['ID'];
62 }
63
64 $result .= '</optgroup>';
65 }
66 $result .= '</select><!--__defaultOptionsValue:'.$defaultIBlockId.'--><!--__modifyOptionsPromt:'.Loc::getMessage('UTP_ELIST_DOCUMENT_MOPROMT').'-->';
67 $fieldType->setOptions($defaultIBlockId);
68
69 return $result;
70 }
71
80 public static function renderControlSingle(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
81 {
82 static::initControlHelpers();
83 return parent::renderControlSingle($fieldType, $field, $value, $allowSelection, $renderMode);
84 }
85
94 public static function renderControlMultiple(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
95 {
96 static::initControlHelpers();
97 return parent::renderControlMultiple($fieldType, $field, $value, $allowSelection, $renderMode);
98 }
99
100 private static function initControlHelpers()
101 {
102 if (!static::$controlIsRendered)
103 {
104 Asset::getInstance()->addJs('/bitrix/js/iblock/iblock_edit.js');
105 static::$controlIsRendered = true;
106 }
107 }
108 }
109}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29