Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
config.php
1<?php
3
15
17{
18 public const QUANTITY_INCONSISTENCY_EXISTS = 'QUANTITY_INCONSISTENCY_EXISTS';
19 public const CONDUCTED_DOCUMENTS_EXIST = 'CONDUCTED_DOCUMENTS_EXIST';
20
27 protected function processBeforeAction(Action $action): ?bool
28 {
29 $r = $this->checkPermission($action->getName(), $action->getArguments());
30 if ($r->isSuccess())
31 {
32 //do nothing
33 }
34 else
35 {
36 $this->addErrors($r->getErrors());
37 return null;
38 }
39
40 return parent::processBeforeAction($action);
41 }
42
46 protected function checkPermission($name, $arguments = [])
47 {
48 $name = strtolower($name);
49
50 if (
51 $name === strtolower('onceInventoryManagementY')
52 || $name === strtolower('onceInventoryManagementN')
53 || $name === strtolower('inventoryManagementN')
54 || $name === strtolower('inventoryManagementY')
55 || $name === strtolower('inventoryManagementYAndResetQuantity')
56 || $name === strtolower('inventoryManagementYAndResetQuantityWithDocuments')
57 || $name === strtolower('unRegisterOnProlog')
58 )
59 {
60 $r = $this->checkModifyPermissionEntity($name, $arguments);
61 }
62 else if (
63 $name === strtolower('isUsedInventoryManagement')
64 || $name === strtolower('conductedDocumentsExist')
65 || $name === strtolower('checkEnablingConditions')
66 )
67 {
68 $r = $this->checkReadPermissionEntity($name, $arguments);
69 }
70 else
71 {
72 $r = $this->checkPermissionEntity($name, $arguments);
73 }
74
75 return $r;
76 }
77
83 protected function checkReadPermissionEntity($name, $arguments = [])
84 {
85 $r = new Result();
86 if (!AccessController::getCurrent()->check(ActionDictionary::ACTION_CATALOG_READ))
87 {
88 $r->addError(new Error('Access denied!', 200040300010));
89 }
90 return $r;
91 }
92
93 protected function checkModifyPermissionEntity($name, $arguments = []): Result
94 {
95 $r = new Result();
96 if (!AccessController::getCurrent()->check(ActionDictionary::ACTION_STORE_VIEW))
97 {
98 $r->addError(new Error('Access denied!', 200040300011));
99 }
100 return $r;
101 }
102
108 protected function checkPermissionEntity($name, $arguments = [])
109 {
110 throw new NotImplementedException('Check permission entity. The method '.$name.' is not implemented.');
111 }
112
113 public function onceInventoryManagementYAction(): bool
114 {
115 return UseStore::enableOnec();
116 }
117
118 public function onceInventoryManagementNAction(): bool
119 {
120 return UseStore::disableOnec();
121 }
122
123 public function isUsedInventoryManagementAction(): bool
124 {
125 return UseStore::isUsed();
126 }
127
128 public function inventoryManagementNAction(): void
129 {
130 if (!UseStore::disable())
131 {
132 $this->addInventoryManagementDisableError();
133 }
134 }
135
136 public function inventoryManagementYAndResetQuantityWithDocumentsAction(string $costPriceCalculationMethod): void
137 {
138 if (
139 UseStore::isPlanRestricted()
140 || !UseStore::enable()
141 )
142 {
143 $this->addInventoryManagementEnableError();
144
145 return;
146 }
147
148 CostPriceCalculator::setMethod($costPriceCalculationMethod);
149
150 UseStore::resetDocuments();
151 }
152
154 {
155 if (
156 UseStore::isPlanRestricted()
157 || !UseStore::enable()
158 )
159 {
160 $this->addInventoryManagementEnableError();
161 }
162 }
163
164 public function inventoryManagementYAction(string $costPriceCalculationMethod): void
165 {
166 if (
167 UseStore::isPlanRestricted()
168 || !UseStore::enableWithoutResetting()
169 )
170 {
171 $this->addInventoryManagementEnableError();
172 }
173
174 CostPriceCalculator::setMethod($costPriceCalculationMethod);
175 }
176
177 public function unRegisterOnPrologAction(): bool
178 {
179 return PresetHandler::unRegister();
180 }
181
182 public function conductedDocumentsExistAction(): bool
183 {
184 return UseStore::conductedDocumentsExist();
185 }
186
187 public function checkEnablingConditionsAction(): array
188 {
189 $result = [];
190
191 if (UseStore::doNonEmptyProductsExist())
192 {
193 $result[] = self::QUANTITY_INCONSISTENCY_EXISTS;
194 }
195
196 if (UseStore::conductedDocumentsExist())
197 {
198 $result[] = self::CONDUCTED_DOCUMENTS_EXIST;
199 }
200
201 return $result;
202 }
203
204 private function addInventoryManagementEnableError(): void
205 {
206 $this->addError(
207 new Error(
208 Loc::getMessage('CATALOG_CONTROLLER_CONFIG_INVENTORY_MANAGEMENT_ENABLE_DEFAULT_ERROR')
209 )
210 );
211 }
212
213 private function addInventoryManagementDisableError(): void
214 {
215 $this->addError(
216 new Error(
217 Loc::getMessage('CATALOG_CONTROLLER_CONFIG_INVENTORY_MANAGEMENT_DISABLE_DEFAULT_ERROR')
218 )
219 );
220 }
221}
inventoryManagementYAction(string $costPriceCalculationMethod)
Definition config.php:164
inventoryManagementYAndResetQuantityWithDocumentsAction(string $costPriceCalculationMethod)
Definition config.php:136
processBeforeAction(Action $action)
Definition config.php:27
checkModifyPermissionEntity($name, $arguments=[])
Definition config.php:93
checkPermission($name, $arguments=[])
Definition config.php:46
checkReadPermissionEntity($name, $arguments=[])
Definition config.php:83
checkPermissionEntity($name, $arguments=[])
Definition config.php:108
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29