1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Bluz PHP Team |
5
|
|
|
* @link https://github.com/bluzphp/skeleton |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace Application\Roles; |
11
|
|
|
|
12
|
|
|
use Bluz\Proxy\Cache; |
|
|
|
|
13
|
|
|
use Bluz\Proxy\Db; |
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Table of User Roles |
17
|
|
|
* |
18
|
|
|
* @package Application\Roles |
19
|
|
|
* |
20
|
|
|
* @method static Row|null findRow($primaryKey) |
21
|
|
|
* @see \Bluz\Db\Table::findRow() |
22
|
|
|
* @method static Row|null findRowWhere($whereList) |
23
|
|
|
* @see \Bluz\Db\Table::findRowWhere() |
24
|
|
|
*/ |
25
|
|
|
class Table extends \Bluz\Db\Table |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
public const BASIC_ADMIN = 'admin'; |
28
|
|
|
public const BASIC_GUEST = 'guest'; |
29
|
|
|
public const BASIC_MEMBER = 'member'; |
30
|
|
|
public const BASIC_SYSTEM = 'system'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Table |
34
|
|
|
* |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $name = 'acl_roles'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Primary key(s) |
41
|
|
|
* |
42
|
|
|
* @var array |
43
|
|
|
*/ |
44
|
|
|
protected $primary = ['id']; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var array |
48
|
|
|
*/ |
49
|
|
|
protected $basicRoles = [ |
50
|
|
|
self::BASIC_ADMIN, |
51
|
|
|
self::BASIC_GUEST, |
52
|
|
|
self::BASIC_MEMBER, |
53
|
|
|
self::BASIC_SYSTEM |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Init table relations |
58
|
|
|
* |
59
|
|
|
* @return void |
60
|
1 |
|
*/ |
61
|
|
|
public function init(): void |
62
|
1 |
|
{ |
63
|
1 |
|
$this->linkTo('id', 'UsersRoles', 'roleId'); |
64
|
1 |
|
$this->linkToMany('Users', 'UsersRoles'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get all basic roles |
69
|
|
|
* |
70
|
|
|
* @return array |
71
|
1 |
|
*/ |
72
|
|
|
public function getBasicRoles(): array |
73
|
1 |
|
{ |
74
|
|
|
return $this->basicRoles; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Get all roles in system |
79
|
|
|
* |
80
|
|
|
* @return Row[] |
81
|
2 |
|
*/ |
82
|
|
|
public function getRoles(): array |
83
|
2 |
|
{ |
84
|
|
|
return self::fetch('SELECT * FROM acl_roles ORDER BY id'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Get all user roles in system |
89
|
|
|
* |
90
|
|
|
* @param integer $userId |
91
|
|
|
* |
92
|
|
|
* @return Row[] |
93
|
|
|
*/ |
94
|
|
|
public function getUserRoles($userId): array |
95
|
|
|
{ |
96
|
|
|
$data = self::fetch( |
97
|
|
|
'SELECT r.* |
98
|
|
|
FROM acl_roles AS r, acl_users_roles AS u2r |
99
|
|
|
WHERE r.id = u2r.roleId AND u2r.userId = ?', |
100
|
|
|
[$userId] |
101
|
|
|
); |
102
|
|
|
return $data; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Get all user roles in system |
107
|
|
|
* |
108
|
|
|
* @param integer $userId |
109
|
|
|
* |
110
|
|
|
* @return array of identity |
111
|
7 |
|
*/ |
112
|
|
|
public function getUserRolesIdentity($userId): array |
113
|
7 |
|
{ |
114
|
7 |
|
$cacheKey = 'users.roles.' . $userId; |
115
|
7 |
|
if (!$data = Cache::get($cacheKey)) { |
116
|
7 |
|
$data = Db::fetchColumn( |
117
|
|
|
'SELECT r.id |
118
|
|
|
FROM acl_roles AS r, acl_users_roles AS u2r |
119
|
|
|
WHERE r.id = u2r.roleId AND u2r.userId = ? |
120
|
7 |
|
ORDER BY r.id ASC', |
121
|
|
|
[$userId] |
122
|
7 |
|
); |
123
|
|
|
Cache::set($cacheKey, $data, Cache::TTL_NO_EXPIRY, ['system', 'users', 'roles']); |
124
|
7 |
|
} |
125
|
|
|
return $data; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths