Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
scrummembers.php
1<?php
2
11
13
15{
16 public static function getValue(array $users = [], array $params = []): string
17 {
18 $visibleMembersCount = 3;
19
20 $totalHeadsCount = (int)($params['NUMBER_OF_MODERATORS'] ?? 0);
21
22 $headsLayout = '';
23 $heads = static::fillUsersLayout(($users['HEADS'] ?? []));
24 if (!empty($heads))
25 {
26 $innerLayouts = [];
27 foreach ($heads as $head)
28 {
29 if ($head['IS_OWNER'] === 'Y')
30 {
31 array_unshift($innerLayouts, $head['LAYOUT']);
32 continue;
33 }
34 $innerLayouts[] = $head['LAYOUT'];
35 }
36
37 if (count($innerLayouts) > $visibleMembersCount)
38 {
39 $innerLayouts = array_slice($innerLayouts, 0, $visibleMembersCount);
40 }
41
42 $innerLayouts = implode("\n", $innerLayouts);
43
44 $headsLayout =
45 "<div style='display: inline-block'>"
46 . "<div class='sonet-ui-grid-user-list sonet-ui-grid-user-list--green'>"
47 . $innerLayouts
48 . static::makeOtherCounterLayout($totalHeadsCount - $visibleMembersCount)
49 . "</div>"
50 . "</div>"
51 ;
52 }
53
54 $usersLayout = '';
55 $users = static::fillUsersLayout(($users['MEMBERS'] ?? []));
56
57 if (count($users) > 0)
58 {
59 $innerLayouts = [];
60 foreach ($users as $user)
61 {
62 $innerLayouts[] = $user['LAYOUT'];
63 if (count($innerLayouts) >= $visibleMembersCount)
64 {
65 break;
66 }
67 }
68 $innerLayouts = implode("\n", $innerLayouts);
69 $totalUsersCount = (int)($params['NUMBER_OF_MEMBERS'] ?? 0);
70
71 $usersLayout =
72 '<div style="display: inline-block">'
73 . '<div class="sonet-ui-grid-user-list">'
74 . $innerLayouts
75 . static::makeOtherCounterLayout(($totalUsersCount - $totalHeadsCount - $visibleMembersCount))
76 . '</div>'
77 . '</div>'
78 ;
79 }
80
81 return
82 '<div class="sonet-ui-grid-user-list-container" onclick="' . static::getMembersPopupShowFunction(
83 (int)$params['GROUP_ID'],
84 (string)$params['GROUP_TYPE'],
85 (string)$params['GRID_ID']
86 ) . '">'
87 . $headsLayout
88 . $usersLayout
89 . '</div>'
90 ;
91 }
92
93 private static function fillUsersLayout(array $users): array
94 {
95 foreach ($users as $id => $user)
96 {
97 $style = (
98 $user['PHOTO']
99 ? 'style="background-image: url(\'' . Uri::urnEncode($user['PHOTO']) . '\')"'
100 : ''
101 );
102
103 $users[$id]['LAYOUT'] =
104 '<a class="sonet-ui-grid-user-item" ' . $style . '>'
105 . '<div class="sonet-ui-grid-user-crown"></div>'
106 . '</a>'
107 ;
108 }
109
110 return $users;
111 }
112
113 private static function makeOtherCounterLayout(int $otherCount): string
114 {
115 if ($otherCount <= 0)
116 {
117 return '';
118 }
119
120 return '<div class="sonet-ui-grid-user-count"><span class="sonet-ui-grid-user-plus">+</span>' . $otherCount . '</div>';
121 }
122
123 private static function getMembersPopupShowFunction(
124 int $groupId = 0,
125 string $groupType = '',
126 string $gridId = ''
127 ): string
128 {
129 if ($groupId <= 0)
130 {
131 return '';
132 }
133
134 $gridId = htmlspecialcharsbx(\CUtil::JSescape($gridId));
135 $groupType = htmlspecialcharsbx(\CUtil::JSescape($groupType));
136
137 return '
138 BX.Socialnetwork.UI.Grid.Controller.getById(\'' . $gridId . '\')
139 .getScrumMembersPopup()
140 .showPopup(' . $groupId . ', \'' . $groupType . '\', this);
141 event.stopPropagation();'
142 ;
143 }
144
145 public static function getUserAvatars(array $imageIds = []): array
146 {
147 $result = [];
148 if (empty($imageIds))
149 {
150 return $result;
151 }
152
153 $result = array_fill_keys($imageIds, '');
154
155 $res = \CFile::getList([], ['@ID' => implode(',', $imageIds)]);
156 while ($file = $res->fetch())
157 {
158 $file['SRC'] = \CFile::getFileSRC($file);
159 $fileInfo = \CFile::ResizeImageGet(
160 $file,
161 [
162 'width' => 100,
163 'height' => 100,
164 ],
165 BX_RESIZE_IMAGE_EXACT,
166 false,
167 false,
168 true,
169 );
170
171 $result[$file['ID']] = $fileInfo['src'];
172 }
173
174 return $result;
175 }
176
177}
static urnEncode($str, $charset='UTF-8')
Definition uri.php:383
static getValue(array $users=[], array $params=[])