8class User extends \CBPRuntimeService
16 $result = \CUser::getList(
18 [
'ID_EQUAL_EXACT' => $userId],
19 [
'FIELDS' => [
'ID'],
'SELECT' => [
'UF_DEPARTMENT']]
22 if ($user = $result->fetch())
24 if (isset($user[
'UF_DEPARTMENT']))
26 $user[
'UF_DEPARTMENT'] = (array) $user[
'UF_DEPARTMENT'];
27 foreach ($user[
'UF_DEPARTMENT'] as $dpt)
29 $departments[] = (int) $dpt;
45 $user = $this->loadUser($userId, $userFields);
52 $this->convertValues($user, $userFields);
55 $user[
'IS_ABSENT'] = $schedule->isAbsent();
56 $user[
'TIMEMAN_STATUS'] = $schedule->getWorkDayStatus();
57 $user[
'UF_HEAD'] = $this->convertUserValue($this->
getUserHeads($userId));
66 if ($this->canUseIntranet())
68 $fields[
'UF_DEPARTMENT'] = [
74 $fields[
'UF_DEPARTMENT_PRINTABLE'] = [
80 $fields[
'IS_ABSENT'] = [
85 if ($this->canUseIblockApi())
87 $fields[
'UF_HEAD'] = [
95 if ($this->canUseTimeman())
97 $fields[
'TIMEMAN_STATUS'] = [
101 'EXPIRED' =>
Loc::getMessage(
'BP_SERVICE_USER_TIMEMAN_STATUS_EXPIRED'),
127 'PERSONAL_MOBILE' => [
131 'UF_PHONE_INNER' => [
155 'PERSONAL_BIRTHDAY' => [
215 if (!$this->canUseIblockApi())
221 $chain = \CIBlockSection::getNavChain($departmentIblockId, $departmentId, [
'ID'],
true);
224 static fn($value) => (
int)$value[
'ID'],
228 return array_reverse($chain);
236 foreach ($userDepartments as $chain)
238 foreach ($chain as $deptId)
242 if (!$departmentHead || $departmentHead === $userId)
247 $heads[] = $departmentHead;
252 return array_unique($heads);
257 if (!$this->canUseIblockApi())
263 $sectionResult = \CIBlockSection::GetList(
265 [
'IBLOCK_ID' => $departmentIblockId,
'ID' => $departmentId],
269 $section = $sectionResult->fetch();
271 return $section ? (int) $section[
'UF_HEAD'] :
null;
281 return (
int) Main\Config\Option::get(
282 static::DEPARTMENT_MODULE_ID,
283 static::DEPARTMENT_OPTION_NAME
287 private function canUseIblockApi()
289 return Main\Loader::includeModule(
'iblock');
292 private function canUseIntranet()
294 return Main\Loader::includeModule(
'intranet');
297 private function canUseTimeman()
299 return \CBPHelper::isWorkTimeAvailable();
313 $userFieldIds = Main\UserFieldTable::getList([
316 '=ENTITY_ID' =>
'USER',
317 '%=FIELD_NAME' =>
'UF_USR_%',
321 foreach ($userFieldIds as $fieldId)
323 $field = Main\UserFieldTable::getFieldData($fieldId[
'ID']);
324 $fieldName = $field[
'FIELD_NAME'];
327 $name = in_array(\LANGUAGE_ID, $field[
'LANGUAGE_ID'])
328 ? $field[
'LIST_COLUMN_LABEL'][\LANGUAGE_ID]
329 : $field[
'FIELD_NAME']
332 $fields[$fieldName] = [
334 'Type' => $fieldType,
335 'Multiple' => $field[
'MULTIPLE'] ===
'Y',
338 if ($fields[$fieldName][
'Type'] ===
'select')
340 $fields[$fieldName][
'Options'] = array_combine(
341 array_column($field[
'ENUM'],
'XML_ID'),
342 array_column($field[
'ENUM'],
'VALUE'),
344 $fields[$fieldName][
'Settings'] = [
'ENUM' => $field[
'ENUM']];
351 private function convertValues(array &$values, array $userFields): void
353 foreach ($userFields as $id => $field)
355 if ($field[
'Type'] ===
'bool')
357 $values[$id] = \CBPHelper::getBool($values[$id]) ?
'Y' :
'N';
359 elseif ($field[
'Type'] ===
'select')
361 $values[$id] = $this->convertSelectValue($values[$id], $field);
365 if (!empty($values[
'UF_DEPARTMENT']))
367 $values[
'UF_DEPARTMENT_PRINTABLE'] = $this->loadDepartmentNames($values[
'UF_DEPARTMENT']);
371 private function convertSelectValue($value, $field)
373 $enumIds = array_combine(
374 array_column($field[
'Settings'][
'ENUM'],
'XML_ID'),
375 array_column($field[
'Settings'][
'ENUM'],
'ID'),
378 if (is_array($value))
381 foreach ($value as $val)
383 $xmlIds[] = array_search($val, $enumIds);
386 return array_filter($xmlIds, fn($id) => $id !==
false);
389 $xmlId = array_search($value, $enumIds);
391 return $xmlId !==
false ? $xmlId :
'';
394 private function convertUserValue($value): array
398 $value = is_array($value) ? $value : [$value];
399 foreach ($value as $userId)
410 private function loadUser(
int $userId, array $fields): ?array
412 $dbUsers = \CUser::GetList(
415 [
'ID_EQUAL_EXACT' => $userId],
441 ...array_keys($fields)
446 $user = $dbUsers->fetch();
448 return is_array($user) ? $user :
null;
451 private function loadDepartmentNames(array $ids): array
455 if (!Main\Loader::includeModule(
'intranet') || !Main\Loader::includeModule(
'iblock'))
460 $iblockId = Main\Config\Option::get(
'intranet',
'iblock_structure');
462 $iterator = \CIBlockSection::GetList(
465 '=IBLOCK_ID' => $iblockId,
472 while ($row = $iterator->fetch())
474 $names[$row[
'ID']] = $row[
'NAME'];
477 return array_values(array_filter(
479 fn($id) => $names[$id] ??
null,
static getMessage($code, $replace=null, $language=null)