1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
pricetypegroup.php
См. документацию.
1<?php
2
3namespace Bitrix\Catalog\Controller;
4
5use Bitrix\Catalog\GroupAccessTable;
6use Bitrix\Main\Error;
7use Bitrix\Main\GroupTable;
8use Bitrix\Main\Result;
9
11{
12 use ListAction; // default listAction realization
13 use PriceTypeRights;
14
15 // region Actions
16
20 public function getFieldsAction(): array
21 {
22 return [$this->getServiceItemName() => $this->getViewFields()];
23 }
24
29 public function addAction(array $fields): ?array
30 {
31 $checkFieldsResult = $this->checkFields($fields);
32 if (!$checkFieldsResult->isSuccess())
33 {
34 $this->addErrors($checkFieldsResult->getErrors());
35
36 return null;
37 }
38
39 $addResult = GroupAccessTable::add($fields);
40 if (!$addResult)
41 {
42 $this->addErrors($addResult->getErrors());
43
44 return null;
45 }
46
47 return [$this->getServiceItemName() => $this->get($addResult->getId())];
48 }
49
54
59 public function deleteAction(int $id): ?bool
60 {
61 $existsResult = $this->exists($id);
62 if (!$existsResult->isSuccess())
63 {
64 $this->addErrors($existsResult->getErrors());
65
66 return null;
67 }
68
69 $deleteResult = GroupAccessTable::delete($id);
70 if (!$deleteResult)
71 {
72 $this->addErrors($deleteResult->getErrors());
73
74 return null;
75 }
76
77 return true;
78 }
79 // endregion
80
85 private function checkFields(array $fields): Result
86 {
87 $result = new Result();
88
89 $priceTypeId = $fields['CATALOG_GROUP_ID'];
90 $priceType = \Bitrix\Catalog\GroupTable::getById($priceTypeId)->fetch();
91 if (!$priceType)
92 {
93 $result->addError(new Error('The specified price type does not exist'));
94 }
95
96 $groupId = $fields['GROUP_ID'];
97 $group = GroupTable::getById($groupId)->fetch();
98 if (!$group)
99 {
100 $result->addError(new Error('The specified group does not exist'));
101 }
102
104 $access = $fields['ACCESS'];
105 if (!in_array($access, $accessTypeValues, true))
106 {
107 $result->addError(
108 new Error(
109 'Invalid access type provided. The available values are: '
110 . implode(', ', $accessTypeValues)
111 )
112 );
113 }
114
115 $exists = (bool)GroupAccessTable::getRow([
116 'select' => ['ID'],
117 'filter' => [
118 '=CATALOG_GROUP_ID' => $fields['CATALOG_GROUP_ID'],
119 '=GROUP_ID' => $fields['GROUP_ID'],
120 '=ACCESS' => $fields['ACCESS'],
121 ]
122 ]);
123
124 if ($exists)
125 {
126 $result->addError(new Error('The specified access type for this group already exists'));
127 }
128
129 return $result;
130 }
131
135 protected function getEntityTable()
136 {
137 return GroupAccessTable::class;
138 }
139}
Определения error.php:15
static getRow(array $parameters)
Определения datamanager.php:398
static getById($id)
Определения datamanager.php:364
static delete($primary)
Определения datamanager.php:1644
static add(array $data)
Определения datamanager.php:877
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
if(!is_array($deviceNotifyCodes)) $access
Определения options.php:174
exists($id)
Определения checkexists.php:30
trait ListAction
Определения listaction.php:9
$fields
Определения yandex_run.php:501