Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
vat.php
1
<?php
2
3
4
namespace
Bitrix\Catalog\Controller
;
5
6
7
use
Bitrix\Catalog\Access\ActionDictionary
;
8
use
Bitrix\Catalog\VatTable
;
9
use
Bitrix\Main\Engine\Response\DataType\Page
;
10
use
Bitrix\Main\Error
;
11
use
Bitrix\Main\Result
;
12
use
Bitrix\Main\UI\PageNavigation
;
13
use
Bitrix\Rest\Event\EventBindInterface
;
14
18
final
class
Vat
extends
Controller
19
{
20
//region Actions
21
26
public
function
addAction
(array $fields): ?array
27
{
28
$application =
self::getApplication
();
29
$application->ResetException();
30
31
$addResult = \CCatalogVat::Add($fields);
32
if
(!$addResult)
33
{
34
if
($application->GetException())
35
{
36
$this->addError(
new
Error
($application->GetException()->GetString()));
37
}
38
else
39
{
40
$this->addError(
new
Error
(
'Error adding VAT'
));
41
}
42
43
return
null
;
44
}
45
46
return
[
'VAT'
=> $this->
get
($addResult)];
47
}
48
54
public
function
updateAction
(
int
$id, array $fields): ?array
55
{
56
$existsResult = $this->
exists
($id);
57
if
(!$existsResult->isSuccess())
58
{
59
$this->addErrors($existsResult->getErrors());
60
61
return
null
;
62
}
63
64
$updateResult = \CCatalogVat::Update($id, $fields);
65
if
(!$updateResult)
66
{
67
$this->addError(
new
Error
(
'Error updating VAT'
));
68
69
return
null
;
70
}
71
72
return
[
'VAT'
=> $this->
get
($id)];
73
}
74
79
public
function
deleteAction
(
int
$id): ?bool
80
{
81
$existsResult = $this->
exists
($id);
82
if
(!$existsResult->isSuccess())
83
{
84
$this->addErrors($existsResult->getErrors());
85
86
return
null
;
87
}
88
89
$deleteResult = \CCatalogVat::Delete($id);
90
if
(!$deleteResult)
91
{
92
$this->addError(
new
Error
(
'Error deleting VAT'
));
93
94
return
null
;
95
}
96
97
return
true
;
98
}
99
103
public
function
getFieldsAction
(): array
104
{
105
return
[
'VAT'
=> $this->
getViewFields
()];
106
}
107
115
public
function
listAction
(
PageNavigation
$pageNavigation, array $select = [], array $filter = [], array $order = []):
Page
116
{
117
return
new
Page
(
118
'VATS'
,
119
$this->getList($select, $filter, $order, $pageNavigation),
120
$this->count($filter)
121
);
122
}
123
128
public
function
getAction
($id): ?array
129
{
130
$r = $this->
exists
($id);
131
if
($r->isSuccess())
132
{
133
return
[
'VAT'
=> $this->
get
($id)];
134
}
135
else
136
{
137
$this->addErrors($r->getErrors());
138
139
return
null
;
140
}
141
}
142
//endregion
143
147
protected
function
exists
($id)
148
{
149
$r =
new
Result
();
150
if
(!isset($this->
get
($id)[
'ID'
]))
151
{
152
$r->addError(
new
Error
(
'VAT does not exist'
));
153
}
154
155
return
$r;
156
}
157
161
protected
function
getEntityTable
()
162
{
163
return
new
VatTable
();
164
}
165
169
protected
function
checkModifyPermissionEntity
()
170
{
171
$r =
new
Result
();
172
173
if
(!$this->accessController->check(ActionDictionary::ACTION_VAT_EDIT))
174
{
175
$r->addError(
new
Error
(
'Access Denied'
, 200040300020));
176
}
177
178
return
$r;
179
}
180
184
protected
function
checkReadPermissionEntity
()
185
{
186
$r =
new
Result
();
187
188
if
(
189
!$this->accessController->check(ActionDictionary::ACTION_CATALOG_READ)
190
&& !$this->accessController->check(ActionDictionary::ACTION_VAT_EDIT)
191
)
192
{
193
$r->addError(
new
Error
(
'Access Denied'
, 200040300010));
194
}
195
196
return
$r;
197
}
198
}
Bitrix\Catalog\Access\ActionDictionary
Definition
ActionDictionary.php:17
Bitrix\Catalog\Controller\Controller\getApplication
static getApplication()
Definition
controller.php:55
Bitrix\Catalog\Controller\Controller\getViewFields
getViewFields()
Definition
controller.php:95
Bitrix\Catalog\Controller\Vat
Definition
vat.php:19
Bitrix\Catalog\Controller\Vat\checkModifyPermissionEntity
checkModifyPermissionEntity()
Definition
vat.php:169
Bitrix\Catalog\Controller\Vat\checkReadPermissionEntity
checkReadPermissionEntity()
Definition
vat.php:184
Bitrix\Catalog\Controller\Vat\exists
exists($id)
Definition
vat.php:147
Bitrix\Catalog\Controller\Vat\addAction
addAction(array $fields)
Definition
vat.php:26
Bitrix\Catalog\Controller\Vat\getEntityTable
getEntityTable()
Definition
vat.php:161
Bitrix\Catalog\Controller\Vat\getFieldsAction
getFieldsAction()
Definition
vat.php:103
Bitrix\Catalog\Controller\Vat\deleteAction
deleteAction(int $id)
Definition
vat.php:79
Bitrix\Catalog\Controller\Vat\updateAction
updateAction(int $id, array $fields)
Definition
vat.php:54
Bitrix\Catalog\Controller\Vat\listAction
listAction(PageNavigation $pageNavigation, array $select=[], array $filter=[], array $order=[])
Definition
vat.php:115
Bitrix\Catalog\Controller\Vat\getAction
getAction($id)
Definition
vat.php:128
Bitrix\Catalog\VatTable
Definition
vat.php:38
Bitrix\Main\DB\Result
Definition
result.php:19
Bitrix\Main\Engine\Response\DataType\Page
Definition
page.php:8
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\ORM\Data\Result
Definition
result.php:16
Bitrix\Main\UI\PageNavigation
Definition
pagenavigation.php:27
Bitrix\Rest\Event\EventBindInterface
Definition
eventbindinterface.php:12
Bitrix\Catalog\Controller
Bitrix\Sender\Internals\QueryController
Definition
action.php:8
modules
catalog
lib
controller
vat.php
Создано системой
1.10.0