35 $signedKey = (string) ($params[
'RATING_VOTE_KEY_SIGNED'] ??
'');
36 $entityId = (int) ($params[
'RATING_VOTE_ENTITY_ID'] ?? 0);
37 $entityTypeId = (string) ($params[
'RATING_VOTE_TYPE_ID'] ??
'');
39 $payloadValue = $entityTypeId .
'-' . $entityId;
41 $signer = new \Bitrix\Main\Security\Sign\TimeSigner();
44 || $signer->unsign($signedKey,
'main.rating.vote') !== $payloadValue
52 $key = self::LOCK_KEY_PREFIX.$this->getCurrentUser()->getId();
56 $this->
addError(
new Main\
Error(
'Request already exists',
'ERR_PARAMS'));
60 $action = (string)($params[
'RATING_VOTE_ACTION'] ??
'');
61 $reaction = (string)($params[
'RATING_VOTE_REACTION'] ??
'');
68 $this->
addError(
new Main\
Error(
'Incorrect data',
'ERR_PARAMS'));
73 'ENTITY_TYPE_ID' => $entityTypeId,
74 'ENTITY_ID' => $entityId,
75 'ACTION' => (in_array($action, [
'plus',
'minus',
'change',
'cancel' ]) ? $action :
'list'),
76 'REACTION' => $reaction,
77 'RATING_RESULT' =>
'N',
78 'REMOTE_ADDR' => $_SERVER[
'REMOTE_ADDR'],
80 'CHECK_RIGHTS' =>
'Y',
83 $ratingVoteResult = \CRatings::getRatingVoteResult($ratingParams[
'ENTITY_TYPE_ID'], $ratingParams[
'ENTITY_ID']);
84 if (!empty($ratingVoteResult))
86 $ratingParams[
'TOTAL_VALUE'] = $ratingVoteResult[
'TOTAL_VALUE'];
87 $ratingParams[
'TOTAL_VOTES'] = $ratingVoteResult[
'TOTAL_VOTES'];
88 $ratingParams[
'TOTAL_POSITIVE_VOTES'] = $ratingVoteResult[
'TOTAL_POSITIVE_VOTES'];
89 $ratingParams[
'TOTAL_NEGATIVE_VOTES'] = $ratingVoteResult[
'TOTAL_NEGATIVE_VOTES'];
90 $ratingParams[
'USER_HAS_VOTED'] = $ratingVoteResult[
'USER_HAS_VOTED'];
91 $ratingParams[
'USER_VOTE'] = $ratingVoteResult[
'USER_VOTE'];
95 $ratingParams[
'TOTAL_VALUE'] = 0;
96 $ratingParams[
'TOTAL_VOTES'] = 0;
97 $ratingParams[
'TOTAL_POSITIVE_VOTES'] = 0;
98 $ratingParams[
'TOTAL_NEGATIVE_VOTES'] = 0;
99 $ratingParams[
'USER_HAS_VOTED'] =
'N';
100 $ratingParams[
'USER_VOTE'] =
'0';
103 $voteList = Action::vote($ratingParams);
104 if (empty($voteList))
106 $this->
addError(
new Main\
Error(
'Cannot do vote',
'CANNOT_VOTE'));
116 $signedKey = (string) ($params[
'RATING_VOTE_KEY_SIGNED'] ??
'');
117 $entityId = (int) ($params[
'RATING_VOTE_ENTITY_ID'] ?? 0);
118 $entityTypeId = (string) ($params[
'RATING_VOTE_TYPE_ID'] ??
'');
120 $payloadValue = $entityTypeId .
'-' . $entityId;
122 $signer = new \Bitrix\Main\Security\Sign\TimeSigner();
125 || $signer->unsign($signedKey,
'main.rating.vote') !== $payloadValue
133 $page = (int)($params[
'RATING_VOTE_LIST_PAGE'] ?? 1);
135 isset($params[
'RATING_VOTE_LIST_TYPE'])
136 && $params[
'RATING_VOTE_LIST_TYPE'] ===
'minus'
140 $reaction = (string)($params[
'RATING_VOTE_REACTION'] ??
'');
141 $pathToUserProfile = (string)($params[
'PATH_TO_USER_PROFILE'] ??
'/people/user/#USER_ID#/');
148 $this->
addError(
new Main\
Error(
'Incorrect data',
'ERR_PARAMS'));
152 return Action::list([
153 'ENTITY_TYPE_ID' => $entityTypeId,
154 'ENTITY_ID' => $entityId,
155 'LIST_PAGE' => $page,
157 'REACTION' => $reaction,
158 'LIST_TYPE' => $listType,
159 'PATH_TO_USER_PROFILE' => $pathToUserProfile,
161 'CHECK_RIGHTS' =>
'Y',