Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
pricetypegroup.php
1<?php
2
4
11
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
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}
listAction(PageNavigation $pageNavigation, array $select=[], array $filter=[], array $order=[])
static getRow(array $parameters)