1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
catalog.php
См. документацию.
1<?php
2
3namespace Bitrix\Catalog\Controller;
4
5use Bitrix\Catalog\Access\ActionDictionary;
6use Bitrix\Catalog\CatalogIblockTable;
7use Bitrix\Main\Engine\CurrentUser;
8use Bitrix\Main\Engine\Response\DataType\Page;
9use Bitrix\Main\Error;
10use Bitrix\Main\Result;
11
12final class Catalog extends Controller
13{
14 use GetAction; // default getAction realization
15 use CheckExists; // default implementation of existence check
16
17 protected function isExistsRow(int $id): bool
18 {
19 $entityTable = $this->getEntityTable();
20
21 $row = $entityTable::getRow([
22 'select' => [
23 'IBLOCK_ID',
24 ],
25 'filter' => [
26 '=IBLOCK_ID' => $id,
27 ],
28 ]);
29
30 return !empty($row);
31 }
32
33 //region Actions
34
40 public function getFieldsAction(): array
41 {
42 return ['CATALOG' => $this->getViewFields()];
43 }
44
45 public function isOffersAction($id)
46 {
47 $r = $this->exists($id);
48 if($r->isSuccess())
49 {
50 return $this->isOffers($id);
51 }
52 else
53 {
54 $this->addErrors($r->getErrors());
55 return null;
56 }
57 }
58
59 public function listAction($select=[], $filter=[], $order=[], $start=0)
60 {
61 $result = [];
62
63 $catalog = new \CCatalog();
64
65 $select = empty($select)? ['*']:$select;
66 $order = empty($order)? ['ID'=>'ASC']:$order;
67
68 $r = $catalog::GetList($order, $filter, false, self::getNavData($start), $select);
69 while ($l = $r->fetch())
70 {
71 $result[] = $l;
72 }
73
74 return new Page('CATALOGS', $result, function() use ($filter)
75 {
76 return (int)\CCatalog::GetList([], $filter, []);
77 });
78 }
79
84
85 public function addAction($fields)
86 {
87 $r = new Result();
88
89 $res = $this->exists($fields['IBLOCK_ID']);
90 if($res->isSuccess() == false)
91 {
92 $r = $this->addValidate($fields);
93 if($r->isSuccess())
94 {
95 \CCatalog::add($fields);
96 }
97 }
98 else
99 {
100 $r->addError(new Error('Duplicate entry for key [iblockId]'));
101 }
102
103 if(!$r->isSuccess())
104 {
105 $this->addErrors($r->getErrors());
106 return null;
107 }
108 else
109 {
110 return ['CATALOG'=>$this->get($fields['IBLOCK_ID'])];
111 }
112 }
113
114 public function updateAction($id, array $fields)
115 {
116 $r = $this->exists($id);
117 if($r->isSuccess())
118 {
119 $r = $this->updateValidate($fields+['ID'=>$id]);
120 if($r->isSuccess())
121 {
122 \CCatalog::update($id, $fields);
123 }
124 }
125
126 if($r->isSuccess())
127 {
128 return ['CATALOG'=>$this->get($id)];
129 }
130 else
131 {
132 $this->addErrors($r->getErrors());
133 return null;
134 }
135 }
136
137 public function deleteAction($id)
138 {
139 $r = $this->exists($id);
140 if($r->isSuccess())
141 {
142 $r = $this->deleteValidate($id);
143 if($r->isSuccess())
144 {
145 if (!\CCatalog::Delete($id))
146 {
147 if ($ex = self::getApplication()->GetException())
148 $r->addError(new Error($ex->GetString(), $ex->GetId()));
149 else
150 $r->addError(new Error('delete catalog error'));
151 }
152 }
153 }
154
155 if($r->isSuccess())
156 {
157 return true;
158 }
159 else
160 {
161 $this->addErrors($r->getErrors());
162 return null;
163 }
164 }
165 //endregion
166
167 protected function isOffers($id)
168 {
169 return $this->get($id)["PRODUCT_IBLOCK_ID"] ? true:false;
170 }
171
172 protected function getEntityTable()
173 {
174 return new CatalogIblockTable();
175 }
176
177 protected function get($id)
178 {
179 return \CCatalog::GetByID($id);
180 }
181
182 protected function addValidate(array $fields)
183 {
184 $r = new Result();
185
186 if(!\CCatalog::CheckFields("ADD", $fields, $fields['ID'] ?? 0))
187 {
188 if ($ex = self::getApplication()->GetException())
189 $r->addError(new Error($ex->GetString(), $ex->GetId()));
190 else
191 $r->addError(new Error('Validate catalog error'));
192 }
193
194 return $r;
195 }
196
197 protected function updateValidate(array $fields)
198 {
199 $r = new Result();
200
201 if(!\CCatalog::CheckFields("UPDATE", $fields, $fields['ID'] ?? 0))
202 {
203 if ($ex = self::getApplication()->GetException())
204 $r->addError(new Error($ex->GetString(), $ex->GetId()));
205 else
206 $r->addError(new Error('Validate catalog error'));
207 }
208
209 return $r;
210 }
211
212 protected function deleteValidate($id)
213 {
214 $r = new Result();
215
216 if($this->isOffers($id))
217 $r->addError(new Error('Catalog is offers'));
218
219 return $r;
220 }
221
222 protected function checkPermissionEntity($name, $arguments=[])
223 {
224 $name = mb_strtolower($name); //for ajax mode
225
226 if($name == 'isoffers')
227 {
228 $r = $this->checkReadPermissionEntity();
229 }
230 else
231 {
232 $r = parent::checkPermissionEntity($name);
233 }
234
235 return $r;
236 }
237
238 protected function checkModifyPermissionEntity()
239 {
240 $r = $this->checkReadPermissionEntity();
241 if($r->isSuccess())
242 {
243 if (!$this->accessController->check(ActionDictionary::ACTION_CATALOG_SETTINGS_ACCESS))
244 {
245 $r->addError($this->getErrorModifyAccessDenied());
246 }
247 }
248
249 return $r;
250 }
251
252 protected function checkReadPermissionEntity()
253 {
254 $r = new Result();
255
256 $user = CurrentUser::get();
257 if(!$user->canDoOperation('view_other_settings') && !$user->canDoOperation('edit_other_settings'))
258 {
259 $r->addError($this->getErrorReadAccessDenied());
260 }
261
262 if (
263 !$this->accessController->check(ActionDictionary::ACTION_CATALOG_READ)
264 && !$this->accessController->check(ActionDictionary::ACTION_CATALOG_SETTINGS_ACCESS)
265 )
266 {
267 $r->addError(new Error('Access Denied', 200040300030));
268 }
269
270 return $r;
271 }
272}
checkModifyPermissionEntity()
Определения catalog.php:238
deleteValidate($id)
Определения catalog.php:212
checkReadPermissionEntity()
Определения catalog.php:252
updateValidate(array $fields)
Определения catalog.php:197
addValidate(array $fields)
Определения catalog.php:182
updateAction($id, array $fields)
Определения catalog.php:114
isExistsRow(int $id)
Определения catalog.php:17
checkPermissionEntity($name, $arguments=[])
Определения catalog.php:222
isOffersAction($id)
Определения catalog.php:45
addAction($fields)
Определения catalog.php:85
listAction($select=[], $filter=[], $order=[], $start=0)
Определения catalog.php:59
Определения error.php:15
static Delete($ID)
Определения catalog.php:1259
static CheckFields($ACTION, &$arFields, $ID=0)
Определения catalog.php:15
static GetList($arOrder=array(), $arFilter=array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
Определения catalog.php:15
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$start
Определения get_search.php:9
$catalog
Определения iblock_catalog_edit.php:135
$select
Определения iblock_catalog_list.php:194
$filter
Определения iblock_catalog_list.php:54
$l
Определения options.php:783
$name
Определения menu_edit.php:35
exists($id)
Определения checkexists.php:30
trait CheckExists
Определения checkexists.php:8
trait GetAction
Определения getaction.php:8
Определения aliases.php:54
$user
Определения mysql_to_pgsql.php:33
$order
Определения payment.php:8
$fields
Определения yandex_run.php:501