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