5use Bitrix\Intranet\ActionFilter;
22 $defaultPreFilters = parent::getDefaultPreFilters();
26 $defaultPreFilters[] =
new ActionFilter\IntranetUser();
29 return $defaultPreFilters;
52 $scopes = $restServer->getAuthScope();
53 if (!in_array($moduleId, $scopes,
true))
57 'The current method required more scopes. (' . $moduleId .
')',
58 \
Bitrix\
Rest\Engine\ActionFilter\Scope::ERROR_INSUFFICIENT_SCOPE
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'));
106 public function getTypesAction(
string $moduleId, \CRestServer $restServer =
null): ?array
108 $access = $this->
getAccess($moduleId, $restServer);
116 $restrictedTypes = array_flip($access->getRestrictedTypes());
118 global $USER_FIELD_MANAGER;
119 $types = $USER_FIELD_MANAGER->GetUserType();
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,
159 $fields = array_intersect_key($fields, $allowedKeys);
161 $converter =
new Converter(Converter::TO_UPPER | Converter::KEYS | Converter::TO_SNAKE);
163 if ($fields[
'showFilter'] ===
'Y')
165 $fields[
'showFilter'] =
'E';
168 return $converter->process($fields);
175 if (isset($field[$labelName]) && !is_array($field[$labelName]))
177 $field[$labelName] = [
182 $settings = $field[
'SETTINGS'];
188 | Converter::TO_CAMEL
189 | Converter::LC_FIRST
190 | Converter::RECURSIVE
194 $field[
'settings'] = $settings;
203 $exception = $APPLICATION->GetException();
204 if (($exception instanceof \CAdminException) && is_array($exception->messages))
206 foreach ($exception->messages as $message)
208 if (isset($message[
'text']))
210 $message = $message[
'text'];
216 $APPLICATION->ResetException();
219 protected function prepareEnums(array $newEnums, array $currentEnums): array
225 foreach ($currentEnums as $enumItem)
227 $storedEnum[$enumItem[
'ID']] = $enumItem;
228 $deletedEnum[$enumItem[
'ID']] =
true;
232 foreach ($newEnums as $enumItem)
234 if (is_array($enumItem))
236 if (!empty($enumItem[
'id']))
238 if (empty($enumItem[
'xmlId']))
240 $enumItem[
'xmlId'] = $storedEnum[$enumItem[
'id']][
'XML_ID'];
242 if (empty($enumItem[
'def']))
244 $enumItem[
'def'] = $storedEnum[$enumItem[
'id']][
'DEF'];
247 unset($deletedEnum[$enumItem[
'id']]);
249 $itemKey = ($enumItem[
'id'] > 0 ? $enumItem[
'id'] :
'n' . ($countAdded++));
252 'VALUE' => $enumItem[
'value'],
253 'DEF' => $enumItem[
'def'] ===
'Y' ?
'Y' :
'N',
254 'SORT' => $enumItem[
'sort'],
257 if (!empty($enumItem[
'xmlId']))
259 $itemDescription[
'XML_ID'] = $enumItem[
'xmlId'];
262 $enumItem[
'sort'] = (int)$enumItem[
'sort'];
263 if ($enumItem[
'sort'] > 0)
265 $itemDescription[
'SORT'] = $enumItem[
'sort'];
268 $updatedEnum[$itemKey] = $itemDescription;
272 foreach ($deletedEnum as $deletedId => $t)
274 $updatedEnum[$deletedId] = [
283 protected function updateEnums(
int $id, array $enums, array $currentEnums = []): void
285 $updatedEnum = $this->
prepareEnums($enums, $currentEnums);
287 $enumValuesManager = new \CUserFieldEnum();
288 $setEnumResult = $enumValuesManager->setEnumValues($id, $updatedEnum);
296 public function getAction(
string $moduleId,
int $id, \CRestServer $restServer =
null): ?array
298 $access = $this->
getAccess($moduleId, $restServer);
307 if (!$access->canRead($id))
314 if (is_array($field))
326 array $select = [
'*'],
330 \CRestServer $restServer =
null
333 $access = $this->
getAccess($moduleId, $restServer);
339 $converter =
new Converter(Converter::TO_UPPER | Converter::KEYS | Converter::TO_SNAKE);
341 $filter = $converter->process($filter);
343 $order = $converter->process($order);
345 $select = $converter->process($select);
347 if (!$access->canReadWithFilter($filter))
353 $filter = $access->prepareFilter($filter);
356 if (!empty($select[
'LANGUAGE']) && is_string($select[
'LANGUAGE']))
359 unset($select[
'LANGUAGE']);
369 'offset' => $pageNavigation ? $pageNavigation->getOffset() :
null,
370 'limit' => $pageNavigation ? $pageNavigation->getLimit() :
null,
371 'runtime' => $runtime,
373 while ($field = $list->fetch())
378 return new Page(
'fields', $fields,
static function () use ($filter) {
383 public function addAction(
string $moduleId, array $field, \CRestServer $restServer =
null): ?array
385 $access = $this->
getAccess($moduleId, $restServer);
391 if (!$access->canAdd($field))
397 $fieldName = $field[
'FIELD_NAME'] ??
'';
398 $entityId = $field[
'ENTITY_ID'] ??
'';
399 $prefix =
'UF_' . $entityId .
'_';
400 if (strpos($fieldName, $prefix) !== 0)
406 $userTypeEntity = new \CUserTypeEntity();
407 $id = $userTypeEntity->Add($field);
410 if ($field[
'USER_TYPE_ID'] ===
'enumeration')
429 public function updateAction(
string $moduleId,
int $id, array $field, \CRestServer $restServer =
null): ?array
431 $access = $this->
getAccess($moduleId, $restServer);
436 if (!$access->canUpdate($id))
443 $userTypeEntity = new \CUserTypeEntity();
444 $isUpdated = $userTypeEntity->Update($id, $field);
447 if ($field[
'USER_TYPE_ID'] ===
'enumeration')
466 public function deleteAction(
string $moduleId,
int $id, \CRestServer $restServer =
null): void
468 $access = $this->
getAccess($moduleId, $restServer);
473 if (!$access->canDelete($id))
479 $userTypeEntity = new \CUserTypeEntity();
480 $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 getMessage($code, $replace=null, $language=null)
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)