Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
roledealcategoryservice.php
1
<?php
2
namespace
Bitrix\Sender\Access\Service
;
3
4
use
Bitrix\Main
;
5
use
Bitrix\Main\ArgumentException
;
6
use
Bitrix\Main\DB\SqlQueryException
;
7
use
Bitrix\Main\Localization\Loc
;
8
use
Bitrix\Main\ObjectPropertyException
;
9
use
Bitrix\Main\SystemException
;
10
use
Bitrix\Sender\Access\AccessController
;
11
use
Bitrix\Sender\Access\ActionDictionary
;
12
use
Bitrix\Sender\Access\Permission\PermissionDictionary
;
13
use
Bitrix\Sender\Access\Role\RoleUtil
;
14
use
Bitrix\Sender\Access\Permission\PermissionTable
;
15
use
Bitrix\Sender\Access\Role\RoleTable
;
16
use
Bitrix\Main\ORM\Fields\Relations\Reference
;
17
use
Bitrix\Main\ORM\Query\Join
;
18
19
Loc::loadMessages
(__FILE__);
20
21
class
RoleDealCategoryService
implements
RoleDealCategoryServiceInterface
22
{
23
public
const
ALL_CATEGORIES
= -1;
27
private
$rolePermissionService;
32
public
function
__construct
()
33
{
34
$this->rolePermissionService =
new
RolePermissionService
();
35
}
36
44
public
function
getAbleDealCategories
(
int
$userId): array
45
{
46
return
PermissionTable::query()
47
->registerRuntimeField(
'role'
,
48
(
new
Reference
(
'role'
,RoleTable::class, Join::on(
'this.ROLE_ID'
,
'ref.ID'
)))
49
->configureJoinType(Join::TYPE_INNER)
50
)
51
->setDistinct()
52
->setSelect([
'CATEGORY_ID'
=>
'role.DEAL_CATEGORY_ID'
])
53
->where(
'PERMISSION_ID'
, PermissionDictionary::SEGMENT_CLIENT_OWN_CATEGORY)
54
->where(
'VALUE'
, PermissionDictionary::VALUE_YES)
55
->whereIn(
'ROLE_ID'
, $this->rolePermissionService->getRoleListByUser($userId))
56
->fetchAll();
57
}
58
66
public
function
getFilteredDealCategories
(
int
$userId, array $categories): array
67
{
68
$ableDealCategories = $this->
getAbleDealCategories
($userId);
69
$dealCategories = [];
70
71
$this->accessController =
new
AccessController
($userId);
72
$allowAll = $this->accessController->isAdmin();
73
74
$dealCategories[
''
] = $categories[
''
]??
Loc::getMessage
(
'SENDER_DEAL_CATEGORY_WITHOUT_DEAL_PREP_MSG_1'
);
75
foreach
($ableDealCategories as $ableDealCategory)
76
{
77
if
((
int
)$ableDealCategory[
'CATEGORY_ID'
] === self::ALL_CATEGORIES)
78
{
79
$allowAll =
true
;
80
break
;
81
}
82
}
83
84
if
(!$allowAll)
85
{
86
foreach
($ableDealCategories as $ableDealCategory)
87
{
88
$dealCategories[$ableDealCategory[
'CATEGORY_ID'
]] = $categories[$ableDealCategory[
'CATEGORY_ID'
]];
89
}
90
return
$dealCategories;
91
}
92
93
return
$dealCategories + $categories;
94
}
95
96
106
public
function
fillDefaultDealCategoryPermission
(
int
$dealCategoryId): array
107
{
108
$query = [];
109
$map = RoleUtil::preparedRoleMap();
110
111
$managerRoleId =
null
;
112
$adminRoleId =
null
;
113
foreach
($map as $roleKey => $permissions)
114
{
115
$roleName = RoleUtil::getLocalizedName($roleKey);
116
117
$roleId = $this->rolePermissionService->saveRole($roleName, $dealCategoryId);
118
$query = array_merge($query, RoleUtil::buildInsertPermissionQuery($permissions, $roleId));
119
120
if
($roleKey ===
'MANAGER'
)
121
{
122
$managerRoleId = $roleId;
123
}
124
125
if
($roleKey ===
'ADMIN'
)
126
{
127
$adminRoleId = $roleId;
128
}
129
}
130
131
RoleUtil::insertPermissions($query);
132
(
new
RoleRelationService
())->saveRoleRelation([
133
[
134
'id'
=> $managerRoleId,
135
'accessCodes'
=> [
136
'AE0'
=>
'usergroups'
137
],
138
],
139
[
140
'id'
=> $adminRoleId,
141
'accessCodes'
=> [
142
'G1'
=>
''
143
],
144
],
145
]);
146
147
return
$this->rolePermissionService->getRoleList(
148
[
149
150
"filter"
=> [
"=DEAL_CATEGORY_ID"
=> $dealCategoryId]
151
]
152
);
153
}
154
}
Bitrix\Main\ArgumentException
Definition
exception.php:34
Bitrix\Main\DB\SqlQueryException
Definition
sqlexception.php:24
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\ORM\Fields\Relations\Reference
Definition
reference.php:26
Bitrix\Main\ORM\Query\Join
Definition
join.php:19
Bitrix\Main\ObjectPropertyException
Definition
exception.php:181
Bitrix\Main\SystemException
Definition
exception.php:8
Bitrix\Sender\Access\AccessController
Definition
accesscontroller.php:19
Bitrix\Sender\Access\ActionDictionary
Definition
actiondictionary.php:18
Bitrix\Sender\Access\Permission\PermissionDictionary
Definition
permissiondictionary.php:12
Bitrix\Sender\Access\Permission\PermissionTable
Definition
permission.php:33
Bitrix\Sender\Access\Role\RoleTable
Definition
role.php:31
Bitrix\Sender\Access\Role\RoleUtil
Definition
roleutil.php:20
Bitrix\Sender\Access\Service\RoleDealCategoryService
Definition
roledealcategoryservice.php:22
Bitrix\Sender\Access\Service\RoleDealCategoryService\__construct
__construct()
Definition
roledealcategoryservice.php:32
Bitrix\Sender\Access\Service\RoleDealCategoryService\ALL_CATEGORIES
const ALL_CATEGORIES
Definition
roledealcategoryservice.php:23
Bitrix\Sender\Access\Service\RoleDealCategoryService\getFilteredDealCategories
getFilteredDealCategories(int $userId, array $categories)
Definition
roledealcategoryservice.php:66
Bitrix\Sender\Access\Service\RoleDealCategoryService\getAbleDealCategories
getAbleDealCategories(int $userId)
Definition
roledealcategoryservice.php:44
Bitrix\Sender\Access\Service\RoleDealCategoryService\fillDefaultDealCategoryPermission
fillDefaultDealCategoryPermission(int $dealCategoryId)
Definition
roledealcategoryservice.php:106
Bitrix\Sender\Access\Service\RolePermissionService
Definition
rolepermissionservice.php:20
Bitrix\Sender\Access\Service\RoleRelationService
Definition
rolerelationservice.php:10
Bitrix\Sender\Access\Service\RoleDealCategoryServiceInterface
Definition
roledealcategoryserviceinterface.php:7
Bitrix\Main
Bitrix\Sender\Access\Service
Definition
roledealcategoryservice.php:2
modules
sender
lib
access
service
roledealcategoryservice.php
Создано системой
1.10.0