38 'BASE_TYPE' => CUserTypeManager::BASE_TYPE_INT,
47 public static function renderField(array $userField, ?array $additionalParameters = []): string
49 static::getEnumList($userField, $additionalParameters);
51 return parent::renderField($userField, $additionalParameters);
61 public static function renderView(array $userField, ?array $additionalParameters = []): string
66 $additionalParameters ?? [],
67 [
'mode' => self::MODE_VIEW]
71 return parent::renderView($userField, $additionalParameters);
81 public static function renderEdit(array $userField, ?array $additionalParameters = []): string
86 $additionalParameters ?? [],
87 [
'mode' => self::MODE_EDIT]
91 return parent::renderEdit($userField, $additionalParameters);
94 public static function renderEditForm(array $userField, ?array $additionalParameters): string
96 $enum = call_user_func([$userField[
'USER_TYPE'][
'CLASS_NAME'],
'getlist'], $userField);
102 while($item = $enum->GetNext())
104 $items[$item[
'ID']] = $item;
106 $additionalParameters[
'items'] = $items;
108 return parent::renderEditForm($userField, $additionalParameters);
111 public static function renderFilter(array $userField, ?array $additionalParameters): string
113 $enum = call_user_func([$userField[
'USER_TYPE'][
'CLASS_NAME'],
'getlist'], $userField);
119 while($item = $enum->GetNext())
121 $items[$item[
'ID']] = $item[
'VALUE'];
123 $additionalParameters[
'items'] = $items;
124 return parent::renderFilter($userField, $additionalParameters);
130 $empty_caption =
' ';
132 if(!array_key_exists($additionalParameters[
'VALUE'], $cache))
134 $enum = call_user_func([$userField[
'USER_TYPE'][
'CLASS_NAME'],
'getlist'], $userField);
137 $additionalParameters[
'VALUE'] = $empty_caption;
138 return parent::renderAdminListView($userField, $additionalParameters);
140 while($item = $enum->GetNext())
142 $cache[$item[
'ID']] = $item[
'VALUE'];
145 if(!array_key_exists($additionalParameters[
'VALUE'], $cache))
147 $cache[$additionalParameters[
'VALUE']] = $empty_caption;
150 $additionalParameters[
'VALUE'] = $cache[$additionalParameters[
'VALUE']];
151 return parent::renderAdminListView($userField, $additionalParameters);
156 $enum = call_user_func([$userField[
'USER_TYPE'][
'CLASS_NAME'],
'getlist'], $userField);
160 while($item = $enum->GetNext())
162 $values[$item[
'ID']] = $item[
'VALUE'];
165 $additionalParameters[
'enumItems'] = $values;
167 return parent::renderAdminListEdit($userField, $additionalParameters);
175 $connection = \Bitrix\Main\Application::getConnection();
176 $helper = $connection->getSqlHelper();
185 public static function checkFields(array $userField, $value): array
196 $height = (int)($userField[
'SETTINGS'][
'LIST_HEIGHT'] ?? 1);
197 $disp = ($userField[
'SETTINGS'][
'DISPLAY'] ??
'');
199 if ($disp !== static::DISPLAY_CHECKBOX && $disp !== static::DISPLAY_LIST)
201 $disp = static::DISPLAY_LIST;
204 $iblockId = (int)($userField[
'SETTINGS'][
'IBLOCK_ID'] ?? 0);
211 $elementId = (int)($userField[
'SETTINGS'][
'DEFAULT_VALUE'] ?? 0);
218 $activeFilter = (($userField[
'SETTINGS'][
'ACTIVE_FILTER'] ??
'') ===
'Y' ?
'Y' :
'N');
222 'LIST_HEIGHT' => (max($height, 1)),
223 'IBLOCK_ID' => $iblockId,
224 'DEFAULT_VALUE' => $elementId,
225 'ACTIVE_FILTER' => $activeFilter,
236 if (!isset($userField[
'VALUE']))
241 if (is_array($userField[
'VALUE']))
243 $val = $userField[
'VALUE'];
247 $val = [$userField[
'VALUE']];
250 Type\Collection::normalizeArrayValuesByInt($val);
252 if (!empty($val) && Loader::includeModule(
'iblock'))
254 $iterator = Iblock\ElementTable::getList([
262 while ($row = $iterator->fetch())
264 $res .= $row[
'NAME'] .
"\r\n";
266 unset($row, $iterator);
278 public static function getFilterData(array $userField, array $additionalParameters): array
280 $enum = call_user_func([$userField[
'USER_TYPE'][
'CLASS_NAME'],
'getlist'], $userField);
284 while($item = $enum->GetNext())
286 $items[$item[
'ID']] = $item[
'VALUE'];
290 'id' => $additionalParameters[
'ID'],
291 'name' => $additionalParameters[
'NAME'],
294 'params' => [
'multiple' =>
'Y'],
303 public static function getList(array $userField)
305 $iblockId = (int)($userField[
'SETTINGS'][
'IBLOCK_ID'] ?? 0);
306 $activeFilter = (string)($userField[
'SETTINGS'][
'ACTIVE_FILTER'] ??
'N');
308 if (self::$iblockIncluded ===
null)
310 self::$iblockIncluded = Loader::includeModule(
'iblock');
312 if ($iblockId <= 0 || !self::$iblockIncluded)
319 $iblockRights = self::getIblockRightsMode($iblockId, $cacheTtl);
320 if ($iblockRights ===
null)
327 'IBLOCK_ID' => $iblockId
331 if ($activeFilter ===
'Y')
333 $filter[
'=ACTIVE'] =
'Y';
337 $elements = \Bitrix\Iblock\ElementTable::getList([
342 'filter' => \CIBlockElement::getPublicElementsOrmFilter($filter),
352 while($element = $elements->fetch())
360 $result = new \CIBlockElementEnum();
361 $result->InitFromArray($rows);
367 $filter[
'CHECK_PERMISSIONS'] =
'Y';
368 $filter[
'MIN_PERMISSION'] = \CIBlockRights::PUBLIC_READ;
369 if ($activeFilter ===
'Y')
371 $filter[
'ACTIVE'] =
'Y';
374 $result = \CIBlockElement::GetList(
390 $result = new \CIBlockElementEnum($result);
401 public static function getEnumList(array &$userField, array $additionalParameters = []): void
403 if (self::$iblockIncluded ===
null)
405 self::$iblockIncluded = Loader::includeModule(
'iblock');
408 $userField[
'MANDATORY'] ??=
'N';
409 $userField[
'SETTINGS'][
'IBLOCK_ID'] ??= 0;
410 $userField[
'SETTINGS'][
'SHOW_NO_VALUE'] ??=
'Y';
411 $userField[
'SETTINGS'][
'DISPLAY'] ??=
'';
412 $userField[
'SETTINGS'][
'ACTIVE_FILTER'] ??=
'N';
415 !self::$iblockIncluded
416 || (
int)$userField[
'SETTINGS'][
'IBLOCK_ID'] <= 0
424 $userField[
'MANDATORY'] !==
'Y'
425 || $userField[
'SETTINGS'][
'SHOW_NO_VALUE'] !==
'N'
427 isset($additionalParameters[
'SHOW_NO_VALUE'])
428 && $additionalParameters[
'SHOW_NO_VALUE'] === true
435 $userField[
'SETTINGS'][
'DISPLAY'] !==
'CHECKBOX'
436 || $userField[
'MULTIPLE'] !==
'Y'
441 null => static::getEmptyCaption($userField)
447 $checkValue = ($additionalParameters[
'mode'] ??
'') === self::MODE_VIEW;
450 $currentValues = static::getFieldValue($userField, $additionalParameters);
451 if (!empty($currentValues))
453 if (is_array($currentValues))
455 Type\Collection::normalizeArrayValuesByInt($currentValues);
459 $currentValues = (int)$currentValues;
460 if ($currentValues <= 0)
462 $currentValues =
null;
466 if (!empty($currentValues))
468 $filter[
'ID'] = $currentValues;
472 $userField[
'USER_TYPE'][
'FIELDS'] = $result;
477 $filter[
'ACTIVE'] = $userField[
'SETTINGS'][
'ACTIVE_FILTER'] ===
'Y';
480 (
int)$userField[
'SETTINGS'][
'IBLOCK_ID'],
484 if (!is_array($elements))
489 if (!empty($currentValues))
495 $result = array_replace($result, $elements);
498 $userField[
'USER_TYPE'][
'FIELDS'] = $result;
507 $message = ($userField[
'SETTINGS'][
'CAPTION_NO_VALUE'] ??
'');
522 return static::renderAdminListEdit($userField, $additionalParameters);
525 public static function getDefaultValue(array $userField, array $additionalParameters = [])
527 $value = ($userField[
'SETTINGS'][
'DEFAULT_VALUE'] ??
'');
528 return ($userField[
'MULTIPLE'] ===
'Y' ? [$value] : $value);
533 return ($userField[
'MULTIPLE'] !==
'Y' && is_array($value)) ? array_shift($value) : $value;
536 public static function getFieldValue(array $userField, array $additionalParameters = [])
538 $valueFromForm = ($additionalParameters[
'bVarsFromForm'] ??
false);
539 if (!$valueFromForm && !isset($additionalParameters[
'VALUE']))
542 isset($userField[
'ENTITY_VALUE_ID'], $userField[
'ENUM'])
543 && $userField[
'ENTITY_VALUE_ID'] <= 0
546 $value = ($userField[
'MULTIPLE'] ===
'Y' ? [] :
null);
547 foreach($userField[
'ENUM'] as $enum)
549 if($enum[
'DEF'] ===
'Y')
551 if($userField[
'MULTIPLE'] ===
'Y')
553 $value[] = $enum[
'ID'];
557 $value = $enum[
'ID'];
565 $value = $userField[
'VALUE'] ??
null;
568 elseif(isset($additionalParameters[
'VALUE']))
570 $value = $additionalParameters[
'VALUE'];
580 protected static function getElements(
int $iblockId, array $additionalFilter = [])
582 if (self::$iblockIncluded ===
null)
584 self::$iblockIncluded = Loader::includeModule(
'iblock');
586 if ($iblockId <= 0 || !self::$iblockIncluded)
593 $iblockRights = self::getIblockRightsMode($iblockId, $cacheTtl);
594 if ($iblockRights ===
null)
601 $filter = [
'IBLOCK_ID' => $iblockId];
602 if ($additionalFilter[
'ACTIVE'])
604 $filter[
'=ACTIVE'] =
'Y';
606 if (isset($additionalFilter[
'ID']))
608 $filter[
'@ID'] = $additionalFilter[
'ID'];
612 $elements = \Bitrix\Iblock\ElementTable::getList([
617 'filter' => \CIBlockElement::getPublicElementsOrmFilter($filter),
627 while($element = $elements->fetch())
629 $result[$element[
'ID']] = $element[
'NAME'];
631 unset($element, $elements);
641 'IBLOCK_ID' => $iblockId,
642 'CHECK_PERMISSIONS' =>
'Y',
643 'MIN_PERMISSION' => \CIBlockRights::PUBLIC_READ,
645 if ($additionalFilter[
'ACTIVE'])
647 $filter[
'ACTIVE'] =
'Y';
649 if (isset($additionalFilter[
'ID']))
651 $filter[
'ID'] = $additionalFilter[
'ID'];
655 $iterator = \CIBlockElement::GetList(
669 while ($element = $iterator->Fetch())
671 $result[$element[
'ID']] = $element[
'NAME'];
673 unset($element, $iterator);
679 private static function getIblockRightsMode(
int $iblockId,
int $cacheTtl): ?string
681 $iblock = Iblock\IblockTable::getRow([
694 return ($iblock[
'RIGHTS_MODE'] ??
null);
static renderAdminListEdit(array $userField, ?array $additionalParameters)
static renderEdit(array $userField, ?array $additionalParameters=[])
static getDefaultValue(array $userField, array $additionalParameters=[])
static getFilterData(array $userField, array $additionalParameters)
static getElements(int $iblockId, array $additionalFilter=[])
static renderEditForm(array $userField, ?array $additionalParameters)
static getEnumList(array &$userField, array $additionalParameters=[])
static getList(array $userField)
static renderField(array $userField, ?array $additionalParameters=[])
static onBeforeSave($userField, $value)
static renderView(array $userField, ?array $additionalParameters=[])
static onSearchIndex(array $userField)
static bool $iblockIncluded
static getFieldValue(array $userField, array $additionalParameters=[])
static checkFields(array $userField, $value)
static renderFilter(array $userField, ?array $additionalParameters)
static getEmptyCaption(array $userField)
static prepareSettings(array $userField)
static renderAdminListView(array $userField, ?array $additionalParameters)
static getAdminListEditHtmlMulty(array $userField, ?array $additionalParameters)
static getMessage($code, $replace=null, $language=null)
static encode($string, $flags=ENT_COMPAT, $doubleEncode=true)