Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
usermodel.php
1
<?php
9
namespace
Bitrix\Main\Access\User
;
10
11
use
Bitrix\Main\Access\AccessCode
;
12
use
Bitrix\Main\UserAccessTable
;
13
use
Bitrix\Main\UserTable
;
14
use
Bitrix\Main\Engine\CurrentUser
;
15
16
abstract
class
UserModel
17
implements
AccessibleUser
18
{
19
protected
20
$userId
,
21
$name
,
22
$roles
,
23
$userDepartments
,
24
$isAdmin
,
25
$accessCodes
;
26
27
protected
static
$cache
= [];
28
29
public
static
function
createFromId
(
int
$userId
):
AccessibleUser
30
{
31
$key =
'USER_'
.static::class.
'_'
.
$userId
;
32
if
(!array_key_exists($key, static::$cache))
33
{
34
$model =
new
static
();
35
$model->
setUserId
(
$userId
);
36
static::$cache[$key] = $model;
37
}
38
return
static::$cache[$key];
39
}
40
41
protected
function
__construct
()
42
{
43
}
44
45
public
function
getUserId
(): int
46
{
47
return
$this->userId
;
48
}
49
50
public
function
setUserId
(
int
$userId
):
AccessibleUser
51
{
52
$this->userId =
$userId
;
53
return
$this;
54
}
55
56
public
function
getName
(): string
57
{
58
if
($this->name ===
null
)
59
{
60
if
($this->userId === 0)
61
{
62
$this->name =
''
;
63
return
$this->name
;
64
}
65
66
}
67
return
$this->name
;
68
}
69
70
public
function
getUserDepartments
(): array
71
{
72
if
($this->userDepartments ===
null
)
73
{
74
$this->userDepartments =
UserSubordinate::getDepartmentsByUserId
($this->userId);
75
}
76
return
$this->userDepartments
;
77
}
78
79
public
function
isAdmin
(): bool
80
{
81
if
(!$this->userId)
82
{
83
return
false
;
84
}
85
if
($this->
isAdmin
===
null
)
86
{
87
$currentUser = CurrentUser::get();
88
if
((
int
) $currentUser->getId() === $this->userId)
89
{
90
$userGroups = $currentUser->getUserGroups();
91
}
92
else
93
{
94
$userGroups = \CUser::GetUserGroup($this->userId);
95
}
96
$this->
isAdmin
= in_array(1, $userGroups);
97
}
98
return
$this->isAdmin
;
99
}
100
101
public
function
getAccessCodes
(): array
102
{
103
if
($this->accessCodes ===
null
)
104
{
105
$this->accessCodes = [];
106
if
($this->userId === 0)
107
{
108
return
$this->accessCodes
;
109
}
110
111
// mantis #0160102
112
$res = UserAccessTable::getList([
113
'select'
=> [
'ACCESS_CODE'
],
114
'filter'
=> [
115
'=USER_ID'
=> $this->userId,
116
'!%=ACCESS_CODE'
=>
'CHAT%'
,
117
]
118
]);
119
foreach
($res as $row)
120
{
121
$signature = (
new
AccessCode
($row[
'ACCESS_CODE'
]))->getSignature();
122
if
($signature)
123
{
124
$this->accessCodes[$signature] = $signature;
125
}
126
}
127
128
$this->accessCodes = array_values($this->accessCodes);
129
130
// add employee access code
131
if
(!\
Bitrix
\Main\
ModuleManager::isModuleInstalled
(
'intranet'
))
132
{
133
return
$this->accessCodes
;
134
}
135
136
$user =
UserTable::getList
([
137
'select'
=> [
'UF_DEPARTMENT'
],
138
'filter'
=> [
139
'=ID'
=> $this->userId,
140
],
141
'limit'
=> 1
142
])->fetch();
143
144
if
(
145
$user
146
&& is_array($user[
'UF_DEPARTMENT'
])
147
&& count($user[
'UF_DEPARTMENT'
])
148
&& !empty(array_values($user[
'UF_DEPARTMENT'
])[0])
149
)
150
{
151
$this->accessCodes[] =
AccessCode::ACCESS_EMPLOYEE
.
'0'
;
152
}
153
}
154
return
$this->accessCodes
;
155
}
156
157
public
function
getSubordinate
(
int
$userId
): int
158
{
159
return
(
new
UserSubordinate
($this->userId))->getSubordinate(
$userId
);
160
}
161
162
abstract
public
function
getRoles
(): array;
163
164
abstract
public
function
getPermission
(
string
$permissionId): ?int;
165
}
Bitrix\Main\Access\AccessCode
Definition
accesscode.php:13
Bitrix\Main\Access\AccessCode\ACCESS_EMPLOYEE
const ACCESS_EMPLOYEE
Definition
accesscode.php:16
Bitrix\Main\Access\User\UserModel
Definition
usermodel.php:18
Bitrix\Main\Access\User\UserModel\getUserId
getUserId()
Definition
usermodel.php:45
Bitrix\Main\Access\User\UserModel\__construct
__construct()
Definition
usermodel.php:41
Bitrix\Main\Access\User\UserModel\getUserDepartments
getUserDepartments()
Definition
usermodel.php:70
Bitrix\Main\Access\User\UserModel\$roles
$roles
Definition
usermodel.php:22
Bitrix\Main\Access\User\UserModel\getName
getName()
Definition
usermodel.php:56
Bitrix\Main\Access\User\UserModel\$userId
$userId
Definition
usermodel.php:20
Bitrix\Main\Access\User\UserModel\getAccessCodes
getAccessCodes()
Definition
usermodel.php:101
Bitrix\Main\Access\User\UserModel\getRoles
getRoles()
Bitrix\Main\Access\User\UserModel\isAdmin
isAdmin()
Definition
usermodel.php:79
Bitrix\Main\Access\User\UserModel\$name
$name
Definition
usermodel.php:21
Bitrix\Main\Access\User\UserModel\createFromId
static createFromId(int $userId)
Definition
usermodel.php:29
Bitrix\Main\Access\User\UserModel\getPermission
getPermission(string $permissionId)
Bitrix\Main\Access\User\UserModel\$cache
static $cache
Definition
usermodel.php:27
Bitrix\Main\Access\User\UserModel\setUserId
setUserId(int $userId)
Definition
usermodel.php:50
Bitrix\Main\Access\User\UserModel\$userDepartments
$userDepartments
Definition
usermodel.php:23
Bitrix\Main\Access\User\UserModel\$isAdmin
$isAdmin
Definition
usermodel.php:24
Bitrix\Main\Access\User\UserModel\$accessCodes
$accessCodes
Definition
usermodel.php:25
Bitrix\Main\Access\User\UserModel\getSubordinate
getSubordinate(int $userId)
Definition
usermodel.php:157
Bitrix\Main\Access\User\UserSubordinate
Definition
usersubordinate.php:13
Bitrix\Main\Access\User\UserSubordinate\getDepartmentsByUserId
static getDepartmentsByUserId(int $userId)
Definition
usersubordinate.php:28
Bitrix\Main\Engine\CurrentUser
Definition
currentuser.php:8
Bitrix\Main\ModuleManager\isModuleInstalled
static isModuleInstalled($moduleName)
Definition
modulemanager.php:67
Bitrix\Main\ORM\Data\DataManager\getList
static getList(array $parameters=array())
Definition
datamanager.php:441
Bitrix\Main\UserAccessTable
Definition
useraccess.php:24
Bitrix\Main\UserTable
Definition
user.php:46
Bitrix\Main\Access\User\AccessibleUser
Definition
accessibleuser.php:13
Bitrix\Main\Access\User\AccessibleUser\setUserId
setUserId(int $userId)
Bitrix\Main\Access\User
Definition
accessibleuser.php:9
Bitrix
modules
main
lib
access
user
usermodel.php
Создано системой
1.10.0