Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
propertyrelation.php
1<?php
2
3
5
6
12
14{
15 //region Actions
16 public function getFieldsAction()
17 {
18 $view = $this->getViewManager()
19 ->getView($this);
20
21 return ['PROPERTY_RELATION'=>$view->prepareFieldInfos(
22 $view->getFields()
23 )];
24 }
25
26 public function addAction(array $fields)
27 {
28 $r = new Result();
29
30 $res = $this->existsByFilter([
31 'PROPERTY_ID'=>$fields['PROPERTY_ID'],
32 'ENTITY_ID'=>$fields['ENTITY_ID'],
33 'ENTITY_TYPE'=>$fields['ENTITY_TYPE']
34 ]);
35
36 if($res->isSuccess() == false)
37 {
38 $r = $this->existsProperty($fields['PROPERTY_ID']);
39 if($r->isSuccess())
40 {
41 $r = $this->getEntityTable()
42 ->add($fields);
43 }
44 }
45 else
46 {
47 $r->addError(new Error('Duplicate entry for key [propertyId, entityId, entityType]', 201650000001));
48 }
49
50 if(!$r->isSuccess())
51 {
52 $this->addErrors($r->getErrors());
53 return null;
54 }
55 else
56 {
57 return [
58 'PROPERTY_RELATION'=>
59 $this->getEntityTable()::getList([
60 'filter'=>[
61 'PROPERTY_ID'=>$fields['PROPERTY_ID'],
62 'ENTITY_ID'=>$fields['ENTITY_ID'],
63 'ENTITY_TYPE'=>$fields['ENTITY_TYPE']
64 ]
65 ])->fetchAll()[0]
66 ];
67 }
68 }
69
70 public function deleteByFilterAction($fields)
71 {
72 $r = $this->checkFields($fields);
73
74 if($r->isSuccess())
75 {
76 $r = $this->existsByFilter($fields);
77 if($r->isSuccess())
78 {
79 $r = $this->getEntityTable()
80 ->delete($fields);
81 }
82 }
83
84 if($r->isSuccess())
85 {
86 return true;
87 }
88 else
89 {
90 $this->addErrors($r->getErrors());
91 return null;
92 }
93 }
94
95 public function listAction(PageNavigation $pageNavigation, array $select = [], array $filter = [], array $order = []): Page
96 {
97 $select = empty($select) ? ['*']:$select;
98 $order = empty($order) ? ['PROPERTY_ID'=>'ASC']:$order;
99
100 $items = $this->getEntityTable()::getList(
101 [
102 'select' => $select,
103 'filter' => $filter,
104 'order' => $order,
105 'offset' => $pageNavigation->getOffset(),
106 'limit' => $pageNavigation->getLimit(),
107 ]
108 )->fetchAll();
109
110 return new Page('PROPERTY_RELATIONS', $items, function() use ($filter)
111 {
112 return $this->getEntityTable()::getCount([$filter]);
113 });
114 }
115 //endregion
116
118 {
119 return new OrderPropsRelationTable();
120 }
121
122 protected function existsByFilter($filter)
123 {
124 $r = new Result();
125
126 $row = $this->getEntityTable()::getList(['filter'=>['PROPERTY_ID'=>$filter['PROPERTY_ID'], 'ENTITY_ID'=>$filter['ENTITY_ID'], 'ENTITY_TYPE'=>$filter['ENTITY_TYPE']]])->fetchAll();
127 if(isset($row[0]['PROPERTY_ID']) == false)
128 $r->addError(new Error('property relation is not exists', 201640400004));
129
130 return $r;
131 }
132
133 protected function checkFields($fields)
134 {
135 $r = new Result();
136
137 if(isset($fields['PROPERTY_ID']) == false && $fields['PROPERTY_ID'] <> '')
138 $r->addError(new Error('propertyId - parametrs is empty', 201640400001));
139
140 if(isset($fields['ENTITY_ID']) == false && $fields['ENTITY_ID'] <> '')
141 $r->addError(new Error('propertyId - parametrs is empty', 201640400002));
142
143 if(isset($fields['ENTITY_TYPE']) == false && $fields['ENTITY_TYPE'] <> '')
144 $r->addError(new Error('propertyId - parametrs is empty', 201640400003));
145
146 return $r;
147 }
148
149 protected function checkPermissionEntity($name, $arguments=[])
150 {
151 if($name == 'deletebyfilter')
152 {
153 $r = $this->checkReadPermissionEntity();
154 }
155 else
156 {
157 $r = parent::checkPermissionEntity($name);
158 }
159 return $r;
160 }
161
162 protected function existsProperty($id)
163 {
164 $r = new Result();
165
166 $property = \Bitrix\Sale\Internals\OrderPropsTable::getRow([
167 'filter' => [
168 '=ID' => $id
169 ]
170 ]);
171
172 if(is_null($property))
173 $r->addError(new Error('property id is not exists', 201650000002));
174
175 return $r;
176 }
177
179 {
180 $r = new Result();
181
182 $saleModulePermissions = self::getApplication()->GetGroupRight("sale");
183 if ($saleModulePermissions < "W")
184 {
185 $r->addError(new Error('Access Denied', 200040300020));
186 }
187 return $r;
188 }
189
190 protected function checkReadPermissionEntity(): Result
191 {
192 $r = new Result();
193
194 $saleModulePermissions = self::getApplication()->GetGroupRight("sale");
195 if ($saleModulePermissions == "D")
196 {
197 $r->addError(new Error('Access Denied', 200040300010));
198 }
199 return $r;
200 }
201}
listAction(PageNavigation $pageNavigation, array $select=[], array $filter=[], array $order=[])