1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
pricetypelang.php
См. документацию.
1<?php
2
3namespace Bitrix\Catalog\Controller;
4
5use Bitrix\Catalog\GroupLangTable;
6use Bitrix\Main\Engine\Response\DataType\Page;
7use Bitrix\Main\Error;
8use Bitrix\Main\Localization\LanguageTable;
9use Bitrix\Main\Result;
10
12{
13 use ListAction; // default listAction realization
14 use GetAction; // default getAction realization
15 use PriceTypeRights;
16
17 // region Actions
18
22 public function getFieldsAction(): array
23 {
24 return [$this->getServiceItemName() => $this->getViewFields()];
25 }
26
31
36
41 public function addAction(array $fields): ?array
42 {
43 $checkFieldsResult = $this->checkFields($fields);
44 if (!$checkFieldsResult->isSuccess())
45 {
46 $this->addErrors($checkFieldsResult->getErrors());
47
48 return null;
49 }
50
51 $addResult = GroupLangTable::add($fields);
52 if (!$addResult)
53 {
54 $this->addErrors($addResult->getErrors());
55
56 return null;
57 }
58
59 return [$this->getServiceItemName() => $this->get($addResult->getId())];
60 }
61
67 public function updateAction(int $id, array $fields): ?array
68 {
69 $existsResult = $this->exists($id);
70 if (!$existsResult->isSuccess())
71 {
73
74 return null;
75 }
76
77 $checkFieldsResult = $this->checkFields($fields);
78 if (!$checkFieldsResult->isSuccess())
79 {
80 $this->addErrors($checkFieldsResult->getErrors());
81
82 return null;
83 }
84
85 $updateResult = GroupLangTable::update($id, $fields);
86 if (!$updateResult)
87 {
88 $this->addErrors($updateResult->getErrors());
89
90 return null;
91 }
92
93 return [$this->getServiceItemName() => $this->get($id)];
94 }
95
100 public function deleteAction(int $id): ?bool
101 {
102 $existsResult = $this->exists($id);
103 if (!$existsResult->isSuccess())
104 {
106
107 return null;
108 }
109
110 $deleteResult = GroupLangTable::delete($id);
111 if (!$deleteResult)
112 {
113 $this->addErrors($deleteResult->getErrors());
114
115 return null;
116 }
117
118 return true;
119 }
120
124 public function getLanguagesAction(): Page
125 {
126 $items = $this->getLanguages();
127
128 return new Page('LANGUAGES', $items, LanguageTable::getCount());
129 }
130 // endregion
131
135 protected function getEntityTable()
136 {
137 return GroupLangTable::class;
138 }
139
143 protected function checkPermissionEntity($name, $arguments = [])
144 {
145 if ($name === 'getlanguages')
146 {
147 $result = $this->checkReadPermissionEntity();
148 }
149 else
150 {
151 $result = parent::checkPermissionEntity($name);
152 }
153
154 return $result;
155 }
156
160 private function getLanguages(): array
161 {
162 return LanguageTable::getList(
163 [
164 'select' => ['ACTIVE', 'NAME', 'LID'],
165 'order' => ['LID' => 'ASC']
166 ]
167 )->fetchAll();
168 }
169
174 private function checkFields(array $fields): Result
175 {
176 $result = new Result();
177
178 if (isset($fields['CATALOG_GROUP_ID']))
179 {
180 $priceTypeId = (int)$fields['CATALOG_GROUP_ID'];
181 $priceType = \Bitrix\Catalog\GroupTable::getById($priceTypeId)->fetch();
182 if (!$priceType)
183 {
184 $result->addError(new Error('The specified price type does not exist', ErrorCode::PRICE_TYPE_ENTITY_NOT_EXISTS));
185 }
186 }
187
188 if (isset($fields['LANG']))
189 {
190 $language = LanguageTable::getById($fields['LANG'])->fetch();
191
192 if (!$language)
193 {
194 $result->addError(new Error('The specified language does not exist', ErrorCode::PRICE_TYPE_LANG_LANGUAGE_NOT_EXISTS));
195 }
196 }
197
198 return $result;
199 }
200
201 protected function getErrorCodeEntityNotExists(): string
202 {
204 }
205}
const PRICE_TYPE_LANG_ENTITY_NOT_EXISTS
Определения errorcode.php:35
const PRICE_TYPE_LANG_LANGUAGE_NOT_EXISTS
Определения errorcode.php:36
const PRICE_TYPE_ENTITY_NOT_EXISTS
Определения errorcode.php:29
addAction(array $fields)
Определения pricetypelang.php:41
updateAction(int $id, array $fields)
Определения pricetypelang.php:67
checkPermissionEntity($name, $arguments=[])
Определения pricetypelang.php:143
Определения error.php:15
static getById($id)
Определения datamanager.php:364
</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
$name
Определения menu_edit.php:35
exists($id)
Определения checkexists.php:30
trait GetAction
Определения getaction.php:8
trait ListAction
Определения listaction.php:9
Определения aliases.php:54
$items
Определения template.php:224
$fields
Определения yandex_run.php:501