Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
pricetypelang.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_LANG' => $this->getViewFields()];
24 }
25
33 public function listAction(PageNavigation $pageNavigation, array $select = [], array $filter = [], array $order = []): Page
34 {
35 return new Page(
36 'PRICE_TYPE_LANGS',
37 $this->getList($select, $filter, $order, $pageNavigation),
38 $this->count($filter)
39 );
40 }
41
46 public function getAction(int $id): ?array
47 {
48 $existsResult = $this->exists($id);
49 if (!$existsResult->isSuccess())
50 {
51 $this->addErrors($existsResult->getErrors());
52
53 return null;
54 }
55
56 return ['PRICE_TYPE_LANG' => $this->get($id)];
57 }
58
63 public function addAction(array $fields): ?array
64 {
65 $checkFieldsResult = $this->checkFields($fields);
66 if (!$checkFieldsResult->isSuccess())
67 {
68 $this->addErrors($checkFieldsResult->getErrors());
69
70 return null;
71 }
72
73 $addResult = GroupLangTable::add($fields);
74 if (!$addResult)
75 {
76 $this->addErrors($addResult->getErrors());
77
78 return null;
79 }
80
81 return ['PRICE_TYPE_LANG' => $this->get($addResult->getId())];
82 }
83
89 public function updateAction(int $id, array $fields): ?array
90 {
91 $existsResult = $this->exists($id);
92 if (!$existsResult->isSuccess())
93 {
94 $this->addErrors($existsResult->getErrors());
95
96 return null;
97 }
98
99 $checkFieldsResult = $this->checkFields($fields);
100 if (!$checkFieldsResult->isSuccess())
101 {
102 $this->addErrors($checkFieldsResult->getErrors());
103
104 return null;
105 }
106
107 $updateResult = GroupLangTable::update($id, $fields);
108 if (!$updateResult)
109 {
110 $this->addErrors($updateResult->getErrors());
111
112 return null;
113 }
114
115 return ['PRICE_TYPE_LANG' => $this->get($id)];
116 }
117
122 public function deleteAction(int $id): ?bool
123 {
124 $existsResult = $this->exists($id);
125 if (!$existsResult->isSuccess())
126 {
127 $this->addErrors($existsResult->getErrors());
128
129 return null;
130 }
131
132 $deleteResult = GroupLangTable::delete($id);
133 if (!$deleteResult)
134 {
135 $this->addErrors($deleteResult->getErrors());
136
137 return null;
138 }
139
140 return true;
141 }
142
146 public function getLanguagesAction(): Page
147 {
148 $items = $this->getLanguages();
149
150 return new Page('LANGUAGES', $items, LanguageTable::getCount());
151 }
152 // endregion
153
157 protected function getEntityTable()
158 {
159 return GroupLangTable::class;
160 }
161
165 protected function checkPermissionEntity($name, $arguments = [])
166 {
167 if ($name === 'getlanguages')
168 {
169 $result = $this->checkReadPermissionEntity();
170 }
171 else
172 {
173 $result = parent::checkPermissionEntity($name);
174 }
175
176 return $result;
177 }
178
182 private function getLanguages(): array
183 {
184 return LanguageTable::getList(
185 [
186 'select' => ['ACTIVE', 'NAME', 'LID'],
187 'order' => ['LID' => 'ASC']
188 ]
189 )->fetchAll();
190 }
191
196 private function checkFields(array $fields): Result
197 {
198 $result = new Result();
199
200 $priceTypeId = (int)$fields['CATALOG_GROUP_ID'];
201 $priceType = \Bitrix\Catalog\GroupTable::getById($priceTypeId)->fetch();
202 if (!$priceType)
203 {
204 $result->addError(new Error('The specified price type does not exist'));
205 }
206
207 $languageId = $fields['LANG'];
208 $language = LanguageTable::getById($languageId)->fetch();
209 if (!$language)
210 {
211 $result->addError(new Error('The specified language does not exist'));
212 }
213
214 return $result;
215 }
216}
listAction(PageNavigation $pageNavigation, array $select=[], array $filter=[], array $order=[])