1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
structure.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Integration\HumanResources;
4
5use Bitrix\HumanResources;
6use Bitrix\Main\Loader;
7
8final class Structure
9{
10 private const INITIAL_ROOT_DEPARTMENT_ID = -1;
11 private static ?int $rootDepartmentId = self::INITIAL_ROOT_DEPARTMENT_ID;
12
13 private static ?self $instance;
14
15 public static function getInstance(): self
16 {
17 self::$instance ??= new self();
18
19 return self::$instance;
20 }
21
22 public function getRootDepartmentId(): ?int
23 {
24 if (self::$rootDepartmentId === self::INITIAL_ROOT_DEPARTMENT_ID)
25 {
26 self::$rootDepartmentId = $this->loadRootDepartmentId();
27 }
28
29 return self::$rootDepartmentId;
30 }
31
32 private function loadRootDepartmentId(): ?int
33 {
34 if (!Loader::includeModule('humanresources'))
35 {
36 return null;
37 }
38
39 $structure = (new HumanResources\Repository\StructureRepository())->getByXmlId(
40 HumanResources\Item\Structure::DEFAULT_STRUCTURE_XML_ID,
41 );
42
43 if (!isset($structure))
44 {
45 return null;
46 }
47
48 $rootNode = (new HumanResources\Repository\NodeRepository())->getRootNodeByStructureId($structure->id);
49 if (!isset($rootNode))
50 {
51 return null;
52 }
53
54 preg_match('/D(\d+)/', $rootNode->accessCode ?? '', $matches);
55
56 if (empty($matches[1]))
57 {
58 return null;
59 }
60
61 return (int)$matches[1];
62 }
63}
$matches
Определения index.php:22