16 if ($this->roles ===
null)
24 $res = UserFieldRoleRelationTable::query()
25 ->addSelect(
'ROLE_ID')
28 foreach ($res as $row)
30 $this->roles[] = (int) $row[
'ROLE_ID'];
36 public function getPermission(
string $permissionId,
int $userFieldId = 0): ?int
38 $permissions = $this->getPermissions($userFieldId);
39 if (array_key_exists($permissionId, $permissions))
41 return $permissions[$permissionId];
46 private function getPermissions(
int $userFieldId = 0): array
48 if (!$this->permissions || !array_key_exists($userFieldId, $this->permissions))
50 $this->permissions[$userFieldId] = [];
52 $res = UserFieldPermissionTable::query()
53 ->addSelect(
"PERMISSION_ID")
54 ->addSelect(
"USER_FIELD_ID")
56 ->where(
"USER_FIELD_ID", $userFieldId)
57 ->where(
"ROLE_ID", $this->userId)
61 foreach ($res as $row)
63 $permissionId = $row[
"PERMISSION_ID"];
64 $value = (int) $row[
"VALUE"];
65 if (!array_key_exists($permissionId, $this->permissions[$userFieldId]))
67 $this->permissions[$userFieldId][$permissionId] = 0;
69 if ($value > $this->permissions[$userFieldId][$permissionId])
71 $this->permissions[$userFieldId][$permissionId] = $value;
75 return $this->permissions[$userFieldId];
getPermission(string $permissionId, int $userFieldId=0)