1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
AttachedVote.php
См. документацию.
1<?php
2
4
22
24{
25 private const ENTITY_IDS_LIMIT = 50;
26 private AttachedVoteFrontendFormatService $formatService;
27 private VoteChangesSender $changesSender;
28
29 public function __construct(Request $request = null)
30 {
31 $this->formatService = new AttachedVoteFrontendFormatService();
32 $this->changesSender = new VoteChangesSender();
33 parent::__construct($request);
34 }
35
36 public function configureActions(): array
37 {
38 return [
39 'download' => [
40 '-prefilters' => [
41 Csrf::class,
42 CheckAttachReadAccess::class,
43 ],
44 '+prefilters' => [new CheckAttachReadAccessWithSign()],
45 ],
46 'get' => [
47 '-prefilters' => [CheckAttachReadAccess::class],
48 '+prefilters' => [new CheckAttachReadAccessWithSign()],
49 ],
50 'getAnswerVoted' => [
51 '-prefilters' => [CheckAttachReadAccess::class],
52 '+prefilters' => [new CheckAttachReadAccessWithSign()],
53 ],
54 'getWithVoted' => [
55 '-prefilters' => [CheckAttachReadAccess::class],
56 '+prefilters' => [new CheckAttachReadAccessWithSign()],
57 ],
58 ];
59 }
60
61 protected function getDefaultPreFilters(): array
62 {
63 return array_merge(
64 parent::getDefaultPreFilters(),
65 [
66 new CloseSession(true),
68 ]
69 );
70 }
71
72 public function getAutoWiredParameters(): array
73 {
74 return [
76 AttachedVotePayload::class,
77 'attachPayload',
78 function(string $className, int $attachId): AttachedVotePayload
79 {
81 },
82 ),
84 AttachedVotePayload::class,
85 'attachPayload',
86 function(string $className, string $moduleId, string $entityType, int $entityId): AttachedVotePayload
87 {
89 }
90 ),
92 AttachedVotePayload::class,
93 'attachPayload',
94 function(string $className, string $signedAttachId): AttachedVotePayload
95 {
96 return AttachedVotePayload::makeBySignedAttachId($signedAttachId);
97 }
98 )
99 ];
100 }
101
102 public function getAction(AttachedVotePayload $attachPayload): array
103 {
104 $attach = $attachPayload->attach;
105 $this->changesSender->addUserWatch($this->getUserId(), $attach->getVoteId());
106
107 return [
108 'attach' => $this->formatService->format($attach, $this->getUserId()),
109 ];
110 }
111
112 public function voteAction(
113 AttachedVotePayload $attachPayload,
114 array $ballot,
115 string $actionUuid = '',
116 ): array
117 {
118 $attach = $attachPayload->attach;
119 $voted = $attach->voteFor(
120 [\Bitrix\Vote\Event::EVENT_FIELD_NAME => [$attach->getAttachId() => ['BALLOT' => $ballot]]],
121 $actionUuid,
122 );
123 if ($voted)
124 {
125 return [
126 'attach' => $this->formatService->format($attach, $this->getUserId()),
127 ];
128 }
129
130 $errors = $attach->getErrors()
131 ? $attach->getErrors()
132 : [new Error('VOTE_CONTROLLER_ATTACH_VOTE_DEFAULT_ERROR')]
133 ;
134 $this->addErrors($errors);
135
136 return [];
137 }
138
139 public function stopAction(AttachedVotePayload $attachPayload, string $actionUuid = ''): array
140 {
141 $attach = $attachPayload->attach;
142 $this->throwAccessDeniedIfNotAbleToEdit($attach);
143 $attach->stop($actionUuid);
144
145 return [];
146 }
147
148 public function resumeAction(AttachedVotePayload $attachPayload, string $actionUuid = ''): array
149 {
150 $attach = $attachPayload->attach;
151 $this->throwAccessDeniedIfNotAbleToEdit($attach);
152 $attach->resume($actionUuid);
153
154 return [];
155 }
156
157 public function getAnswerVotedAction(
158 AttachedVotePayload $attachPayload,
159 int $answerId,
160 PageNavigation $pageNavigation,
161 bool $userForMobileFormat = false,
162 ): Page
163 {
164 $attach = $attachPayload->attach;
165 $this->throwAccessDeniedIfAnswerNotBelongsAttachedVote($attach, $answerId);
166
167 $votedService = new VotedCollectorService($userForMobileFormat);
168 $votedUserPage = $votedService->getByAnswerId($answerId, $pageNavigation->getPageSize(), $pageNavigation->getCurrentPage());
169
170 return new Page('items', $votedUserPage->items, $votedUserPage->totalCount);
171 }
172
173 public function recallAction(AttachedVotePayload $attachPayload, string $actionUuid = ''): array
174 {
175 $attach = $attachPayload->attach;
176 if (!$attach->canRead($this->getUserId()))
177 {
178 $this->addError(new Error('Attach read access denied', 'ATTACH_READ_ACCESS_DENIED'));
179
180 return [];
181 }
182
183 $result = $attach->recall($this->getUserId(), $actionUuid);
184 if ($result->isSuccess())
185 {
186 return [
187 'attach' => $this->formatService->format($attach, $this->getUserId()),
188 ];
189 }
190
191 $this->addErrors($result->getErrors());
192
193 return [];
194 }
195
196 public function downloadAction(AttachedVotePayload $attachPayload): void
197 {
198 $attach = $attachPayload->attach;
199 $attach->exportExcel();
200 }
201
202 public function getWithVotedAction(
203 AttachedVotePayload $attachPayload,
204 int $pageSize = 10,
205 bool $userForMobileFormat = false,
206 ): array
207 {
208 $attach = $attachPayload->attach;
209 $votedService = new VotedCollectorService($userForMobileFormat);
210 $this->changesSender->addUserWatch($this->getUserId(), $attach->getVoteId());
211
212 return [
213 'attach' => $this->formatService->format($attach, $this->getUserId()),
214 'voted' => $votedService->getByAttach($attach, $pageSize),
215 ];
216 }
217
218 public function getManyAction(string $moduleId, string $entityType, array $entityIds): array
219 {
220 $entityIds = array_filter(array_map(fn($value) => (int)$value, $entityIds));
221 if (count($entityIds) > self::ENTITY_IDS_LIMIT)
222 {
223 $this->addError(new Error('To many entity ids'));
224
225 return [];
226 }
227
228 $userId = $this->getUserId();
229 $formatted = [];
230 foreach ($entityIds as $entityId)
231 {
232 $attach = Manager::loadFirstFromEntity($moduleId, $entityType, $entityId);
233 if (!$attach)
234 {
235 $this->addError(new Error("Attach with entityId $entityId not found "));
236
237 return [];
238 }
239
240 if (!$attach->canRead($userId))
241 {
242 $this->addError(new Error("Attach with entityId $entityId read access denied"));
243
244 return [];
245 }
246
247 $formatted[] = $this->formatService->format($attach, $userId);
248 $this->changesSender->addUserWatch($this->getUserId(), $attach->getVoteId());
249 }
250
251 return [
252 'items' => $formatted,
253 ];
254 }
255
256 private function throwAccessDeniedIfNotAbleToEdit(Attach $attach): void
257 {
258 if (!$attach->canEdit($this->getUserId()))
259 {
260 throw new AccessDeniedException();
261 }
262 }
263
264 private function getUserId(): int
265 {
266 return (int)$this->getCurrentUser()?->getId();
267 }
268
269 private function throwAccessDeniedIfAnswerNotBelongsAttachedVote(Attach $attach, int $answerId): void
270 {
271 if (!$this->isAnswerBelongsToAttachedVote($attach, $answerId))
272 {
273 throw new AccessDeniedException();
274 }
275 }
276
277 private function isAnswerBelongsToAttachedVote(Attach $attach, int $answerId): bool
278 {
279 foreach ($attach["QUESTIONS"] ?? [] as $question)
280 {
281 if (array_key_exists($answerId, $question["ANSWERS"]))
282 {
283 return true;
284 }
285 }
286
287 return false;
288 }
289
290 protected function writeToLogException(\Throwable $e): void
291 {
292 if ($e instanceof AccessDeniedException)
293 {
294 return; // do not write to error log access denied errors
295 }
296
297 parent::writeToLogException($e);
298 }
299}
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
Определения error.php:15
Определения request.php:10
Определения attach.php:180
canEdit($userId)
Определения attach.php:520
static loadFirstFromEntity(string $moduleId, string $entityType, int $entityId)
Определения manager.php:103
getAction(AttachedVotePayload $attachPayload)
Определения AttachedVote.php:102
getAnswerVotedAction(AttachedVotePayload $attachPayload, int $answerId, PageNavigation $pageNavigation, bool $userForMobileFormat=false,)
Определения AttachedVote.php:157
__construct(Request $request=null)
Определения AttachedVote.php:29
getManyAction(string $moduleId, string $entityType, array $entityIds)
Определения AttachedVote.php:218
getWithVotedAction(AttachedVotePayload $attachPayload, int $pageSize=10, bool $userForMobileFormat=false,)
Определения AttachedVote.php:202
stopAction(AttachedVotePayload $attachPayload, string $actionUuid='')
Определения AttachedVote.php:139
resumeAction(AttachedVotePayload $attachPayload, string $actionUuid='')
Определения AttachedVote.php:148
voteAction(AttachedVotePayload $attachPayload, array $ballot, string $actionUuid='',)
Определения AttachedVote.php:112
recallAction(AttachedVotePayload $attachPayload, string $actionUuid='')
Определения AttachedVote.php:173
downloadAction(AttachedVotePayload $attachPayload)
Определения AttachedVote.php:196
writeToLogException(\Throwable $e)
Определения AttachedVote.php:290
const EVENT_FIELD_NAME
Определения event.php:207
static makeByAttachId(int $attachId)
Определения AttachedVotePayload.php:20
static makeBySignedAttachId(string $signedAttachId)
Определения AttachedVotePayload.php:43
static makeByEntityId(string $moduleId, string $entityType, int $entityId)
Определения AttachedVotePayload.php:34
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$moduleId
$errors
Определения iblock_catalog_edit.php:74
$pageSize
Определения csv_new_run.php:34
Определения anonymity.php:8
$entityId
Определения payment.php:4
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936