Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
store.php
1<?php
2
3
5
6
13
14final class Store extends Controller
15{
16 //region Actions
17 public function getFieldsAction(): array
18 {
19 return ['STORE' => $this->getViewFields()];
20 }
21
22 public function listAction(PageNavigation $pageNavigation, array $select = [], array $filter = [], array $order = []): Page
23 {
24 $accessFilter = $this->accessController->getEntityFilter(
25 ActionDictionary::ACTION_STORE_VIEW,
26 get_class($this->getEntityTable())
27 );
28 if ($accessFilter)
29 {
30 $filter = [
31 $accessFilter,
32 $filter,
33 ];
34 }
35
36 return new Page(
37 'STORES',
38 $this->getList($select, $filter, $order, $pageNavigation),
39 $this->count($filter)
40 );
41 }
42
43 public function addAction(array $fields)
44 {
45 $view = $this->getViewManager()
46 ->getView($this);
47 $fields = $view->internalizeFieldsAdd($fields);
48
49 $res = $this->add($fields);
50 if ($res->isSuccess())
51 {
52 $result = $res->getId();
53 }
54 else
55 {
56 $result = [
57 'error' => 'ERROR_ADD',
58 'error_description' => implode(
59 '. ',
60 $res->getErrorMessages()
61 ),
62 ];
63 }
64
65 return $result;
66 }
67
68 public function updateAction(int $id, array $fields)
69 {
70 $view = $this->getViewManager()
71 ->getView($this);
72 $fields = $view->internalizeFieldsUpdate($fields);
73
74 $res = $this->update($id, $fields);
75 if (!is_null($res) && $res->isSuccess())
76 {
77 $result = $res->getId();
78 }
79 else
80 {
81 $result = [
82 'error' => 'ERROR_UPDATE',
83 'error_description' => implode(
84 '. ',
85 $this->getErrors()
86 ),
87 ];
88 }
89
90 return $result;
91 }
92
93 public function deleteAction(int $id)
94 {
95 $res = $this->delete($id);
96 if (!is_null($res) && $res->isSuccess())
97 {
98 $result = 'Y';
99 }
100 else
101 {
102 $result = [
103 'error' => 'ERROR_DELETE',
104 'error_description' => implode(
105 '. ',
106 $this->getErrors()
107 ),
108 ];
109 }
110
111 return $result;
112 }
113
114 public function getAction($id)
115 {
116 $r = $this->exists($id);
117 if($r->isSuccess())
118 {
119 return ['STORE'=>$this->get($id)];
120 }
121 else
122 {
123 $this->addErrors($r->getErrors());
124 return null;
125 }
126 }
127 //endregion
128
129 protected function exists($id)
130 {
131 $r = new Result();
132 if(isset($this->get($id)['ID']) == false)
133 $r->addError(new Error('Store is not exists'));
134
135 return $r;
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(new Error('Access Denied', 200040300020));
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 || $this->accessController->check(ActionDictionary::ACTION_STORE_MODIFY)
164 )
165 )
166 {
167 $r->addError(new Error('Access Denied', 200040300010));
168 }
169 return $r;
170 }
171}
updateAction(int $id, array $fields)
Definition store.php:68
listAction(PageNavigation $pageNavigation, array $select=[], array $filter=[], array $order=[])
Definition store.php:22