10 private const INITIAL_ROOT_DEPARTMENT_ID = -1;
11 private static ?
int $rootDepartmentId = self::INITIAL_ROOT_DEPARTMENT_ID;
13 private static ?
self $instance;
17 self::$instance ??=
new self();
19 return self::$instance;
24 if (self::$rootDepartmentId === self::INITIAL_ROOT_DEPARTMENT_ID)
26 self::$rootDepartmentId = $this->loadRootDepartmentId();
29 return self::$rootDepartmentId;
32 private function loadRootDepartmentId(): ?int
34 if (!Loader::includeModule(
'humanresources'))
39 $structure = (
new HumanResources\Repository\StructureRepository())->getByXmlId(
43 if (!isset($structure))
48 $rootNode = (
new HumanResources\Repository\NodeRepository())->getRootNodeByStructureId($structure->id);
49 if (!isset($rootNode))
54 preg_match(
'/D(\d+)/', $rootNode->accessCode ??
'',
$matches);