Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
rest.php
1
<?php
8
namespace
Bitrix\Main\UserConsent
;
9
10
use
Bitrix\Main\Error
;
11
use
Bitrix\Rest\RestException
;
12
17
class
Rest
18
{
27
public
static
function
getAgreementList
($query, $nav = 0, \CRestServer $server)
28
{
29
return
Internals\AgreementTable::getList(array(
30
'select'
=> array(
'ID'
,
'NAME'
,
'ACTIVE'
,
'LANGUAGE_ID'
),
31
'order'
=> array(
'ID'
=>
'DESC'
)
32
))->fetchAll();
33
}
34
44
public
static
function
getAgreementText
($query, $nav = 0, \CRestServer $server)
45
{
46
$query = array_change_key_case($query, CASE_LOWER);
47
$id = empty($query[
'id'
]) ? null : $query[
'id'
];
48
$replace = empty($query[
'replace'
]) ? [] : $query[
'replace'
];
49
$replace = is_array($replace) ? $replace : [];
50
51
$agreement = self::getAgreementById($id);
52
$agreement->setReplace($replace);
53
54
return
[
55
'LABEL'
=> $agreement->getLabelText(),
56
'TEXT'
=> $agreement->getText(),
57
];
58
}
59
69
public
static
function
addConsent
($query, $nav = 0, \CRestServer $server)
70
{
71
$query = array_change_key_case($query, CASE_UPPER);
72
$agreementId = $query[
'AGREEMENT_ID'
] ??
null
;
73
self::getAgreementById($agreementId);
74
75
$result = Internals\ConsentTable::add([
76
'AGREEMENT_ID'
=> $agreementId,
77
'USER_ID'
=> $query[
'USER_ID'
] ??
null
,
78
'IP'
=> $query[
'IP'
] ??
null
,
79
'URL'
=> $query[
'URL'
] ??
null
,
80
'ORIGIN_ID'
=> $query[
'ORIGIN_ID'
] ??
null
,
81
'ORIGINATOR_ID'
=> $query[
'ORIGINATOR_ID'
] ??
null
,
82
]);
83
84
if
(!$result->isSuccess())
85
{
86
self::printErrors($result->getErrors());
87
}
88
89
return
$result->getId();
90
}
91
99
protected
static
function
getAgreementById
($id)
100
{
101
$agreement =
new
Agreement
($id);
102
if
($agreement->hasErrors())
103
{
104
self::printErrors($agreement->getErrors());
105
}
106
107
return
$agreement;
108
}
109
116
protected
static
function
printErrors
(array $errors)
117
{
118
foreach
($errors as $error)
119
{
120
throw
new
RestException
(
121
$error->getMessage(),
122
RestException::ERROR_ARGUMENT,
123
\CRestServer::STATUS_WRONG_REQUEST
124
);
125
}
126
}
127
}
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\UserConsent\Agreement
Definition
agreement.php:25
Bitrix\Main\UserConsent\Rest
Definition
rest.php:18
Bitrix\Main\UserConsent\Rest\getAgreementList
static getAgreementList($query, $nav=0, \CRestServer $server)
Definition
rest.php:27
Bitrix\Main\UserConsent\Rest\getAgreementById
static getAgreementById($id)
Definition
rest.php:99
Bitrix\Main\UserConsent\Rest\addConsent
static addConsent($query, $nav=0, \CRestServer $server)
Definition
rest.php:69
Bitrix\Main\UserConsent\Rest\printErrors
static printErrors(array $errors)
Definition
rest.php:116
Bitrix\Main\UserConsent\Rest\getAgreementText
static getAgreementText($query, $nav=0, \CRestServer $server)
Definition
rest.php:44
Bitrix\Rest\RestException
Definition
restexception.php:6
Bitrix\Main\UserConsent
Definition
agreement.php:8
modules
main
lib
userconsent
rest.php
Создано системой
1.10.0