1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
usermodel.php
См. документацию.
1<?php
8
9namespace Bitrix\Main\Access\User;
10
11use Bitrix\HumanResources\Config\Storage;
12use Bitrix\HumanResources\Service\Container;
13use Bitrix\Main\Access\AccessCode;
14use Bitrix\Main\Engine\CurrentUser;
15use Bitrix\Main\Loader;
16use Bitrix\Main\UserAccessTable;
17use Bitrix\Main\UserTable;
18
19abstract class UserModel
20 implements AccessibleUser
21{
22 protected
29
30 protected static $cache = [];
31
32 public static function createFromId(int $userId): static
33 {
34 $key = 'USER_'.static::class.'_'.$userId;
35 if (!array_key_exists($key, static::$cache))
36 {
37 $model = new static();
38 $model->setUserId($userId);
39 static::$cache[$key] = $model;
40 }
41 return static::$cache[$key];
42 }
43
44 protected function __construct()
45 {
46 }
47
48 public function getUserId(): int
49 {
50 return $this->userId;
51 }
52
53 public function setUserId(int $userId): AccessibleUser
54 {
55 $this->userId = $userId;
56 return $this;
57 }
58
59 public function getName(): string
60 {
61 if ($this->name === null)
62 {
63 if ($this->userId === 0)
64 {
65 $this->name = '';
66 return $this->name;
67 }
68
69 }
70 return $this->name;
71 }
72
73 public function getUserDepartments(): array
74 {
75 if ($this->userDepartments === null)
76 {
77 $this->userDepartments = UserSubordinate::getDepartmentsByUserId($this->userId);
78 }
80 }
81
82 public function isAdmin(): bool
83 {
84 if (!$this->userId)
85 {
86 return false;
87 }
88
89 if ($this->isAdmin === null)
90 {
91 $currentUser = CurrentUser::get();
92 if ((int) $currentUser->getId() === $this->userId)
93 {
94 $userGroups = $currentUser->getUserGroups();
95 }
96 else
97 {
98 $userGroups = \CUser::GetUserGroup($this->userId);
99 }
100 $this->isAdmin = in_array(1, $userGroups);
101 }
102
103 return $this->isAdmin;
104 }
105
106 public function getAccessCodes(): array
107 {
108 if ($this->accessCodes === null)
109 {
110 $this->accessCodes = [];
111 if ($this->userId === 0)
112 {
113 return $this->accessCodes;
114 }
115
116 // mantis #0160102, #0213214
117 $res = UserAccessTable::query()
118 ->setSelect(['ACCESS_CODE'])
119 ->where('USER_ID', $this->userId)
120 ->whereNot('PROVIDER_ID', 'imchat')
121 ->exec()
122 ->fetchAll();
123
124 foreach ($res as $row)
125 {
126 $signature = (new AccessCode($row['ACCESS_CODE']))->getSignature();
127 if ($signature)
128 {
129 $this->accessCodes[$signature] = $signature;
130 }
131 }
132
133 $this->accessCodes = array_values($this->accessCodes);
134
135 if (
136 Loader::includeModule('humanresources')
137 && Storage::instance()->isCompanyStructureConverted()
138 )
139 {
140 return $this->accessCodes;
141 }
142
143 // add employee access code
145 {
146 return $this->accessCodes;
147 }
148
150 'select' => ['UF_DEPARTMENT'],
151 'filter' => [
152 '=ID' => $this->userId,
153 ],
154 'limit' => 1
155 ])->fetch();
156
157 if (
158 $user
159 && is_array($user['UF_DEPARTMENT'])
160 && count($user['UF_DEPARTMENT'])
161 && !empty(array_values($user['UF_DEPARTMENT'])[0])
162 )
163 {
164 $this->accessCodes[] = AccessCode::ACCESS_EMPLOYEE . '0';
165 }
166 }
167 return $this->accessCodes;
168 }
169
170 public function getSubordinate(int $userId): int
171 {
172 return (new UserSubordinate($this->userId))->getSubordinate($userId);
173 }
174
175 abstract public function getRoles(): array;
176
177 abstract public function getPermission(string $permissionId): ?int;
178}
const ACCESS_EMPLOYEE
Определения accesscode.php:16
static createFromId(int $userId)
Определения usermodel.php:32
getPermission(string $permissionId)
setUserId(int $userId)
Определения usermodel.php:53
getSubordinate(int $userId)
Определения usermodel.php:170
static getDepartmentsByUserId(int $userId)
Определения usersubordinate.php:28
static includeModule($moduleName)
Определения loader.php:67
static isModuleInstalled($moduleName)
Определения modulemanager.php:125
static getList(array $parameters=array())
Определения datamanager.php:431
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$user
Определения mysql_to_pgsql.php:33
if(empty($signedUserToken)) $key
Определения quickway.php:257
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936