Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
rating.php
1<?php
2namespace Bitrix\Main\Rest;
3
6
7if(Main\Loader::includeModule("rest")):
8
9class Rating extends \IRestService
10{
11 const LIST_LIMIT = 20;
12
13 public static function getLikeReactions($query, $nav = 0, \CRestServer $server)
14 {
15 $query = array_change_key_case($query, CASE_LOWER);
16
17 $entityTypeId = ($query['entity_type_id'] ?? '');
18 $entityId = (isset($query['entity_id']) ? intval($query['entity_id']) : 0);
19
20 if(
21 empty($entityTypeId)
22 || $entityId <= 0
23 )
24 {
25 throw new Rest\RestException("Wrong entity data.", Rest\RestException::ERROR_ARGUMENT, \CRestServer::STATUS_WRONG_REQUEST);
26 }
27
28 $reactionResult = \CRatings::getRatingVoteReaction(array(
29 "ENTITY_TYPE_ID" => $entityTypeId,
30 "ENTITY_ID" => $entityId,
31 "USE_REACTIONS_CACHE" => 'Y'
32 ));
33
34 return $reactionResult['reactions'];
35 }
36
37 public static function getLikeList($query, $nav = 0, \CRestServer $server)
38 {
39 global $USER;
40
41 $query = array_change_key_case($query, CASE_LOWER);
42 $navParams = static::getNavData($nav, true);
43
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;
49
50 if(
51 empty($entityTypeId)
52 || $entityId <= 0
53 )
54 {
55 throw new Rest\RestException("Wrong entity data.", Rest\RestException::ERROR_ARGUMENT, \CRestServer::STATUS_WRONG_REQUEST);
56 }
57
58 $queryParams = array(
59 "ENTITY_TYPE_ID" => $entityTypeId,
60 "ENTITY_ID" => $entityId,
61 "LIST_PAGE" => $page,
62 "LIST_LIMIT" => $navParams['limit'],
63 "LIST_TYPE" => 'plus',
64 "USE_REACTIONS_CACHE" => 'Y'
65 );
66
67 $extranetInstalled = $mailInstalled = false;
68 if (Main\ModuleManager::isModuleInstalled('extranet'))
69 {
70 $extranetInstalled = true;
71 $queryParams["USER_SELECT"] = array("UF_DEPARTMENT");
72 }
73 if (Main\ModuleManager::isModuleInstalled('mail'))
74 {
75 $mailInstalled = true;
76 $queryParams["USER_FIELDS"] = array("ID", "NAME", "LAST_NAME", "SECOND_NAME", "LOGIN", "PERSONAL_PHOTO", "EXTERNAL_AUTH_ID");
77 }
78
79 if (!empty($reaction))
80 {
81 $queryParams["REACTION"] = $reaction;
82 }
83
84 $res = \CRatings::getRatingVoteList($queryParams);
85
86 $voteList = array(
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'],
90 'items' => array()
91 );
92
93 foreach($res['items'] as $key => $value)
94 {
95 $userVote = array(
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"]
105 )))
106 );
107
108 if (
109 $mailInstalled
110 && $value["EXTERNAL_AUTH_ID"] == "email"
111 )
112 {
113 $userVote["USER_TYPE"] = "mail";
114 }
115 elseif (
116 $extranetInstalled
117 && (
118 empty($value["UF_DEPARTMENT"])
119 || intval($value["UF_DEPARTMENT"][0]) <= 0
120 )
121 )
122 {
123 $userVote["USER_TYPE"] = "extranet";
124 }
125
126 $voteList['items'][] = $userVote;
127 }
128
129 if (
130 $USER->isAuthorized()
131 && $page == 1
132 )
133 {
134 $event = new Main\Event(
135 'main',
136 'onRatingListViewed',
137 array(
138 'entityTypeId' => $entityTypeId,
139 'entityId' => $entityId,
140 'userId' => $USER->getId()
141 )
142 );
143 $event->send();
144 }
145
146 return static::setNavData($voteList['items'], array(
147 "count" => ($reaction && $reaction != 'all' ? $voteList['items_reaction'] : $voteList['items_all']),
148 "offset" => $navParams['offset']
149 ));
150 }
151}
152
static includeModule($moduleName)
Definition loader.php:69
static isModuleInstalled($moduleName)
if(Main\Loader::includeModule("rest")) endif
Definition rating.php:7