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