3namespace Bitrix\Im\V2\Integration\HumanResources\Department;
5use Bitrix\HumanResources\Compatibility\Utils\DepartmentBackwardAccessCode;
6use Bitrix\HumanResources\Contract\Repository\NodeRepository;
7use Bitrix\HumanResources\Contract\Repository\StructureRepository;
8use Bitrix\HumanResources\Contract\Service\NodeMemberService;
9use Bitrix\HumanResources\Contract\Service\NodeService;
10use Bitrix\HumanResources\Enum\DepthLevel;
11use Bitrix\HumanResources\Enum\NodeActiveFilter;
12use Bitrix\HumanResources\Item\Collection\NodeCollection;
13use Bitrix\HumanResources\Item\Node;
14use Bitrix\HumanResources\Item\NodeMember;
15use Bitrix\HumanResources\Service\Container;
16use Bitrix\Im\V2\Integration\HumanResources\Structure;
17use Bitrix\Main\Config\Option;
28 private function __construct()
30 $this->nodeRepository = Container::getNodeRepository();
31 $this->nodeMemberService = Container::getNodeMemberService();
32 $this->structureRepository = Container::getStructureRepository();
33 $this->nodeService = Container::getNodeService();
38 if (self::$instance !==
null)
40 return self::$instance;
47 return self::$instance;
50 self::$instance =
new self();
52 return self::$instance;
57 if (self::$wasSearchedTopId)
62 self::$wasSearchedTopId =
true;
65 if ($rootNode ===
null)
70 preg_match(
'/D(\d+)/', $rootNode->accessCode ??
'',
$matches);
78 if (!empty($this->structureDepartments))
84 if ($rootNode ===
null)
89 $nodes = $this->nodeRepository->getChildOf($rootNode, DepthLevel::FULL, NodeActiveFilter::ONLY_ACTIVE);
91 foreach ($nodes as $node)
94 $this->structureDepartments[$department->id] = $department;
102 if (!empty($this->structureDepartments))
110 foreach ($nodeCollection as $node)
113 $departments[$department->id] = $department;
121 $structure = $this->structureRepository->getByXmlId(\
Bitrix\
HumanResources\Item\Structure::DEFAULT_STRUCTURE_XML_ID);
122 if ($structure ===
null)
128 foreach ($this->nodeRepository->findAllByXmlId($xmlId, NodeActiveFilter::ONLY_ACTIVE) as $node)
131 $departments[$department->id] = $department;
139 $parent = $this->nodeRepository->getById($node->parentId);
140 $parentId = DepartmentBackwardAccessCode::extractIdFromCode($parent?->accessCode);
142 $headMembers = $this->nodeMemberService->getDefaultHeadRoleEmployees($node->id);
143 $id = DepartmentBackwardAccessCode::extractIdFromCode($node->accessCode);
147 headUserID: $headMembers->getIterator()->current()?->entityId ?? 0,
149 depthLevel: $node->depth,
157 $employees = $managers = [];
159 $headRole = Container::getRoleRepository()->findByXmlId(NodeMember::DEFAULT_ROLE_XML_ID[
'HEAD'])?->id;
162 foreach ($nodeCollection as $node)
164 $memberCollection = $this->nodeMemberService->getPagedEmployees(
171 foreach ($memberCollection->getItemMap() as $member)
173 if (in_array($headRole, $member->roles ?? [],
true))
175 $managers[$member->entityId] = $member->entityId;
179 $employees[$member->entityId] = $member->entityId;
191 return array_slice($managers + $employees, 0, $limit);
197 static fn($id) => DepartmentBackwardAccessCode::makeById($id),
201 return $this->nodeRepository->findAllByAccessCodes($codes);
206 $structure = $this->structureRepository->getByXmlId(\
Bitrix\
HumanResources\Item\Structure::DEFAULT_STRUCTURE_XML_ID);
207 if ($structure ===
null)
212 return $this->nodeRepository->getRootNodeByStructureId($structure->id);
217 $departmentByIds = [];
219 foreach ($departments as $department)
221 if (in_array($department->id, $ids,
true))
223 $departmentByIds[$department->id] = $department;
227 return $departmentByIds;
array $structureDepartments
filterDepartmentsByIds(array $departments, array $ids)
static IDepartment $instance
getEmployeeIdsWithLimit(array $ids, int $limit=50)
getListByXml(string $xmlId)
StructureRepository $structureRepository
getNodesByIds(array $ids)
NodeRepository $nodeRepository
NodeMemberService $nodeMemberService
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"