1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
store.php
См. документацию.
1<?php
2
3namespace Bitrix\Catalog\Controller;
4
5use Bitrix\Catalog\Access\ActionDictionary;
6use Bitrix\Catalog\StoreTable;
7use Bitrix\Main\Error;
8use Bitrix\Main\Result;
9use CCatalogStore;
10
11final class Store extends Controller
12{
13 use ListAction; // default listAction realization
14 use CheckExists; // default implementation of existence check
15
16 //region Actions
17 public function getFieldsAction(): array
18 {
19 return [$this->getServiceItemName() => $this->getViewFields()];
20 }
21
26
27 public function getAction($id): ?array
28 {
29 $id = (int)$id;
30
31 if (!$this->exists($id)->isSuccess())
32 {
34
35 return null;
36 }
37
38 $storeInfo = $this->get($id);
39
40 if (!$this->checkSpecificStoreReadRight($id))
41 {
42 $this->addError($this->getErrorReadAccessDenied());
43
44 return null;
45 }
46
47 return [
48 $this->getServiceItemName() => $storeInfo,
49 ];
50 }
51
52 public function addAction(array $fields)
53 {
54 $result = CCatalogStore::Add($fields);
55 if (!$result)
56 {
57 global $APPLICATION;
58 $exception = $APPLICATION->GetException();
59 $error = $exception instanceof \CApplicationException ? $exception->GetString() : 'Unknown error';
60 $this->addError(new Error($error));
61 $APPLICATION->ResetException();
62
63 return null;
64 }
65
66 return [
67 $this->getServiceItemName() => $this->get($result),
68 ];
69 }
70
71 public function updateAction(int $id, array $fields)
72 {
73 $existsResult = $this->exists($id);
74 if (!$existsResult->isSuccess())
75 {
76 $this->addErrors($existsResult->getErrors());
77
78 return null;
79 }
80
81 if (!$this->checkSpecificStoreModifyRights($id)
82 )
83 {
84 $this->addError($this->getErrorModifyAccessDenied());
85
86 return null;
87 }
88
89 $result = CCatalogStore::Update($id, $fields);
90 if (!$result)
91 {
92 global $APPLICATION;
93 $exception = $APPLICATION->GetException();
94 $error = $exception instanceof \CApplicationException ? $exception->GetString() : 'Unknown error';
95 $this->addError(new Error($error));
96 $APPLICATION->ResetException();
97
98 return null;
99 }
100
101 return [
102 $this->getServiceItemName() => $this->get($result),
103 ];
104 }
105
106 public function deleteAction(int $id)
107 {
108 $existsResult = $this->exists($id);
109 if (!$existsResult->isSuccess())
110 {
111 $this->addErrors($existsResult->getErrors());
112
113 return null;
114 }
115
116 if (!$this->checkSpecificStoreModifyRights($id))
117 {
118 $this->addError($this->getErrorModifyAccessDenied());
119
120 return null;
121 }
122
123 $result = CCatalogStore::Delete($id);
124 if (!$result)
125 {
126 global $APPLICATION;
127 $exception = $APPLICATION->GetException();
128 $error = $exception instanceof \CApplicationException ? $exception->GetString() : 'Unknown error';
129 $this->addError(new Error($error));
130 $APPLICATION->ResetException();
131
132 return null;
133 }
134
135 return true;
136 }
137
138 protected function getEntityTable()
139 {
140 return new StoreTable();
141 }
142
143 protected function checkModifyPermissionEntity()
144 {
145 $r = new Result();
146
147 if (!$this->accessController->check(ActionDictionary::ACTION_STORE_MODIFY))
148 {
149 $r->addError($this->getErrorModifyAccessDenied());
150 }
151
152 return $r;
153 }
154
155 protected function checkReadPermissionEntity()
156 {
157 $r = new Result();
158
159 if (
160 !(
161 $this->accessController->check(ActionDictionary::ACTION_CATALOG_READ)
162 || $this->accessController->check(ActionDictionary::ACTION_STORE_VIEW)
163 )
164 )
165 {
166 $r->addError($this->getErrorReadAccessDenied());
167 }
168 return $r;
169 }
170
177 {
178 $accessFilter = $this->accessController->getEntityFilter(
179 ActionDictionary::ACTION_STORE_VIEW,
180 get_class($this->getEntityTable())
181 );
182
183 $innerFilter = [
184 'LOGIC' => 'OR',
185 ];
186
187 if ($accessFilter)
188 {
189 $innerFilter[] = $accessFilter;
190
191 if ($this->checkModifyPermissionEntity()->isSuccess())
192 {
193 $innerFilter[] = ['=USER_ID' => $this->accessController->getUser()->getUserId()];
194 }
195 }
196
197 $params['filter'] = [
198 $innerFilter,
199 $params['filter'],
200 ];
201
202 return $params;
203 }
204
205 protected function getErrorCodeEntityNotExists(): string
206 {
208 }
209
210 protected function checkSpecificStoreReadRight(int $storeId): bool
211 {
213
214 return
215 $this->accessController->checkByValue(ActionDictionary::ACTION_STORE_VIEW, (string)$storeId)
216 || (
217 $this->accessController->check(ActionDictionary::ACTION_STORE_MODIFY)
218 && $creatorId === $this->accessController->getUser()->getUserId()
219 )
220 ;
221 }
222
223 protected function checkSpecificStoreModifyRights(int $storeId): bool
224 {
225 return
226 $this->accessController->check(ActionDictionary::ACTION_STORE_MODIFY)
228 ;
229 }
230}
global $APPLICATION
Определения include.php:80
const STORE_ENTITY_NOT_EXISTS
Определения errorcode.php:32
checkModifyPermissionEntity()
Определения store.php:143
checkSpecificStoreReadRight(int $storeId)
Определения store.php:210
checkReadPermissionEntity()
Определения store.php:155
getErrorCodeEntityNotExists()
Определения store.php:205
addAction(array $fields)
Определения store.php:52
getFieldsAction()
Определения store.php:17
deleteAction(int $id)
Определения store.php:106
modifyListActionParameters(array $params)
Определения store.php:176
updateAction(int $id, array $fields)
Определения store.php:71
getAction($id)
Определения store.php:27
checkSpecificStoreModifyRights(int $storeId)
Определения store.php:223
static getStoreCreatorId(int $storeId)
Определения store.php:418
Определения 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
exists($id)
Определения checkexists.php:30
trait CheckExists
Определения checkexists.php:8
trait ListAction
Определения listaction.php:9
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$error
Определения subscription_card_product.php:20
$fields
Определения yandex_run.php:501