1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
UserView.php
См. документацию.
1<?php
2
3namespace Bitrix\Bizproc\UI;
4
5use Bitrix\Main\Engine\CurrentUser;
6use Bitrix\Main\EO_User;
7use Bitrix\Main\UserTable;
8
9class UserView implements \JsonSerializable
10{
11 private EO_User $user;
12
13 public static function createFromId(int $userId): ?static
14 {
15 $currentUser = CurrentUser::get();
16 if ((int)$currentUser->getId() === $userId)
17 {
18 $user = UserTable::wakeUpObject([
19 'ID' => $currentUser->getId(),
20 'LOGIN' => $currentUser->getLogin(),
21 'NAME' => $currentUser->getFirstName(),
22 'SECOND_NAME' => $currentUser->getSecondName(),
23 'LAST_NAME' => $currentUser->getLastName(),
24 'EMAIL' => $currentUser->getEmail(),
25 ]);
26 }
27 else
28 {
29 $user = UserTable::getByPrimary($userId)->fetchObject();
30 }
31
32 return $user ? new static($user): null;
33 }
34
35 public function __construct(EO_User $user)
36 {
37 $this->user = $user;
38 }
39
40 public function getUserId(): int
41 {
42 return $this->user->getId();
43 }
44
45 public function getFullName(): string
46 {
47 return \CUser::FormatName(
48 \CSite::GetNameFormat(),
49 [
50 'LOGIN' => $this->user->getLogin(),
51 'NAME' => $this->user->getName(),
52 'LAST_NAME' => $this->user->getLastName(),
53 'SECOND_NAME' => $this->user->getSecondName(),
54 'EMAIL' => $this->user->getEmail(),
55 ],
56 true,
57 false
58 );
59 }
60
61 public function getUserAvatar(int $size = 100): ?string
62 {
63 static $cache = [];
64
65 $photo = $this->user->getPersonalPhoto();
66 if (empty($photo) || $size <= 0)
67 {
68 return null;
69 }
70
71 $avatarId = "{$photo}{$size}";
72 if (!isset($cache[$avatarId]))
73 {
74 $cache[$avatarId] = '';
75 if ($photo > 0)
76 {
77 $originalFile = \CFile::getFileArray($photo);
78
79 if ($originalFile !== false)
80 {
81 $resizedFile = \CFile::resizeImageGet(
82 $originalFile,
83 [
84 'width' => $size,
85 'height' => $size,
86 ],
88 false,
89 false,
90 true,
91 );
92
93 $cache[$avatarId] = $resizedFile['src'];
94 }
95 }
96 }
97
98 return $cache[$avatarId];
99 }
100
101 public function jsonSerialize(): array
102 {
103 $userId = $this->getUserId();
104
105 return [
106 'id' => $userId,
107 'login' => $this->user->getLogin(),
108 'name' => $this->user->getName(),
109 'lastName' => $this->user->getLastName(),
110 'secondName' => $this->user->getSecondName(),
111 'fullName' => $this->getFullName(),
112 'workPosition' => $this->user->getWorkPosition(),
113 'link' => "/company/personal/user/{$userId}/",
114 'avatarSize100' => $this->getUserAvatar(),
115 ];
116 }
117}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
getUserId()
Определения UserView.php:40
getFullName()
Определения UserView.php:45
__construct(EO_User $user)
Определения UserView.php:35
getUserAvatar(int $size=100)
Определения UserView.php:61
static createFromId(int $userId)
Определения UserView.php:13
jsonSerialize()
Определения UserView.php:101
Определения orm.php:16144
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
const BX_RESIZE_IMAGE_EXACT
Определения constants.php:12