Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
user.php
1
<?php
9
namespace
Bitrix\Main\UI\AccessRights\Entity
;
10
11
12
use
Bitrix\Main\Access\AccessCode
;
13
use
Bitrix\Main\Loader
;
14
use
Bitrix\Main\UI\AccessRights\Avatar
;
15
use
Bitrix\Main\UserTable
;
16
use
Bitrix\Main\Web\Uri
;
17
18
class
User
extends
EntityBase
19
{
20
private
const
SELECT_FIELDS = [
21
'ID'
,
22
'NAME'
,
23
'LAST_NAME'
,
24
'LOGIN'
,
25
'PERSONAL_PHOTO'
,
26
'UF_DEPARTMENT'
,
27
];
28
29
private
$isIntranetUser;
30
private
static
$modelsCache = [];
31
32
public
function
getType
(): string
33
{
34
return
AccessCode::TYPE_USER;
35
}
36
37
public
function
getName
(): string
38
{
39
if
($this->model)
40
{
41
$name = trim($this->model->getName() .
' '
. $this->model->getLastName());
42
43
return
$name ?: $this->model->getLogin();
44
}
45
return
''
;
46
}
47
48
public
function
getUrl
(): string
49
{
50
if
($this->isExtranetUser())
51
{
52
$userPage = \COption::getOptionString(
"socialnetwork"
,
"user_page"
,
false
, \CExtranet::getExtranetSiteID());
53
if
(!$userPage)
54
{
55
$userPage =
'/extranet/contacts/personal/'
;
56
}
57
}
58
else
59
{
60
$userPage = \COption::getOptionString(
"socialnetwork"
,
"user_page"
,
false
, SITE_ID);
61
if
(!$userPage)
62
{
63
$userPage = SITE_DIR .
'company/personal/'
;
64
}
65
}
66
67
return
$userPage .
'user/'
. $this->
getId
() .
'/'
;
68
}
69
70
public
function
getAvatar
(
int
$width = 58,
int
$height = 58): ?string
71
{
72
if
($this->model)
73
{
74
return
Avatar::getSrc
($this->model->getPersonalPhoto(), $width, $height);
75
}
76
return
''
;
77
}
78
79
protected
function
loadModel
()
80
{
81
if
(!$this->model)
82
{
83
if
(array_key_exists($this->
id
, self::$modelsCache))
84
{
85
$this->model = self::$modelsCache[
$this->id
];
86
}
87
else
88
{
89
$this->model =
UserTable::getList
([
90
'select'
=> self::SELECT_FIELDS,
91
'filter'
=> [
92
'=ID'
=> $this->
id
,
93
],
94
'limit'
=> 1,
95
])->fetchObject();
96
97
self::$modelsCache[
$this->id
] =
$this->model
;
98
}
99
}
100
}
101
102
private
function
isExtranetUser()
103
{
104
return
!$this->isIntranetUser() &&
Loader::includeModule
(
'extranet'
);
105
}
106
107
private
function
isIntranetUser()
108
{
109
if
(isset($this->isIntranetUser))
110
{
111
return
$this->isIntranetUser;
112
}
113
114
$this->isIntranetUser =
false
;
115
116
if
($this->model &&
Loader::includeModule
(
'intranet'
))
117
{
118
$this->isIntranetUser = !empty($this->model->getUfDepartment());
119
}
120
121
return
$this->isIntranetUser;
122
}
123
133
public
static
function
preLoadModels
(array $filter): void
134
{
135
$rows =
UserTable::getList
([
136
'select'
=> self::SELECT_FIELDS,
137
'filter'
=> $filter,
138
]);
139
while
($row = $rows->fetchObject())
140
{
141
self::$modelsCache[$row->getId()] = $row;
142
}
143
}
144
}
Bitrix\Main\Access\AccessCode
Definition
accesscode.php:13
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Main\Loader\includeModule
static includeModule($moduleName)
Definition
loader.php:69
Bitrix\Main\ORM\Data\DataManager\getList
static getList(array $parameters=array())
Definition
datamanager.php:441
Bitrix\Main\UI\AccessRights\Avatar
Definition
avatar.php:12
Bitrix\Main\UI\AccessRights\Avatar\getSrc
static getSrc($avatarId, $width=58, $height=58)
Definition
avatar.php:15
Bitrix\Main\UI\AccessRights\Entity\EntityBase
Definition
entitybase.php:13
Bitrix\Main\UI\AccessRights\Entity\EntityBase\$model
$model
Definition
entitybase.php:15
Bitrix\Main\UI\AccessRights\Entity\EntityBase\getId
getId()
Definition
entitybase.php:23
Bitrix\Main\UI\AccessRights\Entity\EntityBase\$id
$id
Definition
entitybase.php:14
Bitrix\Main\UI\AccessRights\Entity\User
Definition
user.php:19
Bitrix\Main\UI\AccessRights\Entity\User\getName
getName()
Definition
user.php:37
Bitrix\Main\UI\AccessRights\Entity\User\loadModel
loadModel()
Definition
user.php:79
Bitrix\Main\UI\AccessRights\Entity\User\getAvatar
getAvatar(int $width=58, int $height=58)
Definition
user.php:70
Bitrix\Main\UI\AccessRights\Entity\User\getType
getType()
Definition
user.php:32
Bitrix\Main\UI\AccessRights\Entity\User\preLoadModels
static preLoadModels(array $filter)
Definition
user.php:133
Bitrix\Main\UI\AccessRights\Entity\User\getUrl
getUrl()
Definition
user.php:48
Bitrix\Main\UserTable
Definition
user.php:46
Bitrix\Main\Web\Uri
Definition
uri.php:17
Bitrix\Main\UI\AccessRights\Entity
Definition
accessdirector.php:4
modules
main
lib
ui
accessrights
entity
user.php
Создано системой
1.10.0