1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
usersubordinate.php
См. документацию.
1<?php
8
9namespace Bitrix\Main\Access\User;
10
11
13{
14 public const
21
22 private $userId;
23
24 private static $cache = [];
25
26 private static $structure;
27
28 public static function getDepartmentsByUserId(int $userId): array
29 {
30 $key = 'DEP_'.$userId;
31 if (!array_key_exists($key, static::$cache))
32 {
34 [
35 'filter' => [
36 '=ID' => $userId,
37 ],
38 'select' => ['UF_DEPARTMENT']
39 ]
40 );
41
42 $departments = [];
43 while ($row = $res->fetch())
44 {
45 if (is_array($row['UF_DEPARTMENT']))
46 {
47 $departments = array_merge($departments, $row['UF_DEPARTMENT']);
48 }
49 }
50
51 static::$cache[$key] = $departments;
52 }
53
54 return static::$cache[$key];
55 }
56
57 public function __construct(int $userId)
58 {
59 $this->userId = $userId;
60 }
61
62 public function getSubordinate(int $userId): int
63 {
64 if ($this->userId === $userId)
65 {
66 return self::RELATION_HIMSELF;
67 }
68
69 if (!\CModule::IncludeModule('intranet'))
70 {
71 return self::RELATION_OTHER;
72 }
73
74 $key = 'SUB_' . $this->userId .'_'. $userId;
75 if (
76 array_key_exists($key, static::$cache)
77 )
78 {
79 return static::$cache[$key];
80 }
81
82 $managers = self::getAllManagers();
83
84 $selfDepartments = self::getUserDepartments($this->userId);
85 $foreignDepartments = self::getUserDepartments($userId);
86
87 $inDepartment = !empty(array_intersect($selfDepartments, $foreignDepartments));
88
89 $selfManagers = $this->getDepartmentsManagers($selfDepartments);
90 $foreignManagers = $this->getDepartmentsManagers($foreignDepartments, true);
91
92 if (in_array($this->userId, $foreignManagers))
93 {
94 static::$cache[$key] = self::RELATION_SUBORDINATE;
95 }
96 elseif (in_array($userId, $selfManagers))
97 {
98 static::$cache[$key] = self::RELATION_DIRECTOR;
99 }
100 elseif ($inDepartment)
101 {
102 static::$cache[$key] = self::RELATION_DEPARTMENT;
103 }
104 elseif (in_array($userId, $managers))
105 {
106 static::$cache[$key] = self::RELATION_OTHER_DIRECTOR;
107 }
108 else
109 {
110 static::$cache[$key] = self::RELATION_OTHER;
111 }
112
113 return static::$cache[$key];
114 }
115
116 public static function getParentDepartments(int $id): array
117 {
118 $structure = self::getStructure();
119 $res = [];
120 foreach ($structure['TREE'] as $parent => $childs)
121 {
122 if (!is_array($childs))
123 {
124 continue;
125 }
126 if ($parent > 0 && in_array($id, $childs))
127 {
128 $res[] = $parent;
129 $res = array_merge($res, self::getParentDepartments($parent));
130 }
131 }
132
133 return $res;
134 }
135
136 private function getDepartmentsManagers($departments, bool $recursive = false): array
137 {
138 $managersIds = [];
139
140 $deps = [];
141 foreach ($departments as $depId)
142 {
143 $deps[] = $depId;
144 if ($recursive)
145 {
146 $deps = array_merge($deps, self::getParentDepartments($depId));
147 }
148 }
149 $deps = array_unique($deps);
150
151 $structure = self::getStructure();
152 foreach ($structure['DATA'] as $row)
153 {
154 if (in_array($row['ID'], $deps))
155 {
156 $id = (int) $row['UF_HEAD'];
157 $managersIds[$id] = $id;
158 }
159 }
160
161 return $managersIds;
162 }
163
164 private static function getStructure()
165 {
166 if (!static::$structure)
167 {
168 static::$structure = \CIntranetUtils::GetStructure();
169 }
170 return static::$structure;
171 }
172
173 private static function getAllManagers(): array
174 {
175 $managers = [];
176
177 $structure = self::getStructure();
178 foreach ($structure['DATA'] as $row)
179 {
180 $managers[$row['ID']] = $row['UF_HEAD'];
181 }
182
183 return $managers;
184 }
185
186 private static function getUserDepartments(int $userId)
187 {
188 $structure = self::getStructure();
189 $departments = [];
190 foreach ($structure['DATA'] as $row)
191 {
192 if (in_array($userId, $row['EMPLOYEES']))
193 {
194 $departments[$row['ID']] = $row['ID'];
195 }
196 }
197 return $departments;
198 }
199}
static getParentDepartments(int $id)
Определения usersubordinate.php:116
static getDepartmentsByUserId(int $userId)
Определения usersubordinate.php:28
static getList(array $parameters=array())
Определения datamanager.php:431
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257