Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
propertyvariant.php
1<?php
2
3
5
6
11
13{
14 //region Actions
15 public function getFieldsAction()
16 {
17 $view = $this->getViewManager()
18 ->getView($this);
19
20 return ['PROPERTY_VARIANT'=>$view->prepareFieldInfos(
21 $view->getFields()
22 )];
23 }
24
25 public function addAction(array $fields): ?array
26 {
27 $variant = new \CSaleOrderPropsVariant();
28 $variantId = 0;
29
30 $r = $this->existsProperty($fields['ORDER_PROPS_ID']);
31
32 if($r->isSuccess())
33 {
34 if(!isset($fields['XML_ID']) && $fields['XML_ID'] == '')
35 {
36 $fields['XML_ID'] = OrderPropsTable::generateXmlId();
37 }
38
39 $variantId = $variant->Add($fields);
40 if ((int)$variantId <= 0)
41 {
42 if ($ex = self::getApplication()->GetException())
43 {
44 $r->addError(new Error($ex->GetString(), $ex->GetID()));
45 }
46 else
47 {
48 $r->addError(new Error('variant add error', 201550000002));
49 }
50 }
51 }
52
53 if(!$r->isSuccess())
54 {
55 foreach ($r->getErrors() as $error)
56 {
57 $this->addError(new Error($error->getMessage(), 201550000003));
58 }
59 return null;
60 }
61 else
62 return ['PROPERTY_VARIANT'=>$this->get($variantId)];
63 }
64
65 public function updateAction($id, array $fields): ?array
66 {
67 $variant = new \CSaleOrderPropsVariant();
68
69 $r = $this->exists($id);
70 if($r->isSuccess())
71 {
72 if(empty($fields) == false)
73 {
74 if(!$variant->Update($id, $fields))
75 {
76 if ($ex = self::getApplication()->GetException())
77 {
78 $r->addError(new Error($ex->GetString(), $ex->GetID()));
79 }
80 else
81 {
82 $r->addError(new Error('variant update error', 201550000004));
83 }
84 }
85 }
86 }
87
88 if($r->isSuccess())
89 {
90 return ['PROPERTY_VARIANT'=>$this->get($id)];
91 }
92 else
93 {
94 $this->addErrors($r->getErrors());
95 return null;
96 }
97 }
98
99 public function deleteAction($id)
100 {
101 $variant = new \CSaleOrderPropsVariant();
102 $r = $this->exists($id);
103 if($r->isSuccess())
104 {
105 if(!$variant->Delete($id))
106 {
107 if ($ex = self::getApplication()->GetException())
108 {
109 $r->addError(new Error($ex->GetString(), $ex->GetID()));
110 }
111 else
112 $r->addError(new Error('variant delete error ',201550000001));
113 }
114 }
115
116 if($r->isSuccess())
117 {
118 return true;
119 }
120 else
121 {
122 $this->addErrors($r->getErrors());
123 return null;
124 }
125 }
126
127 public function getAction($id)
128 {
129 $r = $this->exists($id);
130 if($r->isSuccess())
131 {
132 return ['PROPERTY_VARIANT'=>$this->get($id)];
133 }
134 else
135 {
136 $this->addErrors($r->getErrors());
137 return null;
138 }
139 }
140
141 public function listAction($select=[], $filter=[], $order=[], $start=0)
142 {
143 $result = [];
144
145 $orderPropsVariant = new \CSaleOrderPropsVariant();
146
147 $select = empty($select)? ['*']:$select;
148 $order = empty($order)? ['ID'=>'ASC']:$order;
149
150 $r = $orderPropsVariant->GetList($order, $filter, false, self::getNavData($start), $select);
151 while ($l = $r->fetch())
152 $result[] = $l;
153
154 return new Page('PROPERTY_VARIANTS', $result, function() use ($filter)
155 {
156 return (int)\CSaleOrderPropsVariant::GetList([], $filter, []);
157 });
158 }
159 //end region
160
161 protected function get($id)
162 {
163 $orderPropsGroup = new \CSaleOrderPropsVariant();
164
165 return $orderPropsGroup->GetByID($id);
166 }
167
168 protected function exists($id): Result
169 {
170 $r = new Result();
171 if(isset($this->get($id)['ID']) == false)
172 $r->addError(new Error('property variant is not exists', 201540400001));
173
174 return $r;
175 }
176
177 protected function existsProperty($id)
178 {
179 $r = new Result();
180
181 $property = OrderPropsTable::getRow([
182 'filter' => [
183 '=ID' => $id
184 ]
185 ]);
186
187 if(is_null($property))
188 $r->addError(new Error('property id is not exists', 201550000005));
189
190 return $r;
191 }
192
194 {
195 $r = new Result();
196
197 $saleModulePermissions = self::getApplication()->GetGroupRight("sale");
198 if ($saleModulePermissions < "W")
199 {
200 $r->addError(new Error('Access Denied', 200040300020));
201 }
202 return $r;
203 }
204
205 protected function checkReadPermissionEntity(): Result
206 {
207 $r = new Result();
208
209 $saleModulePermissions = self::getApplication()->GetGroupRight("sale");
210 if ($saleModulePermissions == "D")
211 {
212 $r->addError(new Error('Access Denied', 200040300010));
213 }
214 return $r;
215 }
216}
listAction($select=[], $filter=[], $order=[], $start=0)