Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
usermodel.php
1<?php
2
4
6use Bitrix\Main\UserField\Access\Role\UserFieldRoleRelationTable;
7
10{
11 private
12 $permissions;
13
14 public function getRoles(): array
15 {
16 if ($this->roles === null)
17 {
18 $this->roles = [];
19 if ($this->userId === 0 || empty($this->getAccessCodes()))
20 {
21 return $this->roles;
22 }
23
24 $res = UserFieldRoleRelationTable::query()
25 ->addSelect('ROLE_ID')
26 ->whereIn('RELATION', $this->getAccessCodes())
27 ->exec();
28 foreach ($res as $row)
29 {
30 $this->roles[] = (int) $row['ROLE_ID'];
31 }
32 }
33 return $this->roles;
34 }
35
36 public function getPermission(string $permissionId, int $userFieldId = 0): ?int
37 {
38 $permissions = $this->getPermissions($userFieldId);
39 if (array_key_exists($permissionId, $permissions))
40 {
41 return $permissions[$permissionId];
42 }
43 return null;
44 }
45
46 private function getPermissions(int $userFieldId = 0): array
47 {
48 if (!$this->permissions || !array_key_exists($userFieldId, $this->permissions))
49 {
50 $this->permissions[$userFieldId] = [];
51
52 $res = UserFieldPermissionTable::query()
53 ->addSelect("PERMISSION_ID")
54 ->addSelect("USER_FIELD_ID")
55 ->addSelect("VALUE")
56 ->where("USER_FIELD_ID", $userFieldId)
57 ->where("ROLE_ID", $this->userId)
58 ->exec()
59 ->fetchAll();
60
61 foreach ($res as $row)
62 {
63 $permissionId = $row["PERMISSION_ID"];
64 $value = (int) $row["VALUE"];
65 if (!array_key_exists($permissionId, $this->permissions[$userFieldId]))
66 {
67 $this->permissions[$userFieldId][$permissionId] = 0;
68 }
69 if ($value > $this->permissions[$userFieldId][$permissionId])
70 {
71 $this->permissions[$userFieldId][$permissionId] = $value;
72 }
73 }
74 }
75 return $this->permissions[$userFieldId];
76 }
77}
getPermission(string $permissionId, int $userFieldId=0)
Definition usermodel.php:36