Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
user.php
1<?php
10
11
17
18class 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}
static includeModule($moduleName)
Definition loader.php:69
static getList(array $parameters=array())
static getSrc($avatarId, $width=58, $height=58)
Definition avatar.php:15
getAvatar(int $width=58, int $height=58)
Definition user.php:70
static preLoadModels(array $filter)
Definition user.php:133