Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
statuslang.php
1<?php
2
3
5
6
13
15{
16 //region Actions
17 public function getFieldsAction()
18 {
19 $view = $this->getViewManager()
20 ->getView($this);
21
22 return ['STATUS_LANG'=>$view->prepareFieldInfos(
23 $view->getFields()
24 )];
25 }
26
27 protected function getEntityTable(): StatusLangTable
28 {
29 return new StatusLangTable();
30 }
31
32 public function addAction(array $fields)
33 {
34 $r = new Result();
35
36 $res = $this->existsByFilter([
37 'STATUS_ID'=>$fields['STATUS_ID'],
38 'LID'=>$fields['LID']
39 ]);
40
41 if($res->isSuccess() == false)
42 {
43 $r = $this->validate($fields);
44 if($r->isSuccess())
45 {
46 $r = $this->getEntityTable()::add($fields);
47 }
48 }
49 else
50 {
51 $r->addError(new Error('Duplicate entry for key [statusId, lid]', 201750000003));
52 }
53
54 if(!$r->isSuccess())
55 {
56 $this->addErrors($r->getErrors());
57 return null;
58 }
59 else
60 {
61 return [
62 'STATUS_LANG'=>
63 $this->getEntityTable()::getList([
64 'filter'=>[
65 'STATUS_ID'=>$fields['STATUS_ID'],
66 'LID'=>$fields['LID']
67 ]
68 ])->fetchAll()[0]
69 ];
70 }
71 }
72
73 public function deleteByFilterAction($fields)
74 {
75 $r = $this->checkFields($fields);
76
77 if($r->isSuccess())
78 {
79 $r = $this->validate($fields);
80 if($r->isSuccess())
81 {
82 $r = $this->existsByFilter([
83 'STATUS_ID'=>$fields['STATUS_ID'],
84 'LID'=>$fields['LID']
85 ]);
86 if($r->isSuccess())
87 {
88 $r = $this->getEntityTable()::delete(['STATUS_ID'=>$fields['STATUS_ID'], 'LID'=>$fields['LID']]);
89 }
90 }
91 }
92
93 if($r->isSuccess())
94 {
95 return true;
96 }
97 else
98 {
99 $this->addErrors($r->getErrors());
100 return null;
101 }
102 }
103
104 public function listAction(PageNavigation $pageNavigation, array $select = [], array $filter = [], array $order = []): Page
105 {
106 $select = empty($select) ? ['*'] : $select;
107 $order = empty($order) ? ['STATUS_ID' => 'ASC'] : $order;
108
109 $items = StatusLangTable::getList(
110 [
111 'select' => $select,
112 'filter' => $filter,
113 'order' => $order,
114 'offset' => $pageNavigation->getOffset(),
115 'limit' => $pageNavigation->getLimit(),
116 ]
117 )->fetchAll();
118
119 return new Page('STATUS_LANGS', $items, function() use ($filter)
120 {
121 return $this->getEntityTable()::getCount([$filter]);
122 });
123 }
124
125 public function getListLangsAction()
126 {
127 $items = LanguageTable::getList(
128 [
129 'select'=>['ACTIVE','NAME','LID'],
130 'filter'=>[],
131 'order'=>['LID'=>'ASC']
132 ]
133 )->fetchAll();
134
135 return new Page('LANGS', $items, function()
136 {
137 return count(
138 LanguageTable::getList()->fetchAll()
139 );
140 });
141 }
142 //endregion
143
144 protected function validate(array $fields)
145 {
146 $r = new Result();
147 if(is_set($this->getListLangs(), $fields['LID']) == false)
148 {
149 $r->addError(new Error('lid out of range',201750000004));
150 }
151
152 return $r;
153 }
154
155 protected function getListLangs()
156 {
157 $r=[];
158 $result = LanguageTable::getList([
159 'select' => ['LID', 'NAME'],
160 'filter' => ['=ACTIVE'=>'Y']
161 ]);
162 while ($row = $result->fetch())
163 $r[$row['LID']] = $row['NAME'];
164 return $r;
165 }
166
167 protected function existsByFilter($filter)
168 {
169 $r = new Result();
170
171 $row = $this->getEntityTable()::getList(['filter'=>['STATUS_ID'=>$filter['STATUS_ID'], 'LID'=>$filter['LID']]])->fetchAll();
172 if(isset($row[0]['STATUS_ID']) == false)
173 $r->addError(new Error('status lang is not exists', 201740400001));
174
175 return $r;
176 }
177
178 protected function checkFields($fields)
179 {
180 $r = new Result();
181
182 if(isset($fields['STATUS_ID']) == false && $fields['STATUS_ID'] <> '')
183 $r->addError(new Error('statusId - parametrs is empty', 201750000001));
184
185 if(isset($fields['LID']) == false && $fields['LID'] <> '')
186 $r->addError(new Error('lid - parametrs is empty', 201750000002));
187
188 return $r;
189 }
190
191 protected function checkPermissionEntity($name, $arguments = [])
192 {
193 if($name == 'deletebyfilter' ||
194 $name == 'getlistlangs')
195 {
196 $r = $this->checkReadPermissionEntity();
197 }
198 else
199 {
200 $r = parent::checkPermissionEntity($name);
201 }
202 return $r;
203 }
204
206 {
207 $r = new Result();
208
209 $saleModulePermissions = self::getApplication()->GetGroupRight("sale");
210 if ($saleModulePermissions < "W")
211 {
212 $r->addError(new Error('Access Denied', 200040300020));
213 }
214 return $r;
215 }
216
217 protected function checkReadPermissionEntity(): Result
218 {
219 $r = new Result();
220
221 $saleModulePermissions = self::getApplication()->GetGroupRight("sale");
222 if ($saleModulePermissions == "D")
223 {
224 $r->addError(new Error('Access Denied', 200040300010));
225 }
226 return $r;
227 }
228}
listAction(PageNavigation $pageNavigation, array $select=[], array $filter=[], array $order=[])
checkPermissionEntity($name, $arguments=[])