1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
rating.php
См. документацию.
1
<?php
2
9
10
namespace
Bitrix\Main\Controller;
11
12
use Bitrix\Main;
13
use Bitrix\Main\Application;
14
use Bitrix\Main\Rating\Internal\Action;
15
use Bitrix\Main\Security\Sign\BadSignatureException;
16
17
class
Rating
extends
Main\Engine\Controller
18
{
19
private
const
LOCK_KEY_PREFIX =
'rating.lock.'
;
20
21
public
function
configureActions
():
array
22
{
23
$configureActions = parent::configureActions();
24
25
$configureActions[
'list'
] = [
26
'-prefilters'
=> [
27
Main\Engine\ActionFilter\Authentication::class,
28
]
29
];
30
31
return
$configureActions;
32
}
33
34
public
function
voteAction
(
array
$params
= []): ?
array
35
{
36
$signedKey = (string) (
$params
[
'RATING_VOTE_KEY_SIGNED'
] ??
''
);
37
$entityId
= (int) (
$params
[
'RATING_VOTE_ENTITY_ID'
] ?? 0);
38
$entityTypeId = (string) (
$params
[
'RATING_VOTE_TYPE_ID'
] ??
''
);
39
40
$payloadValue = $entityTypeId .
'-'
.
$entityId
;
41
42
$signer = new \Bitrix\Main\Security\Sign\TimeSigner();
43
44
$accessDenied =
false
;
45
try
46
{
47
if
(
48
$signedKey ===
''
49
|| $signer->unsign($signedKey,
'main.rating.vote'
) !== $payloadValue
50
)
51
{
52
$accessDenied =
true
;
53
}
54
}
55
catch
(
BadSignatureException
$e)
56
{
57
$accessDenied =
true
;
58
}
59
60
if
($accessDenied)
61
{
62
$this->
addError
(
new
Main
\
Error
(
'Access denied'
));
63
64
return
null
;
65
}
66
67
$key
= self::LOCK_KEY_PREFIX.$this->getCurrentUser()->getId();
68
69
if
(!
Application::getConnection
()->lock(
$key
))
70
{
71
$this->
addError
(
new
Main
\
Error
(
'Request already exists'
,
'ERR_PARAMS'
));
72
return
null
;
73
}
74
75
$action
= (string)(
$params
[
'RATING_VOTE_ACTION'
] ??
''
);
76
$reaction = (string)(
$params
[
'RATING_VOTE_REACTION'
] ??
''
);
77
78
if
(
79
$entityTypeId ===
''
80
||
$entityId
<= 0
81
)
82
{
83
$this->
addError
(
new
Main
\
Error
(
'Incorrect data'
,
'ERR_PARAMS'
));
84
return
null
;
85
}
86
87
$ratingParams = [
88
'ENTITY_TYPE_ID'
=> $entityTypeId,
89
'ENTITY_ID'
=>
$entityId
,
90
'ACTION'
=> (in_array(
$action
, [
'plus'
,
'minus'
,
'change'
,
'cancel'
]) ?
$action
:
'list'
),
91
'REACTION'
=> $reaction,
92
'RATING_RESULT'
=>
'N'
,
93
'REMOTE_ADDR'
=>
$_SERVER
[
'REMOTE_ADDR'
],
94
'CURRENT_USER_ID'
=> $this->
getCurrentUser
()->getId(),
95
'CHECK_RIGHTS'
=>
'Y'
,
96
];
97
98
$ratingVoteResult = \CRatings::getRatingVoteResult($ratingParams[
'ENTITY_TYPE_ID'
], $ratingParams[
'ENTITY_ID'
]);
99
if
(!empty($ratingVoteResult))
100
{
101
$ratingParams[
'TOTAL_VALUE'
] = $ratingVoteResult[
'TOTAL_VALUE'
];
102
$ratingParams[
'TOTAL_VOTES'
] = $ratingVoteResult[
'TOTAL_VOTES'
];
103
$ratingParams[
'TOTAL_POSITIVE_VOTES'
] = $ratingVoteResult[
'TOTAL_POSITIVE_VOTES'
];
104
$ratingParams[
'TOTAL_NEGATIVE_VOTES'
] = $ratingVoteResult[
'TOTAL_NEGATIVE_VOTES'
];
105
$ratingParams[
'USER_HAS_VOTED'
] = $ratingVoteResult[
'USER_HAS_VOTED'
];
106
$ratingParams[
'USER_VOTE'
] = $ratingVoteResult[
'USER_VOTE'
];
107
}
108
else
109
{
110
$ratingParams[
'TOTAL_VALUE'
] = 0;
111
$ratingParams[
'TOTAL_VOTES'
] = 0;
112
$ratingParams[
'TOTAL_POSITIVE_VOTES'
] = 0;
113
$ratingParams[
'TOTAL_NEGATIVE_VOTES'
] = 0;
114
$ratingParams[
'USER_HAS_VOTED'
] =
'N'
;
115
$ratingParams[
'USER_VOTE'
] =
'0'
;
116
}
117
118
$voteList = Action::vote($ratingParams);
119
if
(empty($voteList))
120
{
121
$this->
addError
(
new
Main
\
Error
(
'Cannot do vote'
,
'CANNOT_VOTE'
));
122
}
123
124
Application::getConnection
()->unlock(
$key
);
125
126
return
$voteList;
127
}
128
129
public
function
listAction
(
array
$params
= []): ?
array
130
{
131
$signedKey = (string) (
$params
[
'RATING_VOTE_KEY_SIGNED'
] ??
''
);
132
$entityId
= (int) (
$params
[
'RATING_VOTE_ENTITY_ID'
] ?? 0);
133
$entityTypeId = (string) (
$params
[
'RATING_VOTE_TYPE_ID'
] ??
''
);
134
135
$payloadValue = $entityTypeId .
'-'
.
$entityId
;
136
137
$signer = new \Bitrix\Main\Security\Sign\TimeSigner();
138
139
$accessDenied =
false
;
140
try
141
{
142
if
(
143
$signedKey ===
''
144
|| $signer->unsign($signedKey,
'main.rating.vote'
) !== $payloadValue
145
)
146
{
147
$accessDenied =
true
;
148
}
149
}
150
catch
(
BadSignatureException
$e)
151
{
152
$accessDenied =
true
;
153
}
154
155
if
($accessDenied)
156
{
157
$this->
addError
(
new
Main
\
Error
(
'Access denied'
));
158
159
return
null
;
160
}
161
162
$page
= (int)(
$params
[
'RATING_VOTE_LIST_PAGE'
] ?? 1);
163
$listType = (
164
isset(
$params
[
'RATING_VOTE_LIST_TYPE'
])
165
&&
$params
[
'RATING_VOTE_LIST_TYPE'
] ===
'minus'
166
?
'minus'
167
:
'plus'
168
);
169
$reaction = (string)(
$params
[
'RATING_VOTE_REACTION'
] ??
''
);
170
$pathToUserProfile
= (string)(
$params
[
'PATH_TO_USER_PROFILE'
] ??
'/people/user/#USER_ID#/'
);
171
172
if
(
173
$entityTypeId ===
''
174
||
$entityId
<= 0
175
)
176
{
177
$this->
addError
(
new
Main
\
Error
(
'Incorrect data'
,
'ERR_PARAMS'
));
178
return
null
;
179
}
180
181
return
Action::list([
182
'ENTITY_TYPE_ID'
=> $entityTypeId,
183
'ENTITY_ID'
=>
$entityId
,
184
'LIST_PAGE'
=>
$page
,
185
'LIST_LIMIT'
=> 20,
186
'REACTION'
=> $reaction,
187
'LIST_TYPE'
=> $listType,
188
'PATH_TO_USER_PROFILE'
=>
$pathToUserProfile
,
189
'CURRENT_USER_ID'
=> $this->
getCurrentUser
()->getId(),
190
'CHECK_RIGHTS'
=>
'Y'
,
191
]);
192
}
193
}
Bitrix\Main\Application\getConnection
static getConnection($name="")
Определения
application.php:638
Bitrix\Main\Controller\Rating\configureActions
configureActions()
Определения
rating.php:21
Bitrix\Main\Controller\Rating\voteAction
voteAction(array $params=[])
Определения
rating.php:34
Bitrix\Main\Controller\Rating\listAction
listAction(array $params=[])
Определения
rating.php:129
Bitrix\Main\Engine\Controller\addError
addError(Error $error)
Определения
controller.php:1070
Bitrix\Main\Engine\Controller\getCurrentUser
getCurrentUser()
Определения
controller.php:268
Bitrix\Main\Error
Определения
error.php:15
Bitrix\Main\Security\Sign\BadSignatureException
Определения
badsignatureexception.php:13
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$_SERVER
$_SERVER["DOCUMENT_ROOT"]
Определения
cron_frame.php:9
Bitrix\Main\Controller
Определения
agreement.php:2
Bitrix\Main\Rating
Bitrix\Main
$entityId
$entityId
Определения
payment.php:4
$key
if(empty($signedUserToken)) $key
Определения
quickway.php:257
$page
$page
Определения
order_form.php:33
$params
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения
template.php:799
$pathToUserProfile
$pathToUserProfile
Определения
sonet_set_content_view.php:30
$action
$action
Определения
file_dialog.php:21
bitrix
modules
main
lib
controller
rating.php
Создано системой
1.14.0