1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
base.php
См. документацию.
1<?php
2
4
12
13abstract class Base extends Product
14{
15 protected const TYPE = '';
16
17 abstract protected function getAllowedProductTypes();
18
20 {
21 $arguments = $action->getArguments();
22 $name = $action->getName();
23
24 if ($name === 'add' || $name === 'update')
25 {
26 $fields = $arguments['fields'] ?? [];
27 if (!is_array($fields))
28 {
29 $this->addError(new Error('Incorrect fields format'));
30
31 return null;
32 }
33 $fields['type'] = static::TYPE;
34 $arguments['fields'] = $fields;
35
36 $action->setArguments($arguments);
37 }
38
39 return parent::processBeforeAction($action);
40 }
41
42 private function isAllowedProductTypeByIBlockId(Engine\Action $action): Result
43 {
44 $arguments = $action->getArguments();
45 $fields = $arguments['fields'];
46
48 $view = $this->getViewManager()->getView($this);
49 return $view->isAllowedProductTypeByIBlockId(static::TYPE, $fields['iblockId']);
50 }
51
53 {
54 $r = parent::processBeforeAdd($action);
55
56 if ($r->isSuccess())
57 {
58 $r = $this->isAllowedProductTypeByIBlockId($action);
59 }
60
61 return $r;
62 }
63
65 {
66 $r = parent::processBeforeUpdate($action);
67
68 if ($r->isSuccess())
69 {
70 $r = $this->isAllowedProductTypeByIBlockId($action);
71 }
72
73 return $r;
74 }
75
76 protected function fillKeyResponse($result): ?array
77 {
78 return is_null($result) ? $result : [$this->getServiceItemName() => current($result)];
79 }
80
81 public function addAction($fields): ?array
82 {
83 $result = parent::addAction($fields);
84
85 return $this->fillKeyResponse($result);
86 }
87
88 public function updateAction($id, array $fields): ?array
89 {
90 $result = parent::updateAction($id, $fields);
91
92 return $this->fillKeyResponse($result);
93 }
94
103 public function listAction(
104 PageNavigation $pageNavigation,
105 array $select = [],
106 array $filter = [],
107 array $order = [],
108 bool $__calculateTotalCount = true
109 ): ?Page
110 {
112 $view = $this->getViewManager()->getView($this);
113 $r = $view->isAllowedProductTypeByIBlockId(static::TYPE, $filter['IBLOCK_ID']);
114 if (!$r->isSuccess())
115 {
116 $this->addErrors($r->getErrors());
117
118 return null;
119 }
120
121 $list = $this->getAllowedProductTypes();
122
123 if (isset($filter['TYPE']))
124 {
125 $filter['TYPE'] = in_array($filter['TYPE'], $list, true) ? $filter['TYPE'] : $list;
126 }
127 else
128 {
129 $filter['TYPE'] = $list;
130 }
131
132 return parent::listAction($pageNavigation, $select, $filter, $order, $__calculateTotalCount);
133 }
134
135 protected function get($id)
136 {
137 $result = parent::get($id);
138
139 if (empty($result) === false)
140 {
141 if (in_array($result['TYPE'], $this->getAllowedProductTypes()))
142 {
143 return $result;
144 }
145 }
146
147 return false;
148 }
149}
processBeforeAdd(Engine\Action $action)
Определения base.php:52
processBeforeAction(Action $action)
Определения base.php:19
updateAction($id, array $fields)
Определения base.php:88
fillKeyResponse($result)
Определения base.php:76
addAction($fields)
Определения base.php:81
processBeforeUpdate(Action $action)
Определения base.php:64
listAction(PageNavigation $pageNavigation, array $select=[], array $filter=[], array $order=[], bool $__calculateTotalCount=true)
Определения product.php:253
Определения error.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
$result
Определения get_property_values.php:14
$select
Определения iblock_catalog_list.php:194
$filter
Определения iblock_catalog_list.php:54
$name
Определения menu_edit.php:35
Определения action.php:3
Определения aliases.php:54
$order
Определения payment.php:8
$action
Определения file_dialog.php:21
$fields
Определения yandex_run.php:501