1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
department.php
См. документацию.
1<?php
2namespace Bitrix\Im;
3
4use Bitrix\Im\V2\Entity\User\UserCollection;
5
7{
8 public static function getColleagues($userId = null, $options = array())
9 {
11 if (!$userId)
12 {
13 return false;
14 }
15
16 $pagination = isset($options['LIST'])? true: false;
17
18 $limit = isset($options['LIST']['LIMIT'])? intval($options['LIST']['LIMIT']): 50;
19 $offset = isset($options['LIST']['OFFSET'])? intval($options['LIST']['OFFSET']): 0;
20
21 $list = Array();
22
23 $departments = \Bitrix\Im\User::getInstance($userId)->getDepartments();
24 $managers = self::getManagers($departments);
25 foreach ($managers as $departmentId => $users)
26 {
27 foreach ($users as $uid)
28 {
29 if ($userId == $uid)
30 continue;
31
32 $list[$uid] = $uid;
33 }
34 }
35
36 $employees = self::getEmployees($departments);
37 foreach ($employees as $departmentId => $users)
38 {
39 foreach ($users as $uid)
40 {
41 if ($userId == $uid)
42 continue;
43
44 $list[$uid] = $uid;
45 }
46 }
47
49 if (!empty($result))
50 {
51 $managers = self::getManagers(null);
52 foreach ($managers as $departmentId => $users)
53 {
54 foreach ($users as $uid)
55 {
56 if ($userId == $uid)
57 continue;
58
59 $list[$uid] = $uid;
60 }
61 }
62 }
63
64 $count = count($list);
65
66 $list = array_slice($list, $offset, $limit);
67
68 $jsonOption = $options['JSON'] ?? null;
69 $userDataOption = $options['USER_DATA'] ?? null;
70
71 if ($userDataOption === 'Y')
72 {
73 $result = self::getUsersData($list, $jsonOption === 'Y');
74 }
75 else
76 {
77 $result = array_values($list);
78 }
79
80
81 if ($jsonOption === 'Y')
82 {
83 $result = $pagination? Array('total' => $count, 'result' => $result): $result;
84 }
85 else
86 {
87 $result = $pagination? Array('TOTAL' => $count, 'RESULT' => $result): $result;
88 }
89
90 return $result;
91 }
92
93 public static function getColleaguesSimple(
95 int $limit = 50,
96 ): array
97 {
98 $userId = $user->getId();
99 $departments = $user->getDepartments()->getIds();
100
101 if (empty($departments))
102 {
103 return [];
104 }
105
106 $userList = [];
107 $employees = V2\Integration\HumanResources\Department\Department::getInstance()->getEmployeeIdsWithLimit($departments, $limit);
108 foreach ($employees as $employee)
109 {
110 if ($userId !== $employee)
111 {
112 $userList[$employee] = $employee;
113 }
114 }
115
117 }
118
119 protected static function getUsersData(array $userList, bool $jsonOption = true): array
120 {
121 $users = [];
122 $userCollection = new UserCollection($userList);
123 $userCollection->fillOnlineData();
124
125 $getOptions = [];
126 if ($jsonOption)
127 {
128 $getOptions['JSON'] = 'Y';
129 }
130
131 foreach ($userCollection as $user)
132 {
133 $users[] = $user->getArray($getOptions);
134 }
135
136 return $users;
137 }
138
139 public static function getDepartmentYouManage($userId = null, $options = array())
140 {
142 if (!$userId)
143 {
144 return false;
145 }
146
147 $jsonOption = $options['JSON'] ?? null;
148 $userDataOption = $options['USER_DATA'] ?? null;
149
151
152 $result = Array();
153 foreach ($list as $key => $department)
154 {
155 if ((int)$department['MANAGER_USER_ID'] !== $userId)
156 {
157 continue;
158 }
159 if ($userDataOption === 'Y')
160 {
161 $userData = \Bitrix\Im\User::getInstance($department['MANAGER_USER_ID']);
162 $department['MANAGER_USER_DATA'] = $jsonOption === 'Y'? $userData->getArray(Array('JSON' => 'Y')): $userData;
163 }
164
165 $result[$key] = $jsonOption === 'Y'? array_change_key_case($department, CASE_LOWER): $department;
166 }
167
168 if ($jsonOption === 'Y')
169 {
170 $result = array_values($result);
171 }
172
173 return $result;
174 }
175
176 public static function getStructure($options = array())
177 {
179
180 if (isset($options['FILTER']['ID']))
181 {
182 foreach ($list as $key => $department)
183 {
184 if (!in_array($department['ID'], $options['FILTER']['ID']))
185 {
186 unset($list[$key]);
187 }
188 }
189 }
190
191 $pagination = isset($options['LIST'])? true: false;
192
193 $limit = isset($options['LIST']['LIMIT'])? intval($options['LIST']['LIMIT']): 50;
194 $offset = isset($options['LIST']['OFFSET'])? intval($options['LIST']['OFFSET']): 0;
195
196 if (isset($options['FILTER']['SEARCH']) && mb_strlen($options['FILTER']['SEARCH']) > 1)
197 {
198 $count = 0;
199 $breakAfterDigit = $offset === 0? $offset: false;
200
201 $options['FILTER']['SEARCH'] = mb_strtolower($options['FILTER']['SEARCH']);
202 foreach ($list as $key => $department)
203 {
204 $checkField = mb_strtolower($department['FULL_NAME']);
205 if (
206 mb_strpos($checkField, $options['FILTER']['SEARCH']) !== 0
207 && mb_strpos($checkField, ' '.$options['FILTER']['SEARCH']) === false
208 )
209 {
210 unset($list[$key]);
211 }
212 if ($breakAfterDigit !== false)
213 {
214 $count++;
215 if ($count === $breakAfterDigit)
216 {
217 break;
218 }
219 }
220 }
221 }
222
223 $count = count($list);
224
225 $list = array_slice($list, $offset, $limit);
226
227 if ($options['JSON'] == 'Y' || $options['USER_DATA'] == 'Y')
228 {
229 if ($options['JSON'] == 'Y')
230 {
231 $list = array_values($list);
232 }
233 foreach ($list as $key => $department)
234 {
235 if ($options['USER_DATA'] == 'Y')
236 {
237 $userData = \Bitrix\Im\User::getInstance($department['MANAGER_USER_ID']);
238 $department['MANAGER_USER_DATA'] = $options['JSON'] == 'Y'? $userData->getArray(Array('JSON' => 'Y')): $userData;
239 }
240
241 $list[$key] = $options['JSON'] == 'Y'? array_change_key_case($department, CASE_LOWER): $department;
242 }
243 }
244
245 if ($options['JSON'] == 'Y')
246 {
247 $list = $pagination? Array('total' => $count, 'result' => $list): $list;
248 }
249 else
250 {
251 $list = $pagination? Array('TOTAL' => $count, 'RESULT' => $list): $list;
252 }
253
254 return $list;
255 }
256
257 public static function getManagers($ids = null, $options = array())
258 {
260
261 $userOptions = Array();
262 $jsonOption = $options['JSON'] ?? null;
263 $userDataOption = $options['USER_DATA'] ?? null;
264
265 if ($jsonOption)
266 {
267 $userOptions['JSON'] = 'Y';
268 }
269
270 $managers = Array();
271 foreach ($list as $department)
272 {
273 if ($department['MANAGER_USER_ID'] <= 0)
274 continue;
275
276 if (is_array($ids) && !in_array($department['ID'], $ids))
277 continue;
278
279 if ($userDataOption === 'Y')
280 {
281 $managers[$department['ID']][] = \Bitrix\Im\User::getInstance($department['MANAGER_USER_ID'])->getArray($userOptions);
282 }
283 else
284 {
285 $managers[$department['ID']][] = $department['MANAGER_USER_ID'];
286 }
287 }
288
289 return $managers;
290 }
291
292 public static function getEmployeesList($ids = null, $options = array())
293 {
294 if (!\Bitrix\Main\Loader::includeModule('intranet'))
295 {
296 return Array();
297 }
298
299 $structure = \CIntranetUtils::GetStructure();
300 if (!$structure || !isset($structure['DATA']))
301 {
302 return Array();
303 }
304
305 $result = Array();
306 foreach ($structure['DATA'] as $department)
307 {
308 if (is_array($ids) && !in_array($department['ID'], $ids))
309 continue;
310
311 if (!is_array($department['EMPLOYEES']))
312 {
313 $result[$department['ID']] = Array();
314 continue;
315 }
316
317 foreach ($department['EMPLOYEES'] as $key => $value)
318 {
319 $department['EMPLOYEES'][$key] = (int)$value;
320 }
321
322 $result[$department['ID']] = $department['EMPLOYEES'];
323 }
324
325 return $result;
326 }
327
328 public static function getEmployees($ids = null, $options = array())
329 {
330 $list = self::getEmployeesList();
331
332 $userOptions = Array();
333
334 $jsonOption = $options['JSON'] ?? null;
335 $userDataOption = $options['USER_DATA'] ?? null;
336
337 if ($jsonOption)
338 {
339 $userOptions['JSON'] = 'Y';
340 }
341
342 $employees = Array();
343 foreach ($list as $departmentId => $users)
344 {
345 if (is_array($ids) && !in_array($departmentId, $ids))
346 continue;
347
348 foreach ($users as $employeeId)
349 {
350 if ($userDataOption === 'Y')
351 {
352 $employees[$departmentId][] = \Bitrix\Im\User::getInstance($employeeId)->getArray($userOptions);
353 }
354 else
355 {
356 $employees[$departmentId][] = $employeeId;
357 }
358 }
359 }
360
361 return $employees;
362 }
363}
$count
Определения admin_tab.php:4
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getUserId($userId=null)
Определения common.php:73
static getColleagues($userId=null, $options=array())
Определения department.php:8
static getUsersData(array $userList, bool $jsonOption=true)
Определения department.php:119
static getColleaguesSimple(\Bitrix\Im\V2\Entity\User\User $user, int $limit=50,)
Определения department.php:93
static getStructure($options=array())
Определения department.php:176
static getEmployeesList($ids=null, $options=array())
Определения department.php:292
static getEmployees($ids=null, $options=array())
Определения department.php:328
static getDepartmentYouManage($userId=null, $options=array())
Определения department.php:139
static getManagers($ids=null, $options=array())
Определения department.php:257
static getList(?array $ids=null)
Определения department.php:19
static getInstance($userId=null)
Определения user.php:45
$options
Определения commerceml2.php:49
$userList
Определения discount_coupon_list.php:276
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$uid
Определения hot_keys_act.php:8
Определения ActionUuid.php:3
Определения ufield.php:9
$user
Определения mysql_to_pgsql.php:33
if(empty($signedUserToken)) $key
Определения quickway.php:257
</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."%"
Определения waybill.php:936