Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
usertag.php
1<?php
9
14
16{
17 public static function getTagData($params)
18 {
19 $result = [
20 'USERS' => []
21 ];
22
23 if (
24 empty($params)
25 || !is_array($params)
26 || !isset($params['tag'])
27 || trim($params['tag']) === ''
28 )
29 {
30 return $result;
31 }
32
33 $tag = trim($params['tag']);
34
35 $currentUserId = (isset($params['currentUserId']) ? (int)$params['currentUserId'] : 0);
36 $avatarSize = (isset($params['avatarSize']) ? (int)$params['avatarSize'] : 100);
37 $pageSize = (isset($params['pageSize']) ? (int)$params['pageSize'] : 10);
38 $pageNum = (!empty($params['page']) ? (int)$params['page'] : 1);
39 $pathToUser = (!empty($params['pathToUser']) ? $params['pathToUser'] : '');
40
41 $ratingId = (int)\CRatings::getAuthorityRating();
42 if ($ratingId <= 0)
43 {
44 return $result;
45 }
46
47 $userIdList = [];
48
49 $queryParams = [
50 'order' => (
51 ModuleManager::isModuleInstalled('intranet')
52 ? [
53 'SUBORDINATE.VOTES' => 'DESC'
54 ]
55 : []
56 ),
57 'filter' => [
58 'NAME' => $tag,
59 '=USER.ACTIVE' => 'Y'
60 ],
61 'runtime' => (
62 ModuleManager::isModuleInstalled('intranet')
63 ? [
64 new \Bitrix\Main\Entity\ReferenceField(
65 'SUBORDINATE',
66 '\Bitrix\Intranet\RatingSubordinateTable',
67 Entity\Query\Join::on('this.USER_ID', 'ref.ENTITY_ID')->where('ref.RATING_ID', $ratingId),
68 ["join_type" => "left"]
69 )
70 ]
71 : []
72 ),
73 'select' => [ 'USER_ID' ]
74 ];
75
76 if (isset($params['pageSize']))
77 {
78 $queryParams['limit'] = $pageSize;
79 $queryParams['offset'] = ($pageNum - 1) * $pageSize;
80 }
81
82 $res = UserTagTable::getList($queryParams);
83
84 while ($fields = $res->fetch())
85 {
86 $userIdList[] = $fields['USER_ID'];
87 }
88
89 if (!empty($userIdList))
90 {
91 $userData = self::getUserData([
92 'userIdList' => $userIdList,
93 'pathToUser' => $pathToUser,
94 'avatarSize' => $avatarSize
95 ]);
96
97 foreach($userIdList as $userId)
98 {
99 if (isset($userData[$userId]))
100 {
101 $result['USERS'][] = $userData[$userId];
102 }
103 }
104 }
105
106 $result['CAN_ADD'] = 'N';
107 if ($currentUserId > 0)
108 {
109 $res = UserTagTable::getList([
110 'filter' => [
111 'USER_ID' => $currentUserId,
112 'NAME' => $tag
113 ]
114 ]);
115 if (!($res->fetch()))
116 {
117 $result['CAN_ADD'] = 'Y';
118 }
119 }
120
121 return $result;
122 }
123
124 public static function getUserData($params)
125 {
126 $result = [];
127
128 if (
129 empty($params)
130 && !is_array($params)
131 )
132 {
133 return $result;
134 }
135
136 $userIdList = (!empty($params['userIdList']) && is_array($params['userIdList']) ? $params['userIdList'] : []);
137 $avatarSize = (!empty($params['avatarSize']) && (int)$params['avatarSize'] > 0 ? (int)$params['avatarSize'] : 100);
138
139 if (empty($userIdList))
140 {
141 return $result;
142 }
143
144 $select = [ 'ID', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'LOGIN', 'PERSONAL_PHOTO', 'PERSONAL_GENDER' ];
145
146 $getListClassName = '\Bitrix\Main\UserTable';
147 if (Loader::includeModule('intranet'))
148 {
149 $getListClassName = '\Bitrix\Intranet\UserTable';
150 $select[] = 'USER_TYPE';
151 }
152 $getListMethodName = 'getList';
153
154 $res = $getListClassName::$getListMethodName(array(
155 'filter' => array(
156 '@ID' => $userIdList
157 ),
158 'select' => $select
159 ));
160
161 while ($userFields = $res->fetch())
162 {
163 $result[$userFields["ID"]] = array(
164 'ID' => $userFields["ID"],
165 'NAME_FORMATTED' => \CUser::formatName(
166 \CSite::getNameFormat(false),
167 $userFields,
168 true
169 ),
170 'PERSONAL_PHOTO' => array(
171 'ID' => $userFields['PERSONAL_PHOTO'],
172 'SRC' => false
173 ),
174 'PERSONAL_GENDER' => $userFields['PERSONAL_GENDER'],
175 'URL' => \CComponentEngine::makePathFromTemplate($params['pathToUser'], array('user_id' => $userFields['ID'])),
176 'TYPE' => (!empty($userFields['USER_TYPE']) ? $userFields['USER_TYPE'] : '')
177 );
178
179 if ((int)$userFields['PERSONAL_PHOTO'] > 0)
180 {
181 $imageFile = \CFile::getFileArray($userFields["PERSONAL_PHOTO"]);
182 if ($imageFile !== false)
183 {
184 $file = \CFile::resizeImageGet(
185 $imageFile,
186 array("width" => $avatarSize, "height" => $avatarSize),
187 BX_RESIZE_IMAGE_EXACT,
188 false
189 );
190 $result[$userFields["ID"]]['PERSONAL_PHOTO']['SRC'] = $file['src'];
191 }
192 }
193 }
194
195 return $result;
196 }
197}