Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
propertygroups.php
1
<?php
2
3
4
namespace
Bitrix\Sale\Controller
;
5
6
7
use
Bitrix\Main\Engine\Response\DataType\Page
;
8
use
Bitrix\Main\Error
;
9
use
Bitrix\Main\Localization\Loc
;
10
use
Bitrix\Sale\Result
;
11
12
class
PropertyGroups
extends
Controller
13
{
14
//region Actions
15
public
function
getFieldsAction
()
16
{
17
$entity = new \Bitrix\Sale\Rest\Entity\PropertyGroups();
18
return
[
'PROPERTY_GROUP'
=>$entity->prepareFieldInfos(
19
$entity->getFields()
20
)];
21
}
22
23
public
function
addAction
(array $fields)
24
{
25
global $APPLICATION;
26
27
$r =
new
Result
();
28
29
$propertyGroupId = 0;
30
$orderPropsGroup = new \CSaleOrderPropsGroup();
31
32
if
((
int
)$fields[
'PERSON_TYPE_ID'
]<=0)
33
$r->addError(
new
Error
(
Loc::getMessage
(
'CONTROLLER_ERROR_PERSON_TYPE_ID_FIELD_EMPTY'
),
'PERSON_TYPE_ID_FIELD_EMPTY'
));
34
if
(trim($fields[
'NAME'
])==
''
)
35
$r->addError(
new
Error
(
Loc::getMessage
(
'CONTROLLER_ERROR_PERSON_TYPE_ID_FIELD_EMPTY'
),
'NAME_FIELD_EMPTY'
));
36
37
if
($r->isSuccess())
38
{
39
$propertyGroupId = $orderPropsGroup->Add($fields);
40
if
((
int
)$propertyGroupId <= 0)
41
{
42
if
($ex = $APPLICATION->GetException())
43
$r->addError(
new
Error
($ex->GetString(), $ex->GetID()));
44
else
45
$r->addError(
new
Error
(
Loc::getMessage
(
'CONTROLLER_ERROR_ADD_PROPS_GROUP'
),
'ERROR_ADD_PROPS_GROUP'
));
46
}
47
}
48
49
if
(!$r->isSuccess())
50
{
51
$this->
addErrors
($r->getErrors());
52
return
null
;
53
}
54
else
55
return
[
'PROPERTY_GROUP'
=>$this->
get
($propertyGroupId)];
56
57
58
}
59
60
public
function
updateAction
($id, array $fields)
61
{
62
global $APPLICATION;
63
64
$orderPropsGroup = new \CSaleOrderPropsGroup();
65
66
$r = $this->
exists
($id);
67
if
($r->isSuccess())
68
{
69
if
(isset($fields[
'PERSON_TYPE_ID'
]))
70
unset($fields[
'PERSON_TYPE_ID'
]);
71
72
if
(!$orderPropsGroup->Update($id, $fields))
73
{
74
if
($ex = $APPLICATION->GetException())
75
$r->addError(
new
Error
($ex->GetString(), $ex->GetId()));
76
else
77
$r->addError(
new
Error
(
Loc::getMessage
(
'CONTROLLER_ERROR_UPDATE_PROPS_GROUP'
, [
'#ID#'
=>$id]),
'ERROR_UPDATE_PROPS_GROUP'
));
78
}
79
}
80
81
if
($r->isSuccess())
82
{
83
return
[
'PROPERTY_GROUP'
=>$this->
get
($id)];
84
}
85
else
86
{
87
$this->
addErrors
($r->getErrors());
88
return
null
;
89
}
90
}
91
92
public
function
deleteAction
($id)
93
{
94
global $APPLICATION;
95
96
$orderPropsGroup = new \CSaleOrderPropsGroup();
97
98
$r = $this->
exists
($id);
99
if
($r->isSuccess())
100
{
101
if
(!$orderPropsGroup->Delete($id))
102
{
103
if
($ex = $APPLICATION->GetException())
104
$r->addError(
new
Error
($ex->GetString(), $ex->GetId()));
105
else
106
$r->addError(
new
Error
(
Loc::getMessage
(
'CONTROLLER_ERROR_DELETE_PROPS_GROUP'
, [
'#ID#'
=>$id]),
'ERROR_DELETE_PROPS_GROUP'
));
107
}
108
}
109
110
if
($r->isSuccess())
111
{
112
return
true
;
113
}
114
else
115
{
116
$this->
addErrors
($r->getErrors());
117
return
null
;
118
}
119
}
120
121
public
function
getAction
($id)
122
{
123
$r = $this->
exists
($id);
124
if
($r->isSuccess())
125
{
126
return
[
'PROPERTY_GROUP'
=>$this->
get
($id)];
127
}
128
else
129
{
130
$this->
addErrors
($r->getErrors());
131
return
null
;
132
}
133
}
134
135
public
function
listAction
($select=[], $filter, $order=[], $start=0)
136
{
137
$result = [];
138
139
$orderPropsGroup = new \CSaleOrderPropsGroup();
140
141
$select = empty($select)? [
'*'
]:$select;
142
$order = empty($order)? [
'ID'
=>
'ASC'
]:$order;
143
144
$r = $orderPropsGroup->GetList($order, $filter,
false
, self::getNavData($start), $select);
145
while
($l = $r->fetch())
146
$result[] = $l;
147
148
return
new
Page
(
'PROPERTY_GROUPS'
, $result,
function
() use ($filter)
149
{
150
$orderPropsGroup = new \CSaleOrderPropsGroup();
151
152
$list = [];
153
$r = $orderPropsGroup->GetList([], $filter);
154
while
($l = $r->fetch())
155
$list[] = $l;
156
157
return
count($list);
158
});
159
}
160
//end region
161
162
protected
function
get
($propertyGroupId)
163
{
164
$orderPropsGroup = new \CSaleOrderPropsGroup();
165
166
return
$orderPropsGroup->GetById($propertyGroupId);
167
}
168
169
protected
function
exists
($id)
170
{
171
$r =
new
Result
();
172
if
($this->
get
($id)[
'ID'
]<=0)
173
$r->addError(
new
Error
(
Loc::getMessage
(
'CONTROLLER_ERROR_PROPS_GROUP_NOT_EXISTS'
, [
'#ID#'
=>$id]),
'PROPS_GROUP_NOT_EXISTS'
));
174
175
return
$r;
176
}
177
}
Bitrix\Main\DB\Result
Definition
result.php:19
Bitrix\Main\Engine\Controller\addErrors
addErrors(array $errors)
Definition
controller.php:1064
Bitrix\Main\Engine\Response\DataType\Page
Definition
page.php:8
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Sale\Controller\PropertyGroups
Definition
propertygroups.php:13
Bitrix\Sale\Controller\PropertyGroups\listAction
listAction($select=[], $filter, $order=[], $start=0)
Definition
propertygroups.php:135
Bitrix\Sale\Controller\PropertyGroups\exists
exists($id)
Definition
propertygroups.php:169
Bitrix\Sale\Controller\PropertyGroups\addAction
addAction(array $fields)
Definition
propertygroups.php:23
Bitrix\Sale\Controller\PropertyGroups\updateAction
updateAction($id, array $fields)
Definition
propertygroups.php:60
Bitrix\Sale\Controller\PropertyGroups\getFieldsAction
getFieldsAction()
Definition
propertygroups.php:15
Bitrix\Sale\Controller\PropertyGroups\deleteAction
deleteAction($id)
Definition
propertygroups.php:92
Bitrix\Sale\Controller\PropertyGroups\getAction
getAction($id)
Definition
propertygroups.php:121
Bitrix\Sale\Controller
Bitrix\Sender\Internals\QueryController
Definition
action.php:8
modules
sale
lib
controller
propertygroups.php
Создано системой
1.10.0