3namespace Bitrix\Main\Controller;
5use Bitrix\Intranet\ActionFilter;
6use Bitrix\Main\Engine\Action;
7use Bitrix\Main\Engine\Controller;
10use Bitrix\Main\Localization\Loc;
11use Bitrix\Main\ObjectNotFoundException;
12use Bitrix\Main\UI\PageNavigation;
13use Bitrix\Main\UserField\UserFieldAccess;
14use Bitrix\Main\UserFieldTable;
15use Bitrix\Main\Engine\Response\Converter;
16use Bitrix\Main\Engine\Response\DataType\Page;
22 $defaultPreFilters = parent::getDefaultPreFilters();
26 $defaultPreFilters[] =
new ActionFilter\IntranetUser();
29 return $defaultPreFilters;
52 $scopes = $restServer->getAuthScope();
57 'The current method required more scopes. (' .
$moduleId .
')',
78 return new Error(Loc::getMessage(
'MAIN_USER_FIELD_CONTROLLER_EMPTY_MODULE_ID_ERROR'));
83 return new Error(Loc::getMessage(
'MAIN_USER_FIELD_CONTROLLER_ACCESS_VIEW_ERROR'));
88 return new Error(loc::getMessage(
'MAIN_USER_FIELD_CONTROLLER_ACCESS_CREATE_ERROR'));
93 return new Error(loc::getMessage(
'MAIN_USER_FIELD_CONTROLLER_ACCESS_MODIFY_ERROR'));
98 return new Error(loc::getMessage(
'MAIN_USER_FIELD_CONTROLLER_ACCESS_DELETE_ERROR'));
103 return new Error(Loc::getMessage(
'MAIN_USER_FIELD_CONTROLLER_ERROR'));
116 $restrictedTypes = array_flip(
$access->getRestrictedTypes());
121 if (empty($restrictedTypes))
126 foreach ($types as $id =>
$type)
128 if (!isset($restrictedTypes[$id]))
131 'userTypeId' =>
$type[
'USER_TYPE_ID'],
132 'description' =>
$type[
'DESCRIPTION'],
145 'editFormLabel' =>
true,
147 'userTypeId' =>
true,
154 'showFilter' =>
true,
155 'isSearchable' =>
true,
157 'editInList' =>
true,
162 $converter =
new Converter(Converter::TO_UPPER | Converter::KEYS | Converter::TO_SNAKE);
164 if (
$fields[
'showFilter'] ===
'Y')
169 return $converter->process(
$fields);
176 if (isset($field[$labelName]) && !is_array($field[$labelName]))
178 $field[$labelName] = [
179 Loc::getCurrentLang() => $field[$labelName],
189 | Converter::TO_CAMEL
190 | Converter::LC_FIRST
191 | Converter::RECURSIVE
205 if (($exception instanceof \
CAdminException) && is_array($exception->messages))
207 foreach ($exception->messages as
$message)
226 foreach ($currentEnums as $enumItem)
228 $storedEnum[$enumItem[
'ID']] = $enumItem;
229 $deletedEnum[$enumItem[
'ID']] =
true;
233 foreach ($newEnums as $enumItem)
235 if (is_array($enumItem))
237 if (!empty($enumItem[
'id']))
239 if (empty($enumItem[
'xmlId']))
241 $enumItem[
'xmlId'] = $storedEnum[$enumItem[
'id']][
'XML_ID'];
243 if (empty($enumItem[
'def']))
245 $enumItem[
'def'] = $storedEnum[$enumItem[
'id']][
'DEF'];
248 unset($deletedEnum[$enumItem[
'id']]);
250 $itemKey = ($enumItem[
'id'] > 0 ? $enumItem[
'id'] :
'n' . ($countAdded++));
253 'VALUE' => $enumItem[
'value'],
254 'DEF' => $enumItem[
'def'] ===
'Y' ?
'Y' :
'N',
255 'SORT' => $enumItem[
'sort'],
258 if (!empty($enumItem[
'xmlId']))
260 $itemDescription[
'XML_ID'] = $enumItem[
'xmlId'];
263 $enumItem[
'sort'] = (int)$enumItem[
'sort'];
264 if ($enumItem[
'sort'] > 0)
266 $itemDescription[
'SORT'] = $enumItem[
'sort'];
269 $updatedEnum[$itemKey] = $itemDescription;
273 foreach ($deletedEnum as $deletedId => $t)
275 $updatedEnum[$deletedId] = [
286 $updatedEnum = $this->
prepareEnums($enums, $currentEnums);
288 $enumValuesManager = new \CUserFieldEnum();
289 $setEnumResult = $enumValuesManager->setEnumValues($id, $updatedEnum);
315 if (is_array($field))
340 $converter =
new Converter(Converter::TO_UPPER | Converter::KEYS | Converter::TO_SNAKE);
357 if (!empty(
$select[
'LANGUAGE']) && is_string(
$select[
'LANGUAGE']))
370 'offset' => $pageNavigation ? $pageNavigation->getOffset() :
null,
371 'limit' => $pageNavigation ? $pageNavigation->getLimit() :
null,
372 'runtime' => $runtime,
374 while ($field = $list->fetch())
398 $fieldName = $field[
'FIELD_NAME'] ??
'';
401 if (!str_starts_with($fieldName, $prefix))
403 $this->
addError(
new Error(Loc::getMessage(
'MAIN_USER_FIELD_CONTROLLER_FIELD_NAME_ERROR')));
407 $userTypeEntity = new \CUserTypeEntity();
408 $id = $userTypeEntity->Add($field);
411 if ($field[
'USER_TYPE_ID'] ===
'enumeration')
444 $userTypeEntity = new \CUserTypeEntity();
445 $isUpdated = $userTypeEntity->Update($id, $field);
448 if ($field[
'USER_TYPE_ID'] ===
'enumeration')
480 $userTypeEntity = new \CUserTypeEntity();
481 $userTypeEntity->Delete($id);
getAccess(string $moduleId, ?\CRestServer $restServer=null)
getAddAccessDeniedError()
prepareEnums(array $newEnums, array $currentEnums)
processAfterAction(Action $action, $result)
listAction(string $moduleId, array $select=[' *'], array $order=[], array $filter=[], PageNavigation $pageNavigation=null, \CRestServer $restServer=null)
fillErrorsFromApplication()
getTypesAction(string $moduleId, \CRestServer $restServer=null)
prepareFields(array $fields)
getDeleteAccessDeniedError()
getAction(string $moduleId, int $id, \CRestServer $restServer=null)
updateEnums(int $id, array $enums, array $currentEnums=[])
updateAction(string $moduleId, int $id, array $field, \CRestServer $restServer=null)
preparePublicData(array $field)
getReadAccessDeniedError()
addAction(string $moduleId, array $field, \CRestServer $restServer=null)
getUpdateAccessDeniedError()
deleteAction(string $moduleId, int $id, \CRestServer $restServer=null)
static includeModule($moduleName)
static getList(array $parameters=array())
static getCount($filter=array(), array $cache=array())
static getInstance(string $moduleId, int $userId=null)
static getLabelsSelect(string $referenceName=null)
static getLabelsReference(string $referenceName=null, string $languageId=null)
static getFieldData(int $id)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
global $USER_FIELD_MANAGER
if(!is_array($deviceNotifyCodes)) $access