9class Rating
extends \IRestService
11 const LIST_LIMIT = 20;
13 public static function getLikeReactions($query, $nav = 0, \CRestServer $server)
15 $query = array_change_key_case($query, CASE_LOWER);
17 $entityTypeId = ($query[
'entity_type_id'] ??
'');
18 $entityId = (isset($query[
'entity_id']) ? intval($query[
'entity_id']) : 0);
25 throw new Rest\RestException(
"Wrong entity data.", Rest\RestException::ERROR_ARGUMENT, \CRestServer::STATUS_WRONG_REQUEST);
28 $reactionResult = \CRatings::getRatingVoteReaction(array(
29 "ENTITY_TYPE_ID" => $entityTypeId,
30 "ENTITY_ID" => $entityId,
31 "USE_REACTIONS_CACHE" =>
'Y'
34 return $reactionResult[
'reactions'];
37 public static function getLikeList($query, $nav = 0, \CRestServer $server)
41 $query = array_change_key_case($query, CASE_LOWER);
42 $navParams = static::getNavData($nav,
true);
44 $pathToUserProfile = ($query[
'path_to_user_profile'] ??
'');
45 $entityTypeId = ($query[
'entity_type_id'] ??
'');
46 $entityId = (isset($query[
'entity_id']) ? intval($query[
'entity_id']) : 0);
47 $reaction = ($query[
'reaction'] ??
false);
48 $page = ($navParams[
'offset'] / $navParams[
'limit']) + 1;
55 throw new Rest\RestException(
"Wrong entity data.", Rest\RestException::ERROR_ARGUMENT, \CRestServer::STATUS_WRONG_REQUEST);
59 "ENTITY_TYPE_ID" => $entityTypeId,
60 "ENTITY_ID" => $entityId,
62 "LIST_LIMIT" => $navParams[
'limit'],
63 "LIST_TYPE" =>
'plus',
64 "USE_REACTIONS_CACHE" =>
'Y'
67 $extranetInstalled = $mailInstalled =
false;
70 $extranetInstalled =
true;
71 $queryParams[
"USER_SELECT"] = array(
"UF_DEPARTMENT");
75 $mailInstalled =
true;
76 $queryParams[
"USER_FIELDS"] = array(
"ID",
"NAME",
"LAST_NAME",
"SECOND_NAME",
"LOGIN",
"PERSONAL_PHOTO",
"EXTERNAL_AUTH_ID");
79 if (!empty($reaction))
81 $queryParams[
"REACTION"] = $reaction;
84 $res = \CRatings::getRatingVoteList($queryParams);
87 'items_all' => $res[
'items_all'],
88 'items_reaction' => ($reaction && isset($res[
'reactions']) && isset($res[
'reactions'][$reaction]) ? intval($res[
'reactions'][$reaction]) : 0),
89 'items_page' => $res[
'items_page'],
93 foreach($res[
'items'] as $key => $value)
96 'USER_ID' => $value[
'ID'],
97 'VOTE_VALUE' => $value[
'VOTE_VALUE'],
98 'PHOTO' => $value[
'PHOTO'],
99 'PHOTO_SRC' => $value[
'PHOTO_SRC'],
100 'FULL_NAME' => $value[
'FULL_NAME'],
101 'URL' => \CUtil::jSEscape(\CComponentEngine::makePathFromTemplate($pathToUserProfile, array(
102 "UID" => $value[
"USER_ID"],
103 "user_id" => $value[
"USER_ID"],
104 "USER_ID" => $value[
"USER_ID"]
110 && $value[
"EXTERNAL_AUTH_ID"] ==
"email"
113 $userVote[
"USER_TYPE"] =
"mail";
118 empty($value[
"UF_DEPARTMENT"])
119 || intval($value[
"UF_DEPARTMENT"][0]) <= 0
123 $userVote[
"USER_TYPE"] =
"extranet";
126 $voteList[
'items'][] = $userVote;
130 $USER->isAuthorized()
134 $event =
new Main\Event(
136 'onRatingListViewed',
138 'entityTypeId' => $entityTypeId,
139 'entityId' => $entityId,
140 'userId' => $USER->getId()
146 return static::setNavData($voteList[
'items'], array(
147 "count" => ($reaction && $reaction !=
'all' ? $voteList[
'items_reaction'] : $voteList[
'items_all']),
148 "offset" => $navParams[
'offset']
static includeModule($moduleName)
static isModuleInstalled($moduleName)
if(Main\Loader::includeModule("rest")) endif