Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
propertygroup.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
PropertyGroup
extends
ControllerBase
13
{
14
//region Actions
15
public
function
getFieldsAction
()
16
{
17
$view = $this->getViewManager()
18
->getView($this);
19
20
return
[
'PROPERTY_GROUP'
=>$view->prepareFieldInfos(
21
$view->getFields()
22
)];
23
}
24
25
public
function
addAction
(array $fields)
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'
), 200950000001));
34
if
(trim($fields[
'NAME'
])==
''
)
35
$r->addError(
new
Error
(
Loc::getMessage
(
'CONTROLLER_ERROR_PERSON_TYPE_ID_FIELD_EMPTY'
), 200950000002));
36
37
if
($r->isSuccess())
38
{
39
$propertyGroupId = $orderPropsGroup->Add($fields);
40
if
((
int
)$propertyGroupId <= 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
(
Loc::getMessage
(
'CONTROLLER_ERROR_ADD_PROPS_GROUP'
), 200950000003));
49
}
50
}
51
}
52
53
if
(!$r->isSuccess())
54
{
55
foreach
($r->getErrors() as $error)
56
{
57
$this->addError(
new
Error
($error->getMessage(), 200950000006));
58
}
59
return
null
;
60
}
61
else
62
return
[
'PROPERTY_GROUP'
=>$this->
get
($propertyGroupId)];
63
}
64
65
public
function
updateAction
($id, array $fields)
66
{
67
$orderPropsGroup = new \CSaleOrderPropsGroup();
68
69
$r = $this->
exists
($id);
70
if
($r->isSuccess())
71
{
72
if
(isset($fields[
'PERSON_TYPE_ID'
]))
73
unset($fields[
'PERSON_TYPE_ID'
]);
74
75
if
(!$orderPropsGroup->Update($id, $fields))
76
{
77
if
($ex = self::getApplication()->GetException())
78
{
79
self::getApplication
()->ResetException();
80
self::getApplication
()->ThrowException($ex->GetString(), 200950000008);
81
82
$r->addError(
new
Error
($ex->GetString(), $ex->GetID()));
83
}
84
else
85
$r->addError(
new
Error
(
Loc::getMessage
(
'CONTROLLER_ERROR_UPDATE_PROPS_GROUP'
, [
'#ID#'
=>$id]), 200950000004));
86
}
87
}
88
89
if
($r->isSuccess())
90
{
91
return
[
'PROPERTY_GROUP'
=>$this->
get
($id)];
92
}
93
else
94
{
95
$this->addErrors($r->getErrors());
96
return
null
;
97
}
98
}
99
100
public
function
deleteAction
($id)
101
{
102
$orderPropsGroup = new \CSaleOrderPropsGroup();
103
104
$r = $this->
exists
($id);
105
if
($r->isSuccess())
106
{
107
if
(!$orderPropsGroup->Delete($id))
108
{
109
if
($ex = self::getApplication()->GetException())
110
{
111
$r->addError(
new
Error
($ex->GetString(), $ex->GetID()));
112
}
113
else
114
$r->addError(
new
Error
(
Loc::getMessage
(
'CONTROLLER_ERROR_DELETE_PROPS_GROUP'
, [
'#ID#'
=>$id]),200950000005));
115
}
116
}
117
118
if
($r->isSuccess())
119
{
120
return
true
;
121
}
122
else
123
{
124
$this->addErrors($r->getErrors());
125
return
null
;
126
}
127
}
128
129
public
function
getAction
($id)
130
{
131
$r = $this->
exists
($id);
132
if
($r->isSuccess())
133
{
134
return
[
'PROPERTY_GROUP'
=>$this->
get
($id)];
135
}
136
else
137
{
138
$this->addErrors($r->getErrors());
139
return
null
;
140
}
141
}
142
143
public
function
listAction
($select=[], $filter=[], $order=[], $start=0)
144
{
145
$result = [];
146
147
$orderPropsGroup = new \CSaleOrderPropsGroup();
148
149
$select = empty($select)? [
'*'
]:$select;
150
$order = empty($order)? [
'ID'
=>
'ASC'
]:$order;
151
152
$r = $orderPropsGroup->GetList($order, $filter,
false
, self::getNavData($start), $select);
153
while
($l = $r->fetch())
154
$result[] = $l;
155
156
return
new
Page
(
'PROPERTY_GROUPS'
, $result,
function
() use ($filter)
157
{
158
return
(
int
) \CSaleOrderPropsGroup::GetList([], $filter, []);
159
});
160
}
161
//end region
162
163
protected
function
get
($propertyGroupId)
164
{
165
$orderPropsGroup = new \CSaleOrderPropsGroup();
166
167
return
$orderPropsGroup->GetById($propertyGroupId);
168
}
169
170
protected
function
exists
($id)
171
{
172
$r =
new
Result
();
173
if
($this->
get
($id)[
'ID'
]<=0)
174
$r->addError(
new
Error
(
'property group is not exists'
, 200940400001));
175
176
return
$r;
177
}
178
179
protected
function
checkModifyPermissionEntity
()
180
{
181
$r =
new
Result
();
182
183
$saleModulePermissions =
self::getApplication
()->GetGroupRight(
"sale"
);
184
if
($saleModulePermissions <
"W"
)
185
{
186
$r->addError(
new
Error
(
'Access Denied'
, 200040300020));
187
}
188
return
$r;
189
}
190
191
protected
function
checkReadPermissionEntity
()
192
{
193
$r =
new
Result
();
194
195
$saleModulePermissions =
self::getApplication
()->GetGroupRight(
"sale"
);
196
if
($saleModulePermissions ==
"D"
)
197
{
198
$r->addError(
new
Error
(
'Access Denied'
, 200040300010));
199
}
200
return
$r;
201
}
202
}
Bitrix\Main\DB\Result
Definition
result.php:19
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\ControllerBase
Definition
controllerbase.php:15
Bitrix\Sale\Controller\ControllerBase\getApplication
static getApplication()
Definition
controllerbase.php:39
Bitrix\Sale\Controller\PropertyGroup
Definition
propertygroup.php:13
Bitrix\Sale\Controller\PropertyGroup\checkModifyPermissionEntity
checkModifyPermissionEntity()
Definition
propertygroup.php:179
Bitrix\Sale\Controller\PropertyGroup\checkReadPermissionEntity
checkReadPermissionEntity()
Definition
propertygroup.php:191
Bitrix\Sale\Controller\PropertyGroup\exists
exists($id)
Definition
propertygroup.php:170
Bitrix\Sale\Controller\PropertyGroup\addAction
addAction(array $fields)
Definition
propertygroup.php:25
Bitrix\Sale\Controller\PropertyGroup\updateAction
updateAction($id, array $fields)
Definition
propertygroup.php:65
Bitrix\Sale\Controller\PropertyGroup\getFieldsAction
getFieldsAction()
Definition
propertygroup.php:15
Bitrix\Sale\Controller\PropertyGroup\deleteAction
deleteAction($id)
Definition
propertygroup.php:100
Bitrix\Sale\Controller\PropertyGroup\getAction
getAction($id)
Definition
propertygroup.php:129
Bitrix\Sale\Controller\PropertyGroup\listAction
listAction($select=[], $filter=[], $order=[], $start=0)
Definition
propertygroup.php:143
Bitrix\Sale\Controller
modules
sale
lib
controller
propertygroup.php
Создано системой
1.10.0