Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
usergrouprestriction.php
1
<?php
2
namespace
Bitrix\Sale\Services\Base
;
3
4
use
Bitrix\Main\GroupTable
;
5
use
Bitrix\Main\Localization\Loc
;
6
use
Bitrix\Main\NotImplementedException
;
7
use
Bitrix\Sale\Internals\Entity
;
8
use
Bitrix\Sale\Internals\UserGroupRestrictionTable
;
9
use
Bitrix\Sale\Order
;
10
11
Loc::loadMessages
(__FILE__);
12
18
class
UserGroupRestriction
extends
Restriction
19
{
20
public
static
$easeSort
= 200;
21
25
public
static
function
getClassTitle
()
26
{
27
return
Loc::getMessage
(
"SALE_SRV_RSTR_BY_UG_NAME"
);
28
}
29
33
public
static
function
getClassDescription
()
34
{
35
return
Loc::getMessage
(
"SALE_SRV_RSTR_BY_UG_DESC"
);
36
}
37
38
public
static
function
getOnApplyErrorMessage
(): string
39
{
40
return
Loc::getMessage
(
'SALE_SRV_RSTR_BY_UG_ON_APPLY_ERROR_MSG'
);
41
}
42
49
public
static
function
check
($groups, array $restrictionParams, $entityId = 0)
50
{
51
if
(intval($entityId) <= 0)
52
return
true
;
53
54
if
(empty($groups) <= 0)
55
return
false
;
56
57
$commonGroups = array_intersect($groups, $restrictionParams[
'GROUP_IDS'
]);
58
return
!empty($commonGroups);
59
}
60
66
protected
static
function
getOrder
(
Entity
$entity)
67
{
68
throw
new
NotImplementedException
(
'Method '
.__METHOD__.
' must be overload'
);
69
}
70
75
protected
static
function
getEntityTypeId
()
76
{
77
throw
new
NotImplementedException
(
'Method '
.__METHOD__.
' must be overload'
);
78
}
79
84
protected
static
function
extractParams
(
Entity
$entity)
85
{
86
$result = [];
87
88
if
($order = static::getOrder($entity))
89
{
90
$result = \Bitrix\Main\UserTable::getUserGroupIds($order->getUserId());
91
}
92
93
return
$result;
94
}
95
99
protected
static
function
prepareParamsForSaving
(array $params = array(), $entityId = 0)
100
{
101
$entityId = (int)$entityId;
102
$entityTypeId = (int)static::getEntityTypeId();
103
UserGroupRestrictionTable::deleteByEntity
($entityTypeId, $entityId);
104
105
if
(is_array($params[
'GROUP_IDS'
]) && !empty($params[
'GROUP_IDS'
]))
106
{
107
foreach
($params[
'GROUP_IDS'
] as $groupId)
108
{
109
UserGroupRestrictionTable::add
([
110
'ENTITY_TYPE_ID'
=> $entityTypeId,
111
'ENTITY_ID'
=> $entityId,
112
'GROUP_ID'
=> (
int
)$groupId
113
]);
114
}
115
}
116
117
return
[];
118
}
119
120
protected
static
function
getUserGroups
()
121
{
122
$result = [];
123
$res = GroupTable::getList([
124
'filter'
=> [
'ACTIVE'
=>
'Y'
],
125
'order'
=> [
'NAME'
=>
'ASC'
]
126
]);
127
128
while
($group = $res->fetch())
129
{
130
$result[$group[
'ID'
]] = $group[
'NAME'
];
131
}
132
133
return
$result;
134
}
135
136
public
static
function
getParamsStructure
($entityId = 0)
137
{
138
return
array(
139
"GROUP_IDS"
=> array(
140
"TYPE"
=>
"ENUM"
,
141
'MULTIPLE'
=>
'Y'
,
142
"LABEL"
=>
Loc::getMessage
(
"SALE_SRV_RSTR_BY_UG_LIST"
),
143
"OPTIONS"
=> static::getUserGroups()
144
)
145
);
146
}
147
148
public
static
function
prepareParamsValues
(array $paramsValues, $entityId = 0)
149
{
150
$result = [];
151
152
$res =
UserGroupRestrictionTable::getList
([
'filter'
=> [
153
'=ENTITY_TYPE_ID'
=> static::getEntityTypeId(),
154
'=ENTITY_ID'
=> $entityId
155
]]);
156
157
while
($row = $res->fetch())
158
{
159
$result[] = $row[
'GROUP_ID'
];
160
}
161
162
return
array(
"GROUP_IDS"
=> $result);
163
}
164
165
public
static
function
save
(array $fields, $restrictionId = 0)
166
{
167
$fields[
"PARAMS"
] = static::prepareParamsForSaving($fields[
"PARAMS"
], $fields[
"SERVICE_ID"
]);
168
return
parent::save($fields, $restrictionId);
169
}
170
171
public
static
function
delete
($restrictionId, $entityId = 0)
172
{
173
UserGroupRestrictionTable::deleteByEntity
(static::getEntityTypeId(), $entityId);
174
return
parent::delete($restrictionId);
175
}
176
182
public
static
function
filterServicesArray
(
Entity
$entity, array $restrictionFields)
183
{
184
if
(empty($restrictionFields))
185
return
[];
186
187
$groups = static::extractParams($entity);
188
189
if
(empty($groups))
190
{
191
return
[];
192
}
193
194
$entityIds = array_keys($restrictionFields);
195
196
$res =
UserGroupRestrictionTable::getList
(array(
197
'filter'
=> array(
198
'=ENTITY_TYPE_ID'
=> static::getEntityTypeId(),
199
'=ENTITY_ID'
=> $entityIds,
200
'=GROUP_ID'
=> $groups
201
)
202
));
203
204
$result = [];
205
206
while
($row = $res->fetch())
207
{
208
if
(!isset($result[$row[
'ENTITY_ID'
]]))
209
{
210
$result[$row[
'ENTITY_ID'
]] =
true
;
211
}
212
}
213
214
return
array_keys($result);
215
}
216
217
public
static
function
isAvailable
()
218
{
219
return
true
;
220
}
221
}
Bitrix\Catalog\Model\Entity
Definition
entity.php:12
Bitrix\Main\GroupTable
Definition
group.php:29
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\NotImplementedException
Definition
exception.php:147
Bitrix\Main\ORM\Data\DataManager\getList
static getList(array $parameters=array())
Definition
datamanager.php:441
Bitrix\Main\ORM\Data\DataManager\add
static add(array $data)
Definition
datamanager.php:874
Bitrix\Main\ORM\Entity
Definition
entity.php:26
Bitrix\Sale\Helpers\Order
Definition
order.php:10
Bitrix\Sale\Internals\UserGroupRestrictionTable
Definition
usergrouprestriction.php:38
Bitrix\Sale\Internals\UserGroupRestrictionTable\deleteByEntity
static deleteByEntity($entityType, $entityId)
Definition
usergrouprestriction.php:79
Bitrix\Sale\Services\Base\Restriction
Definition
restriction.php:17
Bitrix\Sale\Services\Base\UserGroupRestriction
Definition
usergrouprestriction.php:19
Bitrix\Sale\Services\Base\UserGroupRestriction\getEntityTypeId
static getEntityTypeId()
Definition
usergrouprestriction.php:75
Bitrix\Sale\Services\Base\UserGroupRestriction\extractParams
static extractParams(Entity $entity)
Definition
usergrouprestriction.php:84
Bitrix\Sale\Services\Base\UserGroupRestriction\prepareParamsValues
static prepareParamsValues(array $paramsValues, $entityId=0)
Definition
usergrouprestriction.php:148
Bitrix\Sale\Services\Base\UserGroupRestriction\prepareParamsForSaving
static prepareParamsForSaving(array $params=array(), $entityId=0)
Definition
usergrouprestriction.php:99
Bitrix\Sale\Services\Base\UserGroupRestriction\$easeSort
static $easeSort
Definition
usergrouprestriction.php:20
Bitrix\Sale\Services\Base\UserGroupRestriction\getClassTitle
static getClassTitle()
Definition
usergrouprestriction.php:25
Bitrix\Sale\Services\Base\UserGroupRestriction\isAvailable
static isAvailable()
Definition
usergrouprestriction.php:217
Bitrix\Sale\Services\Base\UserGroupRestriction\save
static save(array $fields, $restrictionId=0)
Definition
usergrouprestriction.php:165
Bitrix\Sale\Services\Base\UserGroupRestriction\getClassDescription
static getClassDescription()
Definition
usergrouprestriction.php:33
Bitrix\Sale\Services\Base\UserGroupRestriction\filterServicesArray
static filterServicesArray(Entity $entity, array $restrictionFields)
Definition
usergrouprestriction.php:182
Bitrix\Sale\Services\Base\UserGroupRestriction\getOrder
static getOrder(Entity $entity)
Definition
usergrouprestriction.php:66
Bitrix\Sale\Services\Base\UserGroupRestriction\getOnApplyErrorMessage
static getOnApplyErrorMessage()
Definition
usergrouprestriction.php:38
Bitrix\Sale\Services\Base\UserGroupRestriction\getParamsStructure
static getParamsStructure($entityId=0)
Definition
usergrouprestriction.php:136
Bitrix\Sale\Services\Base\UserGroupRestriction\getUserGroups
static getUserGroups()
Definition
usergrouprestriction.php:120
Bitrix\Sale\Services\Base\UserGroupRestriction\check
static check($groups, array $restrictionParams, $entityId=0)
Definition
usergrouprestriction.php:49
Bitrix\Sale\Services\Base
Definition
concreteproductrestriction.php:3
modules
sale
lib
services
base
usergrouprestriction.php
Создано системой
1.10.0