Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
pricetypegroup.php
1
<?php
2
3
namespace
Bitrix\Catalog\Controller
;
4
5
use
Bitrix\Catalog\GroupAccessTable
;
6
use
Bitrix\Main\Engine\Response\DataType\Page
;
7
use
Bitrix\Main\Error
;
8
use
Bitrix\Main\GroupTable
;
9
use
Bitrix\Main\Result
;
10
use
Bitrix\Main\UI\PageNavigation
;
11
12
class
PriceTypeGroup
extends
Controller
13
{
14
use PriceTypeRights;
15
16
// region Actions
17
21
public
function
getFieldsAction
(): array
22
{
23
return
[
'PRICE_TYPE_GROUP'
=> $this->
getViewFields
()];
24
}
25
30
public
function
addAction
(array $fields): ?array
31
{
32
$checkFieldsResult = $this->checkFields($fields);
33
if
(!$checkFieldsResult->isSuccess())
34
{
35
$this->addErrors($checkFieldsResult->getErrors());
36
37
return
null
;
38
}
39
40
$addResult =
GroupAccessTable::add
($fields);
41
if
(!$addResult)
42
{
43
$this->addErrors($addResult->getErrors());
44
45
return
null
;
46
}
47
48
return
[
'PRICE_TYPE_GROUP'
=> $this->
get
($addResult->getId())];
49
}
50
58
public
function
listAction
(
PageNavigation
$pageNavigation, array $select = [], array $filter = [], array $order = []):
Page
59
{
60
return
new
Page
(
61
'PRICE_TYPE_GROUPS'
,
62
$this->getList($select, $filter, $order, $pageNavigation),
63
$this->count($filter)
64
);
65
}
66
71
public
function
deleteAction
(
int
$id): ?bool
72
{
73
$existsResult = $this->exists($id);
74
if
(!$existsResult->isSuccess())
75
{
76
$this->addErrors($existsResult->getErrors());
77
78
return
null
;
79
}
80
81
$deleteResult =
GroupAccessTable::delete
($id);
82
if
(!$deleteResult)
83
{
84
$this->addErrors($deleteResult->getErrors());
85
86
return
null
;
87
}
88
89
return
true
;
90
}
91
// endregion
92
97
private
function
checkFields(array $fields):
Result
98
{
99
$result =
new
Result
();
100
101
$priceTypeId = $fields[
'CATALOG_GROUP_ID'
];
102
$priceType = \Bitrix\Catalog\GroupTable::getById($priceTypeId)->fetch();
103
if
(!$priceType)
104
{
105
$result->addError(
new
Error
(
'The specified price type does not exist'
));
106
}
107
108
$groupId = $fields[
'GROUP_ID'
];
109
$group =
GroupTable::getById
($groupId)->fetch();
110
if
(!$group)
111
{
112
$result->addError(
new
Error
(
'The specified group does not exist'
));
113
}
114
115
$accessTypeValues = [
GroupAccessTable::ACCESS_BUY
,
GroupAccessTable::ACCESS_VIEW
];
116
$access = $fields[
'ACCESS'
];
117
if
(!in_array($access, $accessTypeValues,
true
))
118
{
119
$result->addError(
120
new
Error(
121
'Invalid access type provided. The available values are: '
122
. implode(
', '
, $accessTypeValues)
123
)
124
);
125
}
126
127
$exists = (bool)
GroupAccessTable::getRow
([
128
'select'
=> [
'ID'
],
129
'filter'
=> [
130
'=CATALOG_GROUP_ID'
=> $fields[
'CATALOG_GROUP_ID'
],
131
'=GROUP_ID'
=> $fields[
'GROUP_ID'
],
132
'=ACCESS'
=> $fields[
'ACCESS'
],
133
]
134
]);
135
136
if
($exists)
137
{
138
$result->addError(
new
Error(
'The specified access type for this group already exists'
));
139
}
140
141
return
$result;
142
}
143
147
protected
function
getEntityTable
()
148
{
149
return
GroupAccessTable::class;
150
}
151
}
Bitrix\Catalog\Controller\Controller\getViewFields
getViewFields()
Definition
controller.php:95
Bitrix\Catalog\Controller\PriceTypeGroup
Definition
pricetypegroup.php:13
Bitrix\Catalog\Controller\PriceTypeGroup\addAction
addAction(array $fields)
Definition
pricetypegroup.php:30
Bitrix\Catalog\Controller\PriceTypeGroup\getEntityTable
getEntityTable()
Definition
pricetypegroup.php:147
Bitrix\Catalog\Controller\PriceTypeGroup\getFieldsAction
getFieldsAction()
Definition
pricetypegroup.php:21
Bitrix\Catalog\Controller\PriceTypeGroup\deleteAction
deleteAction(int $id)
Definition
pricetypegroup.php:71
Bitrix\Catalog\Controller\PriceTypeGroup\listAction
listAction(PageNavigation $pageNavigation, array $select=[], array $filter=[], array $order=[])
Definition
pricetypegroup.php:58
Bitrix\Catalog\GroupAccessTable
Definition
groupaccess.php:37
Bitrix\Catalog\GroupAccessTable\ACCESS_BUY
const ACCESS_BUY
Definition
groupaccess.php:38
Bitrix\Catalog\GroupAccessTable\ACCESS_VIEW
const ACCESS_VIEW
Definition
groupaccess.php:39
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\GroupTable
Definition
group.php:29
Bitrix\Main\ORM\Data\DataManager\getRow
static getRow(array $parameters)
Definition
datamanager.php:410
Bitrix\Main\ORM\Data\DataManager\getById
static getById($id)
Definition
datamanager.php:377
Bitrix\Main\ORM\Data\DataManager\delete
static delete($primary)
Definition
datamanager.php:1632
Bitrix\Main\ORM\Data\DataManager\add
static add(array $data)
Definition
datamanager.php:874
Bitrix\Main\ORM\Data\Result
Definition
result.php:16
Bitrix\Main\UI\PageNavigation
Definition
pagenavigation.php:27
Bitrix\Catalog\Controller
Bitrix\Sender\Internals\QueryController
Definition
action.php:8
modules
catalog
lib
controller
pricetypegroup.php
Создано системой
1.10.0