Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Department.php
1<?php
2
4
7
8class Department implements RestEntity
9{
10 private static ?array $structure = null;
11
12 private int $id;
13
14 public function __construct(int $id)
15 {
16 $this->id = $id;
17 }
18
19 public function getId(): ?int
20 {
21 return $this->id;
22 }
23
24 public function getDepth(): int
25 {
26 return (int)$this->get('DEPTH_LEVEL');
27 }
28
29 public function getName(): string
30 {
31 return $this->get('NAME') ?? '';
32 }
33
34 public function isExist(): bool
35 {
36 $this->fillStructure();
37
38 return isset(self::$structure['DATA'][$this->id]);
39 }
40
41 public static function getRestEntityName(): string
42 {
43 return 'department';
44 }
45
46 public function toRestFormat(array $option = []): array
47 {
48 return ['id' => $this->id, 'name' => $this->getName()];
49 }
50
51 private function fillStructure(): void
52 {
53 if (isset(self::$structure))
54 {
55 return;
56 }
57
58 if (!Loader::includeModule('intranet'))
59 {
60 self::$structure = [];
61
62 return;
63 }
64
65 $structure = \CIntranetUtils::GetStructure();
66
67 if (!isset($structure) || !isset($structure['DATA']))
68 {
69 self::$structure = [];
70
71 return;
72 }
73
74 self::$structure = $structure;
75 }
76
77 private function get(string $fieldName)
78 {
79 $this->fillStructure();
80
81 return self::$structure['DATA'][$this->id][$fieldName] ?? null;
82 }
83}