Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
base.php
1<?php
2
4
11
12abstract class Base extends Product
13{
14 protected const TYPE = '';
15
16 abstract protected function getAllowedProductTypes();
17
18 protected function processBeforeAction(Action $action)
19 {
20 $arguments = $action->getArguments();
21 $name = $action->getName();
22
23 if ($name === 'getfieldsbyfilter')
24 {
25 $arguments['filter']['productType'] = static::TYPE;
26 $action->setArguments($arguments);
27 }
28
29 return parent::processBeforeAction($action);
30 }
31
32 private function isAllowedProductTypeByIBlockId(Engine\Action $action): Result
33 {
34 $arguments = $action->getArguments();
35 $fields = $arguments['fields'];
36
38 $view = $this->getViewManager()->getView($this);
39 return $view->isAllowedProductTypeByIBlockId(static::TYPE, $fields['iblockId']);
40 }
41
42 protected function processBeforeAdd(Engine\Action $action): Result
43 {
44 $r = parent::processBeforeAdd($action);
45
46 if ($r->isSuccess())
47 {
48 $r = $this->isAllowedProductTypeByIBlockId($action);
49 }
50
51 return $r;
52 }
53
54 protected function processBeforeUpdate(Action $action): Result
55 {
56 $r = parent::processBeforeUpdate($action);
57
58 if ($r->isSuccess())
59 {
60 $r = $this->isAllowedProductTypeByIBlockId($action);
61 }
62
63 return $r;
64 }
65
66 protected function fillKeyResponse($result): ?array
67 {
68 return is_null($result) ? $result : [$this->getServiceItemName() => current($result)];
69 }
70
71 public function addAction($fields): ?array
72 {
73 $fields['TYPE'] = static::TYPE;
74 $result = parent::addAction($fields);
75
76 return $this->fillKeyResponse($result);
77 }
78
79 public function updateAction($id, array $fields): ?array
80 {
81 $result = parent::updateAction($id, $fields);
82
83 return $this->fillKeyResponse($result);
84 }
85
93 public function listAction(PageNavigation $pageNavigation, array $select = [], array $filter = [], array $order = []): ?Page
94 {
96 $view = $this->getViewManager()->getView($this);
97 $r = $view->isAllowedProductTypeByIBlockId(static::TYPE, $filter['IBLOCK_ID']);
98 if (!$r->isSuccess())
99 {
100 $this->addErrors($r->getErrors());
101
102 return null;
103 }
104
105 $list = $this->getAllowedProductTypes();
106
107 if (isset($filter['TYPE']))
108 {
109 $filter['TYPE'] = in_array($filter['TYPE'], $list, true) ? $filter['TYPE'] : $list;
110 }
111 else
112 {
113 $filter['TYPE'] = $list;
114 }
115
116 return parent::listAction($pageNavigation, $select, $filter, $order);
117 }
118
119 protected function get($id)
120 {
121 $result = parent::get($id);
122
123 if (empty($result) === false)
124 {
125 if (in_array($result['TYPE'], $this->getAllowedProductTypes()))
126 {
127 return $result;
128 }
129 }
130
131 return false;
132 }
133}
processBeforeAdd(Engine\Action $action)
Definition base.php:42
processBeforeAction(Action $action)
Definition base.php:18
updateAction($id, array $fields)
Definition base.php:79
processBeforeUpdate(Action $action)
Definition base.php:54
listAction(PageNavigation $pageNavigation, array $select=[], array $filter=[], array $order=[])
Definition product.php:191
setArguments(array $arguments)
Definition action.php:79