1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
accesscodeconverter.php
См. документацию.
1<?php
2
4
5use Bitrix\HumanResources\Item\Node;
6use Bitrix\HumanResources\Item\NodeMember;
7use Bitrix\HumanResources\Repository\NodeRepository;
8use Bitrix\HumanResources\Service\Container;
15use Closure;
16
18{
22 private array $accessCodes;
23 private NodeRepository $nodeRepository;
24
28 public function __construct(string ...$accessCodes)
29 {
30 if (!Loader::includeModule('humanresources'))
31 {
32 throw new LoaderException('Humanresources is not loaded');
33 }
34
35 $this->accessCodes = $accessCodes;
36 $this->nodeRepository = Container::getNodeRepository();
37 }
38
46 public function getUserIds(): array
47 {
48 $userIds = $this->getDepartmentUserIds();
49 $userIds = array_merge($userIds, $this->getUsers()->getAccessCodeIdList());
50
51 return array_unique($userIds);
52 }
53
61 private function getDepartmentUserIds(): array
62 {
63 $departmentIds = $this->getDepartments()->accessCodes;
64 $departmentIdsWithoutRecursive = array_map(
65 static fn(string $departmentId): string => str_replace("DR", "D", $departmentId),
66 $departmentIds,
67 );
68
69 $nodeCollection = $this->nodeRepository->findAllByAccessCodes($departmentIdsWithoutRecursive);
70
71 $userIds = [];
72
76 foreach ($nodeCollection as $node)
77 {
78 $departmentId = $this->getEntityIdByAccessCode($node->accessCode);
79 $withAllChildNodes = in_array("DR{$departmentId}", $this->accessCodes, true);
80
81 $memberCollectionByNode = Container::getNodeMemberService()->getAllEmployees(
82 $node->id,
83 $withAllChildNodes,
84 );
85
86 $memberIdsByNode = array_map(
87 static fn(NodeMember $member) => $member->entityId,
88 $memberCollectionByNode->getItemMap()
89 );
90
91 $userIds = [...$userIds, ...$memberIdsByNode];
92 }
93
94 return array_unique($userIds);
95 }
96
97 private function getEntityIdByAccessCode(string $accessCode): int
98 {
99 return (new AccessCode($accessCode))->getEntityId();
100 }
101
102 public function getAccessCodeIdList(): array
103 {
104 $ids = array_map(static fn(string $code): int => (new AccessCode($code))->getEntityId(), $this->accessCodes);
105
106 return array_filter(array_unique($ids));
107 }
108
112 public function getUsers(): static
113 {
114 $users = array_filter($this->accessCodes, $this->getFilter(AccessCode::TYPE_USER));
115 return new static(...$users);
116 }
117
121 public function getDepartments(): static
122 {
123 $departments = array_filter($this->accessCodes, $this->getFilter(AccessCode::TYPE_DEPARTMENT));
124 return new static(...$departments);
125 }
126
127 private function getFilter(string $entityType): Closure
128 {
129 return static fn (string $code): bool => (new AccessCode($code))->getEntityType() === $entityType;
130 }
131}
Определения loader.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195