6 public static function getColleagues($userId =
null, $options = array())
8 $userId = \Bitrix\Im\Common::getUserId($userId);
14 $pagination = isset($options[
'LIST'])?
true:
false;
16 $limit = isset($options[
'LIST'][
'LIMIT'])? intval($options[
'LIST'][
'LIMIT']): 50;
17 $offset = isset($options[
'LIST'][
'OFFSET'])? intval($options[
'LIST'][
'OFFSET']): 0;
21 $departments = \Bitrix\Im\User::getInstance($userId)->getDepartments();
23 foreach ($managers as $departmentId => $users)
25 foreach ($users as $uid)
35 foreach ($employees as $departmentId => $users)
37 foreach ($users as $uid)
50 foreach ($managers as $departmentId => $users)
52 foreach ($users as $uid)
62 $count = count($list);
64 $list = array_slice($list, $offset, $limit);
66 $jsonOption = $options[
'JSON'] ??
null;
67 $userDataOption = $options[
'USER_DATA'] ??
null;
69 if ($userDataOption ===
'Y')
73 $getOptions = Array();
74 if ($jsonOption ===
'Y')
76 $getOptions[
'JSON'] =
'Y';
79 foreach ($list as $userId)
81 $result[] = \Bitrix\Im\User::getInstance($userId)->getArray($getOptions);
86 $result = array_values($list);
90 if ($jsonOption ===
'Y')
92 $result = $pagination? Array(
'total' => $count,
'result' => $result): $result;
96 $result = $pagination? Array(
'TOTAL' => $count,
'RESULT' => $result): $result;
104 $userId = \Bitrix\Im\Common::getUserId($userId);
110 $jsonOption = $options[
'JSON'] ??
null;
111 $userDataOption = $options[
'USER_DATA'] ??
null;
113 $list = \Bitrix\Im\Integration\Intranet\Department::getList();
116 foreach ($list as $key => $department)
118 if ((
int)$department[
'MANAGER_USER_ID'] !== $userId)
122 if ($userDataOption ===
'Y')
124 $userData = \Bitrix\Im\User::getInstance($department[
'MANAGER_USER_ID']);
125 $department[
'MANAGER_USER_DATA'] = $jsonOption ===
'Y'? $userData->getArray(Array(
'JSON' =>
'Y')): $userData;
128 $result[$key] = $jsonOption ===
'Y'? array_change_key_case($department, CASE_LOWER): $department;
131 if ($jsonOption ===
'Y')
133 $result = array_values($result);
141 $list = \Bitrix\Im\Integration\Intranet\Department::getList();
143 if (isset($options[
'FILTER'][
'ID']))
145 foreach ($list as $key => $department)
147 if (!in_array($department[
'ID'], $options[
'FILTER'][
'ID']))
154 $pagination = isset($options[
'LIST'])?
true:
false;
156 $limit = isset($options[
'LIST'][
'LIMIT'])? intval($options[
'LIST'][
'LIMIT']): 50;
157 $offset = isset($options[
'LIST'][
'OFFSET'])? intval($options[
'LIST'][
'OFFSET']): 0;
159 if (isset($options[
'FILTER'][
'SEARCH']) && mb_strlen($options[
'FILTER'][
'SEARCH']) > 1)
162 $breakAfterDigit = $offset === 0? $offset:
false;
164 $options[
'FILTER'][
'SEARCH'] = ToLower($options[
'FILTER'][
'SEARCH']);
165 foreach ($list as $key => $department)
167 $checkField = ToLower($department[
'FULL_NAME']);
169 mb_strpos($checkField, $options[
'FILTER'][
'SEARCH']) !== 0
170 && mb_strpos($checkField,
' '.$options[
'FILTER'][
'SEARCH']) ===
false
175 if ($breakAfterDigit !==
false)
178 if ($count === $breakAfterDigit)
186 $count = count($list);
188 $list = array_slice($list, $offset, $limit);
190 if ($options[
'JSON'] ==
'Y' || $options[
'USER_DATA'] ==
'Y')
192 if ($options[
'JSON'] ==
'Y')
194 $list = array_values($list);
196 foreach ($list as $key => $department)
198 if ($options[
'USER_DATA'] ==
'Y')
200 $userData = \Bitrix\Im\User::getInstance($department[
'MANAGER_USER_ID']);
201 $department[
'MANAGER_USER_DATA'] = $options[
'JSON'] ==
'Y'? $userData->getArray(Array(
'JSON' =>
'Y')): $userData;
204 $list[$key] = $options[
'JSON'] ==
'Y'? array_change_key_case($department, CASE_LOWER): $department;
208 if ($options[
'JSON'] ==
'Y')
210 $list = $pagination? Array(
'total' => $count,
'result' => $list): $list;
214 $list = $pagination? Array(
'TOTAL' => $count,
'RESULT' => $list): $list;
220 public static function getManagers($ids =
null, $options = array())
222 $list = \Bitrix\Im\Integration\Intranet\Department::getList();
224 $userOptions = Array();
225 $jsonOption = $options[
'JSON'] ??
null;
226 $userDataOption = $options[
'USER_DATA'] ??
null;
230 $userOptions[
'JSON'] =
'Y';
234 foreach ($list as $department)
236 if ($department[
'MANAGER_USER_ID'] <= 0)
239 if (is_array($ids) && !in_array($department[
'ID'], $ids))
242 if ($userDataOption ===
'Y')
244 $managers[$department[
'ID']][] = \Bitrix\Im\User::getInstance($department[
'MANAGER_USER_ID'])->getArray($userOptions);
248 $managers[$department[
'ID']][] = $department[
'MANAGER_USER_ID'];
295 $userOptions = Array();
297 $jsonOption = $options[
'JSON'] ??
null;
298 $userDataOption = $options[
'USER_DATA'] ??
null;
302 $userOptions[
'JSON'] =
'Y';
305 $employees = Array();
306 foreach ($list as $departmentId => $users)
308 if (is_array($ids) && !in_array($departmentId, $ids))
311 foreach ($users as $employeeId)
313 if ($userDataOption ===
'Y')
315 $employees[$departmentId][] = \Bitrix\Im\User::getInstance($employeeId)->getArray($userOptions);
319 $employees[$departmentId][] = $employeeId;