22 return $this->getUserDepartmentsOld(
$userId);
32 if (isset($this->users[
$userId]))
39 return $this->loadUser(
$userId, $userFields);
46 if ($this->canUseIntranet())
49 'Name' => Loc::getMessage(
'BP_SERVICE_USER_DEPARTMENT_1'),
54 $fields[
'UF_DEPARTMENT_PRINTABLE'] = [
55 'Name' => Loc::getMessage(
'BP_SERVICE_USER_DEPARTMENT_PRINTABLE_1'),
61 'Name' => Loc::getMessage(
'BP_SERVICE_USER_IS_ABSENT'),
65 if ($this->canUseIblockApi() || $this->canUseHumanResources())
68 'Name' => Loc::getMessage(
'BP_SERVICE_USER_HEAD'),
75 if ($this->canUseTimeman())
78 'Name' => Loc::getMessage(
'BP_SERVICE_USER_TIMEMAN_STATUS'),
81 'EXPIRED' => Loc::getMessage(
'BP_SERVICE_USER_TIMEMAN_STATUS_EXPIRED'),
82 'OPENED' => Loc::getMessage(
'BP_SERVICE_USER_TIMEMAN_STATUS_OPENED'),
83 'PAUSED' => Loc::getMessage(
'BP_SERVICE_USER_TIMEMAN_STATUS_PAUSED'),
84 'CLOSED' => Loc::getMessage(
'BP_SERVICE_USER_TIMEMAN_STATUS_CLOSED'),
89 if ($this->canUseHumanResources())
92 'Name' => Loc::getMessage(
'BP_SERVICE_USER_HR_NODE_IDS'),
97 'Name' => Loc::getMessage(
'BP_SERVICE_USER_HR_NODE'),
110 'Name' => Loc::getMessage(
'BP_SERVICE_USER_ACTIVE'),
114 'Name' => Loc::getMessage(
'BP_SERVICE_USER_EMAIL'),
118 'Name' => Loc::getMessage(
'BP_SERVICE_USER_WORK_PHONE'),
121 'PERSONAL_MOBILE' => [
122 'Name' => Loc::getMessage(
'BP_SERVICE_USER_PERSONAL_MOBILE'),
125 'UF_PHONE_INNER' => [
126 'Name' => Loc::getMessage(
'BP_SERVICE_USER_UF_PHONE_INNER'),
130 'Name' => Loc::getMessage(
'BP_SERVICE_USER_LOGIN'),
134 'Name' => Loc::getMessage(
'BP_SERVICE_USER_NAME'),
138 'Name' => Loc::getMessage(
'BP_SERVICE_USER_LAST_NAME'),
142 'Name' => Loc::getMessage(
'BP_SERVICE_USER_SECOND_NAME'),
146 'Name' => Loc::getMessage(
'BP_SERVICE_USER_WORK_POSITION'),
149 'PERSONAL_BIRTHDAY' => [
150 'Name' => Loc::getMessage(
'BP_SERVICE_USER_PERSONAL_BIRTHDAY'),
154 'Name' => Loc::getMessage(
'BP_SERVICE_USER_PERSONAL_WWW'),
158 'Name' => Loc::getMessage(
'BP_SERVICE_USER_PERSONAL_CITY'),
162 'Name' => Loc::getMessage(
'BP_SERVICE_USER_DEPARTMENT_1'),
167 'Name' => Loc::getMessage(
'BP_SERVICE_USER_UF_SKYPE'),
171 'Name' => Loc::getMessage(
'BP_SERVICE_USER_UF_TWITTER'),
175 'Name' => Loc::getMessage(
'BP_SERVICE_USER_UF_FACEBOOK'),
179 'Name' => Loc::getMessage(
'BP_SERVICE_USER_UF_LINKEDIN'),
183 'Name' => Loc::getMessage(
'BP_SERVICE_USER_UF_XING'),
187 'Name' => Loc::getMessage(
'BP_SERVICE_USER_UF_WEB_SITES'),
207 if (!$this->canUseHumanResources())
209 return $this->getDepartmentChainOld($departmentId);
213 $node = $this->getDepartmentNode($departmentId);
217 $nodes = Container::getNodeRepository()->getParentOf(
219 \
Bitrix\HumanResources\Enum\DepthLevel::FULL,
221 foreach ($nodes as $parent)
223 $idByAccessCode = DepartmentBackwardAccessCode::extractIdFromCode($parent->accessCode);
224 if ($idByAccessCode !==
null)
226 $chain[] = $idByAccessCode;
239 foreach ($userDepartments as $chain)
241 foreach ($chain as $deptId)
245 if (!$departmentHead || $departmentHead ===
$userId)
250 $heads[] = $departmentHead;
255 return array_unique($heads);
260 if (!$this->canUseHumanResources())
262 return $this->getDepartmentHeadOld($departmentId);
265 $node = $this->getDepartmentNode($departmentId);
271 $head = current(Container::getNodeMemberService()->getDefaultHeadRoleEmployees($node->id)->getItemMap());
273 return $head->entityId ??
null;
284 static::DEPARTMENT_MODULE_ID,
285 static::DEPARTMENT_OPTION_NAME
289 private function canUseHumanResources(): bool
294 private function canUseIblockApi()
299 private function canUseIntranet()
304 private function canUseTimeman()
306 return \CBPHelper::isWorkTimeAvailable();
321 'select' => array_merge(
322 [
'ID',
'FIELD_NAME',
'USER_TYPE_ID',
'MULTIPLE'],
326 '=ENTITY_ID' =>
'USER',
327 '%=FIELD_NAME' =>
'UF_USR_%',
335 foreach ($userFields as $field)
337 $fieldName = $field[
'FIELD_NAME'];
340 $name = empty($field[
'LIST_COLUMN_LABEL']) ? $field[
'FIELD_NAME'] : $field[
'LIST_COLUMN_LABEL'];
344 'Type' => $fieldType,
345 'Multiple' => $field[
'MULTIPLE'] ===
'Y',
348 if (
$fields[$fieldName][
'Type'] ===
'select')
351 $fields[$fieldName][
'Options'] = array_combine(
352 array_column($fieldData[
'ENUM'],
'XML_ID'),
353 array_column($fieldData[
'ENUM'],
'VALUE'),
355 $fields[$fieldName][
'Settings'] = [
'ENUM' => $fieldData[
'ENUM']];
364 if (!$this->canUseHumanResources())
366 return $this->extractUsersFromDepartmentOld($departmentId, $recursive);
369 $node = $this->getDepartmentNode($departmentId);
387 UserGroupTable::query()
388 ->setSelect([
'USER_ID'])
389 ->where(
'GROUP_ID', $groupId)
390 ->setOrder([
'USER_ID' =>
'ASC'])
404 if (!$this->canUseHumanResources())
406 return $this->extractUsersFromAllDepartmentsOld();
409 $rootNode = \Bitrix\HumanResources\Util\StructureHelper::getRootStructureDepartment();
412 $employees = Container::getNodeMemberService()->getAllEmployees($rootNode->id,
true);
414 $result = array_map(
static fn(NodeMember $item) => $item->entityId, [...$employees->getItemMap()]);
428 private function extractUsersFromAllDepartmentsOld(): bool |
array
436 [
'ACTIVE' =>
'Y',
'>UF_DEPARTMENT' => 0],
455 $iterator = \CSocNetUserToGroup::GetList(
456 [
'USER_ID' =>
'ASC'],
457 [
'=GROUP_ID' => $groupId,
'<=ROLE' => $role,
'USER_ACTIVE' =>
'Y'],
475 if ($nodeId <= 0 || !$this->canUseHumanResources())
480 $employeesCollection = Container::getNodeMemberService()->getPagedEmployees($nodeId, $recursive);
484 array_map(
static fn(NodeMember $item) => $item->entityId, [...$employeesCollection->getItemMap()])
489 private function convertValues(
array &$values,
array $userFields): void
491 foreach ($userFields as $id => $field)
493 if ($field[
'Type'] ===
'bool')
495 $values[$id] = \CBPHelper::getBool($values[$id]) ?
'Y' :
'N';
497 elseif ($field[
'Type'] ===
'select')
499 $values[$id] = $this->convertSelectValue($values[$id], $field);
503 if (!empty($values[
'UF_DEPARTMENT']))
505 $values[
'UF_DEPARTMENT_PRINTABLE'] = $this->loadDepartmentNames($values[
'UF_DEPARTMENT']);
509 private function convertSelectValue($value, $field)
511 $enumIds = array_combine(
512 array_column($field[
'Settings'][
'ENUM'],
'XML_ID'),
513 array_column($field[
'Settings'][
'ENUM'],
'ID'),
516 if (is_array($value))
519 foreach ($value as
$val)
521 $xmlIds[] = array_search(
$val, $enumIds);
524 return array_filter($xmlIds, fn($id) => $id !==
false);
527 $xmlId = array_search($value, $enumIds);
529 return $xmlId !==
false ? $xmlId :
'';
532 private function convertUserValue($value):
array
550 $dbUsers = \CUser::GetList(
584 $user = $dbUsers->fetch();
588 if ($this->canUseHumanResources())
590 $user[
'HR_NODE_IDS'] =
592 static fn (\Bitrix\HumanResources\Item\Node $node) => $node->id,
593 [...Container::getNodeRepository()->findAllByUserId(
$userId)->getItemMap()]
596 $user[
'HR_NODE'] = array_map(
static fn(
int $id) =>
'group_hr' . $id,
$user[
'HR_NODE_IDS']);
603 $this->users[
$userId][
'IS_ABSENT'] = $schedule->isAbsent();
604 $this->users[
$userId][
'TIMEMAN_STATUS'] = $schedule->getWorkDayStatus();
613 private function loadDepartmentNames(
array $ids):
array
615 if (!$this->canUseHumanResources())
617 return $this->loadDepartmentNamesOld($ids);
621 static fn($id) => DepartmentBackwardAccessCode::makeById($id),
625 $collection = Container::getNodeRepository()->findAllByAccessCodes($codes);
627 foreach ($collection as $node)
629 $names[DepartmentBackwardAccessCode::extractIdFromCode($node->accessCode)] = $node->name;
632 return array_values(array_filter(
634 static fn($id) => $names[$id] ??
null,
640 private function getDepartmentNode(
int $departmentId): ?\Bitrix\HumanResources\Item\Node
642 return Container::getNodeRepository()->getByAccessCode(DepartmentBackwardAccessCode::makeById($departmentId));
651 private function extractUsersFromDepartmentOld(
int $departmentId,
bool $recursive =
false): ?
array
653 if (!$this->canUseIntranet() || !$this->canUseIblockApi())
659 $departmentIds = [$departmentId];
665 [
'=IBLOCK_ID' =>
$iblockId,
'ID' => $departmentId],
667 [
'ID',
'LEFT_MARGIN',
'RIGHT_MARGIN',
'DEPTH_LEVEL']
672 ">LEFT_MARGIN" => $section[
"LEFT_MARGIN"],
673 "<RIGHT_MARGIN" => $section[
"RIGHT_MARGIN"],
674 ">DEPTH_LEVEL" => $section[
'DEPTH_LEVEL'],
676 $iterator = \CIBlockSection::GetList([
"left_margin" =>
"asc"],
$filter,
false, [
'ID']);
679 $departmentIds[] = $section[
'ID'];
684 $iterator = \CUser::GetList(
"departmentId",
"asc",
685 [
'ACTIVE' =>
'Y',
'UF_DEPARTMENT' => $departmentIds],
702 private function loadDepartmentNamesOld(
array $ids):
array
718 'CHECK_PERMISSIONS' =>
'N',
726 $names[$row[
'ID']] = $row[
'NAME'];
729 return array_values(array_filter(
731 fn($id) => $names[$id] ??
null,
742 private function getUserDepartmentsOld(
int $userId):
array
744 if (isset($this->users[
$userId][
'UF_DEPARTMENT']))
746 return is_array($this->users[
$userId][
'UF_DEPARTMENT']) ? $this->users[
$userId][
'UF_DEPARTMENT'] : [];
753 [
'FIELDS' => [
'ID'],
'SELECT' => [
'UF_DEPARTMENT']]
758 if (isset(
$user[
'UF_DEPARTMENT']))
761 foreach (
$user[
'UF_DEPARTMENT'] as $dpt)
763 $departments[] = (int) $dpt;
776 private function getDepartmentChainOld(
int $departmentId):
array
780 if (!$this->canUseIblockApi())
786 $chain = \CIBlockSection::getNavChain($departmentIblockId, $departmentId, [
'ID'],
true);
789 static fn($value) => (
int)$value[
'ID'],
793 return array_reverse($chain);
801 private function getDepartmentHeadOld(
int $departmentId): ?int
803 if (!$this->canUseIblockApi())
809 $sectionResult = \CIBlockSection::GetList(
811 [
'IBLOCK_ID' => $departmentIblockId,
'ID' => $departmentId],
815 $section = $sectionResult->fetch();
817 return $section ? (int) $section[
'UF_HEAD'] : null;
static get($moduleId, $name, $default="", $siteId=false)
static includeModule($moduleName)
static getList(array $parameters=array())
static normalizeArrayValuesByInt(&$map, $sorted=true)
static getLabelsSelect(string $referenceName=null)
static getLabelsReference(string $referenceName=null, string $languageId=null)
static getFieldData(int $id)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)