Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
usermodel.php
1<?php
2
4
7
16{
17 private $permissions;
18
26 public function getRoles(): array
27 {
28 if ($this->roles === null)
29 {
30 $this->roles = [];
31 if ($this->userId === 0 || empty($this->getAccessCodes()))
32 {
33 return $this->roles;
34 }
35
36 $res = RoleRelationTable::query()
37 ->addSelect('ROLE_ID')
38 ->whereIn('RELATION', $this->getAccessCodes())
39 ->exec();
40 foreach ($res as $row)
41 {
42 $this->roles[] = (int) $row['ROLE_ID'];
43 }
44 }
45 return $this->roles;
46 }
47
58 public function getPermission(string $permissionId): ?int
59 {
60 $permissions = $this->getPermissions();
61 if (array_key_exists($permissionId, $permissions))
62 {
63 return $permissions[$permissionId];
64 }
65 return null;
66 }
67
74 private function getPermissions(): array
75 {
76 if (!$this->permissions)
77 {
78 $this->permissions = [];
79 $roles = $this->getRoles();
80
81 if (empty($roles))
82 {
83 return $this->permissions;
84 }
85
86 $query = PermissionTable::query();
87
88 $res = $query
89 ->addSelect("PERMISSION_ID")
90 ->addSelect("VALUE")
91 ->whereIn("ROLE_ID", $roles)
92 ->exec()
93 ->fetchAll();
94
95 foreach ($res as $row)
96 {
97 $permissionId = $row["PERMISSION_ID"];
98 $value = (int) $row["VALUE"];
99 if (!array_key_exists($permissionId, $this->permissions))
100 {
101 $this->permissions[$permissionId] = 0;
102 }
103 if ($value > $this->permissions[$permissionId])
104 {
105 $this->permissions[$permissionId] = $value;
106 }
107 }
108 }
109 return $this->permissions;
110 }
111}
getPermission(string $permissionId)
Definition usermodel.php:58