Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
StoreViewFilter.php
1<?php
2
4
17
24{
28 public function getFilter(string $entity, array $params = []): array
29 {
30 $action = (string)($params['action'] ?? '');
31 if (empty($action))
32 {
33 throw new SystemException('No action is set in the parameters');
34 }
35
36 $this->validateEntity($entity);
37
38 if ($this->user->isAdmin())
39 {
40 return [];
41 }
42
43 if ($entity === StoreTable::class)
44 {
45 return $this->getStoreFilter($action);
46 }
47
48 if ($entity === StoreDocumentTable::class)
49 {
50 return $this->getDocumentFilter($action);
51 }
52
53 if ($entity === StoreProductTable::class)
54 {
55 return $this->getProductFilter($action);
56 }
57
58 if (Loader::includeModule('sale'))
59 {
60 if ($entity === ShipmentTable::class)
61 {
62 return $this->getSaleShipmentFilter($action);
63 }
64 }
65
66 throw new UnknownEntityException($entity, $this);
67 }
68
77 private function validateEntity(string $entity): void
78 {
79 $available = [
80 StoreTable::class,
81 StoreProductTable::class,
82 StoreDocumentTable::class,
83 // sale
84 ShipmentTable::class,
85 ];
86
87 if (!in_array($entity, $available, true))
88 {
89 throw new UnknownEntityException($entity, $this);
90 }
91 }
92
100 private function getStoreFilter(string $action): array
101 {
102 $allowedStores = $this->controller->getPermissionValue($action);
103 if (empty($allowedStores))
104 {
105 return [
106 '=ID' => null,
107 ];
108 }
109
110 if (in_array(PermissionDictionary::VALUE_VARIATION_ALL, $allowedStores, true))
111 {
112 return [];
113 }
114
115 return [
116 '=ID' => $allowedStores,
117 ];
118 }
119
127 private function getDocumentFilter(string $action): array
128 {
129 $allowedStores = $this->controller->getPermissionValue($action);
130 if (empty($allowedStores))
131 {
132 $documentFilter = [
133 'LOGIC' => 'OR',
134 '=ELEMENTS.ID' => null, // without elements
135 [
136 '=ELEMENTS.STORE_TO' => null,
137 '=ELEMENTS.STORE_FROM' => null,
138 ]
139 ];
140 }
141 elseif (in_array(PermissionDictionary::VALUE_VARIATION_ALL, $allowedStores, true))
142 {
143 return [];
144 }
145 else
146 {
147 $documentFilter = [
148 'LOGIC' => 'OR',
149 '=ELEMENTS.ID' => null, // without elements
150 '=ELEMENTS.STORE_TO' => $allowedStores,
151 '=ELEMENTS.STORE_FROM' => $allowedStores,
152 [
153 '=ELEMENTS.STORE_TO' => null,
154 '=ELEMENTS.STORE_FROM' => null,
155 ]
156 ];
157 }
158
159 $query =
161 ->setSelect(['ID'])
162 ->setFilter($documentFilter)
163 ->getQuery()
164 ;
165
166 return [
167 '@ID' => new SqlExpression($query),
168 ];
169 }
170
178 private function getProductFilter(string $action): array
179 {
180 $allowedStores = $this->controller->getPermissionValue($action);
181 if (empty($allowedStores))
182 {
183 return [
184 '=ID' => null,
185 ];
186 }
187
188 if (in_array(PermissionDictionary::VALUE_VARIATION_ALL, $allowedStores, true))
189 {
190 return [];
191 }
192
193 return [
194 '=STORE_ID' => $allowedStores,
195 ];
196 }
197
205 private function getSaleShipmentFilter(string $action): array
206 {
207 $allowedStores = $this->controller->getPermissionValue($action);
208 if (empty($allowedStores))
209 {
210 return [
211 '=ID' => null,
212 ];
213 }
214
215 if (in_array(PermissionDictionary::VALUE_VARIATION_ALL, $allowedStores, true))
216 {
217 return [];
218 }
219
220 $allowedStores[] = null;
221 $storeFilter = [
222 '=STORE_ID' => $allowedStores,
223 ];
224
225 $query =
226 ShipmentItemStoreTable::query()
227 ->setSelect(['ORDER_DELIVERY_BASKET_ID'])
228 ->setFilter($storeFilter)
229 ->getQuery()
230 ;
231
232 return [
233 [
234 'LOGIC' => 'OR',
235 '=SHIPMENT_ITEM.ID' => null,
236 '@SHIPMENT_ITEM.ID' => new SqlExpression($query),
237 ]
238 ];
239 }
240}
getFilter(string $entity, array $params=[])