1 | <?php |
||
15 | class Permission { |
||
16 | use |
||
17 | CRUD_helpers, |
||
18 | Singleton; |
||
19 | |||
20 | protected $data_model = [ |
||
21 | 'id' => 'int:1', |
||
22 | 'group' => 'text', |
||
23 | 'label' => 'text' |
||
24 | ]; |
||
25 | protected $table = '[prefix]permissions'; |
||
26 | /** |
||
27 | * Array of all permissions for quick selecting |
||
28 | * |
||
29 | * @var array|null |
||
30 | */ |
||
31 | protected $permissions_table; |
||
32 | /** |
||
33 | * @var Cache\Prefix |
||
34 | */ |
||
35 | protected $cache; |
||
36 | /** |
||
37 | * Returns database index |
||
38 | * |
||
39 | * @return int |
||
40 | */ |
||
41 | 6 | protected function cdb () { |
|
47 | /** |
||
48 | * Get permission data<br> |
||
49 | * If <b>$group</b> or/and <b>$label</b> parameter is specified, <b>$id</b> is ignored. |
||
50 | * |
||
51 | * @param int|null $id |
||
52 | * @param null|string $group |
||
53 | * @param null|string $label |
||
54 | * |
||
55 | * @return array|false If only <b>$id</b> specified - result is array of permission data, in other cases result will be array of arrays of corresponding |
||
56 | * permissions data |
||
57 | */ |
||
58 | 4 | function get ($id = null, $group = null, $label = null) { |
|
76 | /** |
||
77 | * Add permission |
||
78 | * |
||
79 | * @param string $group |
||
80 | * @param string $label |
||
81 | * |
||
82 | * @return false|int Group id or <b>false</b> on failure |
||
83 | */ |
||
84 | 4 | function add ($group, $label) { |
|
91 | /** |
||
92 | * Set permission |
||
93 | * |
||
94 | * @param int $id |
||
95 | * @param string $group |
||
96 | * @param string $label |
||
97 | * |
||
98 | * @return bool |
||
99 | */ |
||
100 | 2 | function set ($id, $group, $label) { |
|
107 | /** |
||
108 | * Deletion of permission or array of permissions |
||
109 | * |
||
110 | * @param int|int[] $id |
||
111 | * |
||
112 | * @return bool |
||
113 | */ |
||
114 | 2 | function del ($id) { |
|
136 | /** |
||
137 | * Returns array of all permissions grouped by permissions groups |
||
138 | * |
||
139 | * @return array Format of array: ['group']['label'] = <i>permission_id</i> |
||
140 | */ |
||
141 | 10 | function get_all () { |
|
159 | /** |
||
160 | * Deletion of permission table (is used after adding, setting or deletion of permission) |
||
161 | */ |
||
162 | 4 | protected function del_all_cache () { |
|
166 | } |
||
167 |