Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
user.php
1<?php
2
4
5use Bitrix\Main\Entity\Query;
8
9class User
10{
11 public static function fillUsers(array $params = []): array
12 {
13 $result = [];
14
15 if (
16 !isset($params['groupIdList'])
17 || !is_array($params['groupIdList'])
18 )
19 {
20 return $result;
21 }
22
23 $groupIdList = Util::filterNumericIdList($params['groupIdList']);
24 if (empty($groupIdList))
25 {
26 return $result;
27 }
28
29 $scrumMasterIdList = ($params['scrumMasterIdList'] ?? []);
30
31 $query = new Query(UserToGroupTable::getEntity());
32 $records = $query
33 ->setSelect([
34 'GROUP_ID',
35 'USER_ID',
36 'ROLE',
37 'INITIATED_BY_TYPE',
38 'AUTO_MEMBER',
39 'NAME' => 'USER.NAME',
40 'LAST_NAME' => 'USER.LAST_NAME',
41 'SECOND_NAME' => 'USER.SECOND_NAME',
42 'LOGIN' => 'USER.LOGIN',
43 'PERSONAL_PHOTO' => 'USER.PERSONAL_PHOTO',
44 ])
45 ->whereIn('GROUP_ID', $groupIdList)
46 ->whereIn('ROLE', UserToGroupTable::getRolesMember())
47 ->exec()->fetchCollection();
48
49 $imageIdList = [];
50 foreach ($records as $record)
51 {
52 $user = $record->get('USER');
53 $imageIdList[$record->get('USER_ID')] = $user->get('PERSONAL_PHOTO');
54 $members[] = $record;
55 }
56
57 $imageIdList = array_filter(
58 $imageIdList,
59 static function ($id) {
60 return (int)$id > 0;
61 }
62 );
63
64 $avatars = Helper\UI\Grid\Workgroup\Members::getUserAvatars($imageIdList);
65 $membersData = [];
66
67 foreach ($members as $member)
68 {
69 $memberId = (int)$member['USER_ID'];
70 $groupId = (int)$member['GROUP_ID'];
71
72 $isScrumProject = isset($scrumMasterIdList[$groupId]);
73
74 $isOwner = ($member['ROLE'] === UserToGroupTable::ROLE_OWNER);
75 $isModerator = ($member['ROLE'] === UserToGroupTable::ROLE_MODERATOR);
76 $isScrumMaster = ($isScrumProject && $scrumMasterIdList[$groupId] === $memberId);
77 $isHead = ($isOwner || $isModerator);
78
79 if (!isset($membersData[$groupId]))
80 {
81 $membersData[$groupId] = [];
82 }
83
84 $membersData[$groupId][($isHead ? 'HEADS' : 'MEMBERS')][$memberId] = [
85 'ID' => $memberId,
86 'IS_OWNER' => ($isOwner ? 'Y' : 'N'),
87 'IS_MODERATOR' => ($isModerator ? 'Y' : 'N'),
88 'IS_SCRUM_MASTER' => ($isScrumMaster ? 'Y' : 'N'),
89 'IS_AUTO_MEMBER' => $member['AUTO_MEMBER'],
90 'PHOTO' => ($avatars[($imageIdList[$memberId] ?? '')] ?? ''),
91 ];
92 }
93
94 foreach ($groupIdList as $groupId)
95 {
96 $result[$groupId] = [
97 'HEADS' => ($membersData[$groupId]['HEADS'] ?? []),
98 'MEMBERS' => ($membersData[$groupId]['MEMBERS'] ?? []),
99 ];
100 }
101
102 return $result;
103 }
104}
static filterNumericIdList(array $idList=[])
Definition util.php:7