Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
StoreDocumentFilter.php
1<?php
2
4
14
21{
25 public function getFilter(string $entity, array $params = []): array
26 {
27 $action = (string)($params['action'] ?? '');
28 if (empty($action))
29 {
30 throw new SystemException('No action is set in the parameters');
31 }
32
33 Loader::includeModule('sale');
34
35 $this->validateEntity($entity);
36
37 if ($this->user->isAdmin())
38 {
39 return [];
40 }
41
42 if ($entity === StoreDocumentTable::class)
43 {
44 return $this->getDocumentFilter($action);
45 }
46
47 if ($entity === StoreDocumentElementTable::class)
48 {
49 return $this->getElementFilter($action);
50 }
51
52 if ($entity === ShipmentTable::class)
53 {
54 return $this->getShipmentFilter($action);
55 }
56
57 if ($entity === ShipmentItemTable::class)
58 {
59 return $this->getShipmentItemFilter($action);
60 }
61 }
62
71 private function validateEntity(string $entity): void
72 {
73 $available = [
74 StoreDocumentTable::class,
75 StoreDocumentElementTable::class,
76 ShipmentTable::class,
77 ShipmentItemTable::class,
78 ];
79
80 if (!in_array($entity, $available, true))
81 {
82 throw new UnknownEntityException($entity, $this);
83 }
84 }
85
93 private function getDocumentFilter(string $action): ?array
94 {
95 $types = array_filter(
96 PermissionDictionary::getAvailableStoreDocuments(),
97 fn(string $docType) => $this->controller->check($action, null, ['value' => $docType])
98 );
99
100 if (empty($types))
101 {
102 return [
103 '=ID' => null,
104 ];
105 }
106
107 return [
108 '=DOC_TYPE' => $types,
109 ];
110 }
111
119 private function getElementFilter(string $action): ?array
120 {
121 $types = array_filter(
122 PermissionDictionary::getAvailableStoreDocuments(),
123 fn(string $docType) => $this->controller->check($action, null, ['value' => $docType])
124 );
125
126 if (empty($types))
127 {
128 return [
129 '=ID' => null,
130 ];
131 }
132
133 return [
134 '=DOCUMENT.DOC_TYPE' => $types,
135 ];
136 }
137
145 private function getShipmentFilter(string $action): ?array
146 {
147 $can = $this->controller->check($action, null, ['value' => StoreDocumentTable::TYPE_SALES_ORDERS]);
148 if (!$can)
149 {
150 return [
151 '=ID' => null,
152 ];
153 }
154
155 return [];
156 }
157
165 private function getShipmentItemFilter(string $action): ?array
166 {
167 // identical checks
168 return $this->getShipmentFilter($action);
169 }
170}