Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
businessvaluepersondomain.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\UI\PageNavigation
;
10
use
Bitrix\Sale\Internals\BusinessValuePersonDomainTable
;
11
use
Bitrix\Sale\Result
;
12
13
class
BusinessValuePersonDomain
extends
ControllerBase
14
{
15
//region Actions
16
public
function
getFieldsAction
()
17
{
18
$view = $this->getViewManager()
19
->getView($this);
20
21
return
[
'BUSINESS_VALUE_PERSON_DOMAIN'
=>$view->prepareFieldInfos(
22
$view->getFields()
23
)];
24
}
25
26
public
function
listAction
(
PageNavigation
$pageNavigation, array $select = [], array $filter = [], array $order = []):
Page
27
{
28
$select = empty($select) ? [
'*'
] : $select;
29
$order = empty($order) ? [
'PERSON_TYPE_ID'
=>
'ASC'
] : $order;
30
31
$items = BusinessValuePersonDomainTable::getList(
32
[
33
'select'
=> $select,
34
'filter'
=> $filter,
35
'order'
=> $order,
36
'offset'
=> $pageNavigation->
getOffset
(),
37
'limit'
=> $pageNavigation->
getLimit
(),
38
]
39
)->fetchAll();
40
41
return
new
Page
(
'BUSINESS_VALUE_PERSON_DOMAINS'
, $items,
function
() use ($filter)
42
{
43
return
BusinessValuePersonDomainTable::getCount([$filter]);
44
});
45
}
46
47
public
function
addAction
(array $fields)
48
{
49
$result =
new
Result
();
50
51
$personTypeId = $fields[
'PERSON_TYPE_ID'
];
52
$domain = $fields[
'DOMAIN'
];
53
54
$r = $this->
personTypeExists
($personTypeId);
55
56
if
($r->isSuccess())
57
{
58
$r = $this->
exists
($personTypeId);
59
if
($r->isSuccess())
60
{
61
$result->addError(
new
Error
(
'Duplicate entry for key [personTypeId]'
, 201450000001));
62
}
63
else
64
{
65
BusinessValuePersonDomainTable::add(array(
66
'PERSON_TYPE_ID'
=> $personTypeId,
67
'DOMAIN'
=> $domain,
68
));
69
}
70
}
71
else
72
{
73
$result->addErrors($r->getErrors());
74
}
75
76
if
($result->isSuccess())
77
{
78
return
[
79
'BUSINESS_VALUE_PERSON_DOMAIN'
=>BusinessValuePersonDomainTable::getList([
'filter'
=>[
80
'PERSON_TYPE_ID'
=>$personTypeId,
81
'DOMAIN'
=>$domain
82
]])->fetchAll()[0]
83
];
84
}
85
else
86
{
87
$this->addErrors($result->getErrors());
88
return
null
;
89
}
90
}
91
93
public
function
getAction
($personTypeId)
94
{
95
$r = $this->
exists
($personTypeId);
96
if
($r->isSuccess())
97
{
98
return
[
'BUSINESS_VALUE_PERSON_DOMAIN'
=>$this->
get
($personTypeId)];
99
}
100
else
101
{
102
$this->addErrors($r->getErrors());
103
return
null
;
104
}
105
}
106
108
public
function
deleteAction
($personTypeId)
109
{
110
$r = $this->
exists
($personTypeId);
111
if
($r->isSuccess())
112
{
113
\Bitrix\Sale\Internals\BusinessValuePersonDomainTable::deleteByPersonTypeId((
int
)$personTypeId);
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
deleteByFilterAction
($fields)
128
{
129
$r = $this->
checkFields
($fields);
130
131
if
($r->isSuccess())
132
{
133
$r = $this->
existsByFilter
([
134
'PERSON_TYPE_ID'
=>$fields[
'PERSON_TYPE_ID'
],
135
'DOMAIN'
=>$fields[
'DOMAIN'
]
136
]);
137
if
($r->isSuccess())
138
{
139
$r = BusinessValuePersonDomainTable::delete([
'PERSON_TYPE_ID'
=>$fields[
'PERSON_TYPE_ID'
],
'DOMAIN'
=>$fields[
'DOMAIN'
]]);
140
}
141
}
142
143
if
($r->isSuccess())
144
{
145
return
true
;
146
}
147
else
148
{
149
$this->addErrors($r->getErrors());
150
return
null
;
151
}
152
}
153
//endregion
154
155
protected
function
getPersonType
($id)
156
{
157
$r = \Bitrix\Sale\PersonType::getList([
'filter'
=>[
'ID'
=>$id]])->fetchAll();
158
return
$r? $r[0]:[];
159
}
160
161
protected
function
personTypeExists
($id)
162
{
163
$r =
new
Result
();
164
if
($this->
getPersonType
($id)[
'ID'
]<=0)
165
$r->addError(
new
Error
(
'person type is not exists'
, 201440400002));
166
167
return
$r;
168
}
169
170
protected
function
get
($personTypeId)
171
{
172
$r = BusinessValuePersonDomainTable::getList([
'filter'
=>[
'PERSON_TYPE_ID'
=>$personTypeId]])->fetchAll();
173
return
$r? $r[0]:[];
174
}
175
176
protected
function
exists
($personTypeId)
177
{
178
$r =
new
Result
();
179
if
($this->
get
($personTypeId)[
'PERSON_TYPE_ID'
]<=0)
180
$r->addError(
new
Error
(
'business value person domain is not exists'
, 201440400001));
181
182
return
$r;
183
}
184
185
protected
function
existsByFilter
($filter)
186
{
187
$r =
new
Result
();
188
189
$row = BusinessValuePersonDomainTable::getList([
'filter'
=>[
'PERSON_TYPE_ID'
=>$filter[
'PERSON_TYPE_ID'
],
'DOMAIN'
=>$filter[
'DOMAIN'
]]])->fetchAll();
190
if
(isset($row[0][
'PERSON_TYPE_ID'
]) ==
false
)
191
$r->addError(
new
Error
(
'business value person domain is not exists'
, 201440400003));
192
193
return
$r;
194
}
195
196
protected
function
checkFields
($fields)
197
{
198
$r =
new
Result
();
199
200
if
(isset($fields[
'PERSON_TYPE_ID'
]) ==
false
&& $fields[
'PERSON_TYPE_ID'
] <>
''
)
201
$r->addError(
new
Error
(
'personTypeId - parametrs is empty'
, 201450000002));
202
203
if
(isset($fields[
'DOMAIN'
]) ==
false
&& $fields[
'DOMAIN'
] <>
''
)
204
$r->addError(
new
Error
(
'domian - parametrs is empty'
, 201450000003));
205
206
return
$r;
207
}
208
209
protected
function
checkPermissionEntity
($name, $arguments = [])
210
{
211
if
($name ==
'deletebyfilter'
)
212
{
213
$r = $this->
checkModifyPermissionEntity
();
214
}
215
else
216
{
217
$r = parent::checkPermissionEntity($name);
218
}
219
return
$r;
220
}
221
222
protected
function
checkModifyPermissionEntity
()
223
{
224
$r =
new
Result
();
225
226
$saleModulePermissions =
self::getApplication
()->GetGroupRight(
"sale"
);
227
if
($saleModulePermissions <
"W"
)
228
{
229
$r->addError(
new
Error
(
'Access Denied'
, 200040300020));
230
}
231
return
$r;
232
}
233
234
protected
function
checkReadPermissionEntity
()
235
{
236
$r =
new
Result
();
237
238
$saleModulePermissions =
self::getApplication
()->GetGroupRight(
"sale"
);
239
if
($saleModulePermissions ==
"D"
)
240
{
241
$r->addError(
new
Error
(
'Access Denied'
, 200040300010));
242
}
243
return
$r;
244
}
245
}
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\UI\PageNavigation
Definition
pagenavigation.php:27
Bitrix\Main\UI\PageNavigation\getLimit
getLimit()
Definition
pagenavigation.php:247
Bitrix\Main\UI\PageNavigation\getOffset
getOffset()
Definition
pagenavigation.php:234
Bitrix\Sale\Controller\BusinessValuePersonDomain
Definition
businessvaluepersondomain.php:14
Bitrix\Sale\Controller\BusinessValuePersonDomain\deleteByFilterAction
deleteByFilterAction($fields)
Definition
businessvaluepersondomain.php:127
Bitrix\Sale\Controller\BusinessValuePersonDomain\checkModifyPermissionEntity
checkModifyPermissionEntity()
Definition
businessvaluepersondomain.php:222
Bitrix\Sale\Controller\BusinessValuePersonDomain\checkReadPermissionEntity
checkReadPermissionEntity()
Definition
businessvaluepersondomain.php:234
Bitrix\Sale\Controller\BusinessValuePersonDomain\exists
exists($personTypeId)
Definition
businessvaluepersondomain.php:176
Bitrix\Sale\Controller\BusinessValuePersonDomain\addAction
addAction(array $fields)
Definition
businessvaluepersondomain.php:47
Bitrix\Sale\Controller\BusinessValuePersonDomain\personTypeExists
personTypeExists($id)
Definition
businessvaluepersondomain.php:161
Bitrix\Sale\Controller\BusinessValuePersonDomain\getPersonType
getPersonType($id)
Definition
businessvaluepersondomain.php:155
Bitrix\Sale\Controller\BusinessValuePersonDomain\existsByFilter
existsByFilter($filter)
Definition
businessvaluepersondomain.php:185
Bitrix\Sale\Controller\BusinessValuePersonDomain\getFieldsAction
getFieldsAction()
Definition
businessvaluepersondomain.php:16
Bitrix\Sale\Controller\BusinessValuePersonDomain\deleteAction
deleteAction($personTypeId)
Definition
businessvaluepersondomain.php:108
Bitrix\Sale\Controller\BusinessValuePersonDomain\listAction
listAction(PageNavigation $pageNavigation, array $select=[], array $filter=[], array $order=[])
Definition
businessvaluepersondomain.php:26
Bitrix\Sale\Controller\BusinessValuePersonDomain\getAction
getAction($personTypeId)
Definition
businessvaluepersondomain.php:93
Bitrix\Sale\Controller\BusinessValuePersonDomain\checkFields
checkFields($fields)
Definition
businessvaluepersondomain.php:196
Bitrix\Sale\Controller\BusinessValuePersonDomain\checkPermissionEntity
checkPermissionEntity($name, $arguments=[])
Definition
businessvaluepersondomain.php:209
Bitrix\Sale\Controller\ControllerBase
Definition
controllerbase.php:15
Bitrix\Sale\Controller\ControllerBase\getApplication
static getApplication()
Definition
controllerbase.php:39
Bitrix\Sale\Internals\BusinessValuePersonDomainTable
Definition
businessvalue_persondomain.php:24
Bitrix\Sale\Controller
modules
sale
lib
controller
businessvaluepersondomain.php
Создано системой
1.10.0