151 !empty($params[
'userId'])
152 ? intval($params[
'userId'])
157 isset($params[
'topCount'])
158 ? intval($params[
'topCount'])
173 isset($params[
'avatarSize'])
174 ? intval($params[
'avatarSize'])
178 $connection = \Bitrix\Main\Application::getConnection();
179 $connection->queryExecute(
'SET @user_rank = 0');
180 $connection->queryExecute(
'SET @current_entity_id = 0');
182 $params[
'tagName'] = $params[
'tagName'] ??
null;
185 (is_array($params[
'tagName']) && !empty($params[
'tagName']))
186 || (!is_array($params[
'tagName']) && $params[
'tagName'] <>
'')
193 ? (is_array($tagName)) ?
" NAME IN (".implode(
',', array_map(
function($val) use ($DB) {
return "'".$DB->forSql($val).
"'"; }, $tagName)).
")" :
" NAME = '".$DB->forSql($tagName).
"'"
194 : ($userId ?
" USER_ID = ".$userId :
"")
197 $whereClause = (!empty($nameFilter) ?
'WHERE '.$nameFilter :
'');
199 $tagsSql =
'SELECT NAME FROM '.self::getTableName().
' '.$whereClause;
201 if (\
Bitrix\Main\ModuleManager::isModuleInstalled(
'intranet'))
203 $ratingId = \CRatings::getAuthorityRating();
204 if (intval($ratingId) <= 0)
209 $res = $connection->query(
"SELECT /*+ NO_DERIVED_CONDITION_PUSHDOWN() */
211 @current_name = tmp.NAME,
215 @current_name := tmp.NAME,
216 tmp.USER_ID as USER_ID,
220 SELECT /*+ NO_DERIVED_CONDITION_PUSHDOWN() */
221 @rownum := @rownum + 1 as ROWNUM,
222 RS1.ENTITY_ID as USER_ID,
224 MAX(RS1.VOTES) as WEIGHT
226 b_rating_subordinate RS1,
227 ".self::getTableName().
" UT1
228 INNER JOIN b_user U ON U.ID = UT1.USER_ID
230 RS1.RATING_ID = ".intval($ratingId).
"
231 AND RS1.ENTITY_ID = UT1.USER_ID
232 AND UT1.NAME IN (".$tagsSql.
")
235 UT1.NAME, RS1.ENTITY_ID
243 $res = $connection->query(
"SELECT /*+ NO_DERIVED_CONDITION_PUSHDOWN() */
245 @current_name = tmp.NAME,
249 tmp.USER_ID as USER_ID,
253 SELECT /*+ NO_DERIVED_CONDITION_PUSHDOWN() */
254 @rownum := @rownum + 1 as ROWNUM,
255 UT1.USER_ID as USER_ID,
258 ".self::getTableName().
" UT1
259 INNER JOIN b_user U ON U.ID = UT1.USER_ID
261 UT1.NAME IN (".$tagsSql.
")
268 $userWeightData = $tagUserData = array();
270 $currentTagName =
false;
273 while ($resultFields = $res->fetch())
277 && $resultFields[
'USER_ID'] == $USER->getId()
283 if ($resultFields[
'NAME'] != $currentTagName)
287 $tagUserData[$resultFields[
'NAME']] = array();
290 $currentTagName = $resultFields[
'NAME'];
293 if ($cnt > ($hasMine ? $topCount+1 : $topCount))
298 $tagUserData[$resultFields[
'NAME']][] = $resultFields[
'USER_ID'];
299 if (!isset($userWeightData[$resultFields[
'USER_ID']]))
301 $userWeightData[$resultFields[
'USER_ID']] = floatval($resultFields[
'WEIGHT']);
305 $userData = \Bitrix\Socialnetwork\Item\UserTag::getUserData([
306 'userIdList' => array_keys($userWeightData),
307 'avatarSize' => $avatarSize
310 foreach($tagUserData as $tagName => $userIdList)
312 $result[$tagName] = array();
314 foreach($userIdList as $userId)
316 $result[$tagName][] = array(
318 'NAME_FORMATTED' => $userData[$userId][
'NAME_FORMATTED'],
319 'PERSONAL_PHOTO' => $userData[$userId][
'PERSONAL_PHOTO'][
'ID'],
320 'PERSONAL_PHOTO_SRC' => $userData[$userId][
'PERSONAL_PHOTO'][
'SRC'],
321 'PERSONAL_GENDER' => $userData[$userId][
'PERSONAL_GENDER'],
322 'WEIGHT' => $userWeightData[$userId]
327 foreach($result as $tagName => $data)
333 if ($a[
'WEIGHT'] == $b[
'WEIGHT'])
337 return ($a[
'WEIGHT'] > $b[
'WEIGHT']) ? -1 : 1;
340 $result[$tagName] = $data;