1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
propertyrelation.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\OrderPropsRelationTable;
11
use Bitrix\Sale\Result;
12
13
class
PropertyRelation
extends
ControllerBase
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
117
protected
function
getEntityTable
():
OrderPropsRelationTable
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
178
protected
function
checkModifyPermissionEntity
():
Result
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
}
Bitrix\Main\Error
Определения
error.php:15
Bitrix\Main\ORM\Data\DataManager\getRow
static getRow(array $parameters)
Определения
datamanager.php:398
Bitrix\Main\UI\PageNavigation
Определения
pagenavigation.php:27
Bitrix\Main\UI\PageNavigation\getLimit
getLimit()
Определения
pagenavigation.php:252
Bitrix\Main\UI\PageNavigation\getOffset
getOffset()
Определения
pagenavigation.php:239
Bitrix\Sale\Controller\ControllerBase
Определения
controllerbase.php:15
Bitrix\Sale\Controller\ControllerBase\getApplication
static getApplication()
Определения
controllerbase.php:39
Bitrix\Sale\Controller\PropertyRelation
Определения
propertyrelation.php:14
Bitrix\Sale\Controller\PropertyRelation\deleteByFilterAction
deleteByFilterAction($fields)
Определения
propertyrelation.php:70
Bitrix\Sale\Controller\PropertyRelation\checkModifyPermissionEntity
checkModifyPermissionEntity()
Определения
propertyrelation.php:178
Bitrix\Sale\Controller\PropertyRelation\existsProperty
existsProperty($id)
Определения
propertyrelation.php:162
Bitrix\Sale\Controller\PropertyRelation\checkReadPermissionEntity
checkReadPermissionEntity()
Определения
propertyrelation.php:190
Bitrix\Sale\Controller\PropertyRelation\addAction
addAction(array $fields)
Определения
propertyrelation.php:26
Bitrix\Sale\Controller\PropertyRelation\getEntityTable
getEntityTable()
Определения
propertyrelation.php:117
Bitrix\Sale\Controller\PropertyRelation\existsByFilter
existsByFilter($filter)
Определения
propertyrelation.php:122
Bitrix\Sale\Controller\PropertyRelation\getFieldsAction
getFieldsAction()
Определения
propertyrelation.php:16
Bitrix\Sale\Controller\PropertyRelation\listAction
listAction(PageNavigation $pageNavigation, array $select=[], array $filter=[], array $order=[])
Определения
propertyrelation.php:95
Bitrix\Sale\Controller\PropertyRelation\checkFields
checkFields($fields)
Определения
propertyrelation.php:133
Bitrix\Sale\Controller\PropertyRelation\checkPermissionEntity
checkPermissionEntity($name, $arguments=[])
Определения
propertyrelation.php:149
Bitrix\Sale\Internals\OrderPropsRelationTable
Определения
orderprops_relation.php:29
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$res
$res
Определения
filter_act.php:7
$select
$select
Определения
iblock_catalog_list.php:194
$filter
$filter
Определения
iblock_catalog_list.php:54
$name
$name
Определения
menu_edit.php:35
Bitrix\Main\Page
Определения
aliases.php:54
Bitrix\Sale\Discount\Result
Определения
compatibleformat.php:2
$order
$order
Определения
payment.php:8
$saleModulePermissions
$saleModulePermissions
Определения
tools.php:21
$items
$items
Определения
template.php:224
$fields
$fields
Определения
yandex_run.php:501
bitrix
modules
sale
lib
controller
propertyrelation.php
Создано системой
1.14.0