Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
agreement.php
1<?php
3
10
12{
13 public function configureActions()
14 {
15 return [
16 'get' => [
17 '-prefilters' => [
19 Engine\ActionFilter\Csrf::class,
20 ],
21 ],
22 ];
23 }
24
25 public function getAction(int $id, string $sec, array $replace): array
26 {
27 $agreement = $this->getAgreement($id, $sec);
28 if (!$agreement)
29 {
30 return [];
31 }
32
33 $agreement->setReplace($replace);
34
35 $result = [
36 'id' => $agreement->getId(),
37 'title' => $agreement->getTitle(),
38 'label' => $agreement->getLabel(),
39 'url' => $agreement->getUrl(),
40 'content' => [
41 'text' => $agreement->getText(),
42 'html' => $agreement->getHtml(),
43 ],
44 ];
45
46 return $result;
47 }
48
49 private function getAgreement(int $id, string $sec): ?UserConsent\Agreement
50 {
51 $agreement = new UserConsent\Agreement($id);
52 if (!$agreement->isExist() || !$agreement->isActive())
53 {
54 $this->addError(new Error('Agreement not found'));
55 return null;
56 }
57
58 $secStored = $agreement->getData()['SECURITY_CODE'] ?? '';
59 if ($secStored && $sec !== $secStored)
60 {
61 $this->addError(new Error('Wrong security code'));
62 return null;
63 }
64
65 return $agreement;
66 }
67}
68
getAction(int $id, string $sec, array $replace)
Definition agreement.php:25