34 'BASE_TYPE' => CUserTypeManager::BASE_TYPE_ENUM,
38 public static function renderField(array $userField, ?array $additionalParameters = []): string
40 static::getEnumList($userField, $additionalParameters);
41 return parent::renderField($userField, $additionalParameters);
44 public static function renderView(array $userField, ?array $additionalParameters = []): string
46 static::getEnumList($userField, $additionalParameters);
47 return parent::renderView($userField, $additionalParameters);
50 public static function renderEdit(array $userField, ?array $additionalParameters = []): string
52 static::getEnumList($userField, $additionalParameters);
53 return parent::renderEdit($userField, $additionalParameters);
56 public static function renderEditForm(array $userField, ?array $additionalParameters): string
58 $enum = call_user_func([$userField[
'USER_TYPE'][
'CLASS_NAME'],
'getlist'], $userField);
64 while ($item = $enum->GetNext())
66 $items[$item[
'ID']] = $item;
68 $additionalParameters[
'items'] = $items;
70 return parent::renderEditForm($userField, $additionalParameters);
73 public static function renderFilter(array $userField, ?array $additionalParameters): string
75 $enum = call_user_func([$userField[
'USER_TYPE'][
'CLASS_NAME'],
'getlist'], $userField);
81 while ($item = $enum->GetNext())
83 $items[$item[
'ID']] = $item[
'VALUE'];
85 $additionalParameters[
'items'] = $items;
86 return parent::renderFilter($userField, $additionalParameters);
93 $emptyCaption =
' ';
95 $value = (int)($additionalParameters[
'VALUE'] ?? 0);
96 $fieldId = (int)$userField[
'ID'];
98 if (!isset($cache[$fieldId][$value]))
100 $enum = call_user_func([$userField[
'USER_TYPE'][
'CLASS_NAME'],
'getlist'], $userField);
103 $additionalParameters[
'VALUE'] = $emptyCaption;
104 return parent::renderAdminListView($userField, $additionalParameters);
106 while ($item = $enum->GetNext())
108 $cache[$fieldId][(int)$item[
'ID']] = $item[
'VALUE'];
111 if (!isset($cache[$fieldId][$value]))
113 $cache[$fieldId][$value] = $emptyCaption;
116 $additionalParameters[
'VALUE'] = $cache[$fieldId][$value];
117 return parent::renderAdminListView($userField, $additionalParameters);
122 $enum = call_user_func([$userField[
'USER_TYPE'][
'CLASS_NAME'],
'getlist'], $userField);
126 while ($item = $enum->GetNext())
128 $values[$item[
'ID']] = $item[
'VALUE'];
131 $additionalParameters[
'enumItems'] = $values;
133 return parent::renderAdminListEdit($userField, $additionalParameters);
141 $connection = \Bitrix\Main\Application::getConnection();
142 $helper = $connection->getSqlHelper();
152 $height = (int)($userField[
'SETTINGS'][
'LIST_HEIGHT'] ?? 0);
153 $display = $userField[
'SETTINGS'][
'DISPLAY'] ??
'';
154 $caption_no_value = trim($userField[
'SETTINGS'][
'CAPTION_NO_VALUE'] ??
'');
155 $show_no_value = (isset($userField[
'SETTINGS'][
'SHOW_NO_VALUE']) && $userField[
'SETTINGS'][
'SHOW_NO_VALUE'] ===
'N' ?
'N' :
'Y');
163 if (!in_array($display, $displays,
true))
169 'DISPLAY' => $display,
170 'LIST_HEIGHT' => ($height < 1 ? 1 : $height),
171 'CAPTION_NO_VALUE' => $caption_no_value,
172 'SHOW_NO_VALUE' => $show_no_value,
181 public static function checkFields(array $userField, $value): array
194 if (is_array($userField[
'VALUE']))
196 $val = $userField[
'VALUE'];
200 $val = [$userField[
'VALUE']];
203 $val = array_filter($val,
'strlen');
206 $ob =
new CUserFieldEnum();
207 $rs = $ob->GetList([], [
208 'USER_FIELD_ID' => $userField[
'ID'],
212 while ($ar = $rs->Fetch())
214 $res .= $ar[
'VALUE'] .
'\r\n';
226 public static function getFilterData(array $userField, array $additionalParameters): array
228 $enum = call_user_func([$userField[
'USER_TYPE'][
'CLASS_NAME'],
'getlist'], $userField);
232 while ($item = $enum->GetNext())
234 $items[$item[
'ID']] = $item[
'VALUE'];
238 'id' => $additionalParameters[
'ID'],
239 'name' => $additionalParameters[
'NAME'],
242 'params' => [
'multiple' =>
'Y'],
251 public static function getList(array $userField)
253 $userFieldEnum =
new CUserFieldEnum();
254 return $userFieldEnum->GetList([], [
'USER_FIELD_ID' => $userField[
'ID'] ??
null]);
261 public static function getEnumList(array &$userField, array $additionalParameters = []): void
264 (!isset($userField[
'MANDATORY']) || $userField[
'MANDATORY'] !==
'Y')
266 (!isset($userField[
'SETTINGS'][
'SHOW_NO_VALUE']) || $userField[
'SETTINGS'][
'SHOW_NO_VALUE'] !==
'N')
269 isset($additionalParameters[
'SHOW_NO_VALUE'])
271 $additionalParameters[
'SHOW_NO_VALUE'] === true
279 (!isset($userField[
'SETTINGS'][
'DISPLAY']) || $userField[
'SETTINGS'][
'DISPLAY'] !==
'CHECKBOX')
281 (!isset($userField[
'MULTIPLE']) || $userField[
'MULTIPLE'] !==
'Y')
285 $enum = [
null => static::getEmptyCaption($userField)];
286 $userField[
'USER_TYPE'][
'FIELDS'] = $enum;
287 $userField[
'USER_TYPE'][
'~FIELDS'] = $enum;
290 $enumList = static::getList($userField);
292 while ($item = $enumList->Fetch())
295 $userField[
'USER_TYPE'][
'~FIELDS'][$item[
'ID']] = $item[
'VALUE'];
306 $message = ($userField[
'SETTINGS'][
'CAPTION_NO_VALUE'] ??
'');
322 foreach ($userFields as $field)
324 $ids[] = $field[
'ID'];
326 $userFieldEnum =
new CUserFieldEnum();
327 return $userFieldEnum->GetList(
328 [
'USER_FIELD_ID' =>
'ASC',
'SORT' =>
'ASC',
'ID' =>
'ASC'],
329 [
'USER_FIELD_ID' => $ids]
341 $enum = call_user_func([$userField[
'USER_TYPE'][
'CLASS_NAME'],
'getlist'], $userField);
347 while ($item = $enum->GetNext())
349 $result[] = [
'NAME' => $item[
'VALUE'],
'VALUE' => $item[
'ID']];
362 return static::renderAdminListEdit($userField, $additionalParameters);
365 public static function getDefaultValue(array $userField, array $additionalParameters = [])
367 if (!isset($userField[
'ENUM']))
369 $userField[
'ENUM'] = [];
370 $enumValuesManager =
new CUserFieldEnum();
371 $dbRes = $enumValuesManager->getList(
374 'USER_FIELD_ID' => $userField[
'ID'],
379 while ($enumValue = $dbRes->fetch())
381 $userField[
'ENUM'][] = [
382 'ID' => $enumValue[
'ID'],
383 'VALUE' => $enumValue[
'VALUE'],
384 'DEF' => $enumValue[
'DEF'],
385 'SORT' => $enumValue[
'SORT'],
386 'XML_ID' => $enumValue[
'XML_ID'],
391 $userField[
'ENTITY_VALUE_ID'] = 0;
392 return static::getFieldValue($userField, $additionalParameters);
397 return ($userField[
'MULTIPLE'] !==
'Y' && is_array($value)) ? array_shift($value) : $value;
400 public static function getFieldValue(array $userField, array $additionalParameters = [])
402 $bVarsFromForm = ($additionalParameters[
'bVarsFromForm'] ??
false);
403 if (!$bVarsFromForm && !isset($additionalParameters[
'VALUE']))
406 isset($userField[
'ENTITY_VALUE_ID'], $userField[
'ENUM'])
407 && $userField[
'ENTITY_VALUE_ID'] <= 0
410 $value = ($userField[
'MULTIPLE'] ===
'Y' ? [] :
null);
411 foreach ($userField[
'ENUM'] as $enum)
413 if ($enum[
'DEF'] ===
'Y')
415 if ($userField[
'MULTIPLE'] ===
'Y')
417 $value[] = $enum[
'ID'];
421 $value = $enum[
'ID'];
429 $value = $userField[
'VALUE'] ??
null;
432 elseif (isset($additionalParameters[
'VALUE']))
434 $value = $additionalParameters[
'VALUE'];
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)
static encode($string, $flags=ENT_COMPAT, $doubleEncode=true)
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 renderEditForm(array $userField, ?array $additionalParameters)
static getListMultiple(array $userFields)
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 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 getGroupActionData(array $userField, ?array $additionalParameters)
static getAdminListEditHtmlMulty(array $userField, ?array $additionalParameters)