| 1 | <?php |
||
| 30 | class Group { |
||
| 31 | use |
||
| 32 | CRUD_helpers, |
||
| 33 | Singleton, |
||
| 34 | Any; |
||
| 35 | protected $data_model = [ |
||
| 36 | 'id' => 'int:0', |
||
| 37 | 'title' => 'html', |
||
| 38 | 'description' => 'html' |
||
| 39 | ]; |
||
| 40 | protected $table = '[prefix]groups'; |
||
| 41 | /** |
||
| 42 | * @var Cache\Prefix |
||
| 43 | */ |
||
| 44 | protected $cache; |
||
| 45 | /** |
||
| 46 | * Returns database index |
||
| 47 | * |
||
| 48 | * @return int |
||
| 49 | */ |
||
| 50 | 4 | protected function cdb () { |
|
| 56 | /** |
||
| 57 | * Get group data |
||
| 58 | * |
||
| 59 | * @param int|int[] $id |
||
| 60 | * |
||
| 61 | * @return array|array[]|false |
||
| 62 | */ |
||
| 63 | 2 | function get ($id) { |
|
| 64 | 2 | if (is_array($id)) { |
|
| 65 | 2 | foreach ($id as &$i) { |
|
| 66 | 2 | $i = $this->get($i); |
|
| 67 | } |
||
| 68 | 2 | return $id; |
|
| 69 | } |
||
| 70 | 2 | $id = (int)$id; |
|
| 71 | 2 | if (!$id) { |
|
| 72 | 2 | return false; |
|
| 73 | } |
||
| 74 | 2 | return $this->cache->get( |
|
| 75 | $id, |
||
| 76 | function () use ($id) { |
||
| 77 | 2 | return $this->read($id); |
|
| 78 | 2 | } |
|
| 79 | ); |
||
| 80 | } |
||
| 81 | /** |
||
| 82 | * Get array of all groups |
||
| 83 | * |
||
| 84 | * @return int[] |
||
| 85 | */ |
||
| 86 | 2 | function get_all () { |
|
| 94 | /** |
||
| 95 | * Add new group |
||
| 96 | * |
||
| 97 | * @param string $title |
||
| 98 | * @param string $description |
||
| 99 | * |
||
| 100 | * @return false|int |
||
|
1 ignored issue
–
show
|
|||
| 101 | */ |
||
| 102 | 4 | function add ($title, $description) { |
|
| 115 | /** |
||
| 116 | * Set group data |
||
| 117 | * |
||
| 118 | * @param int $id |
||
| 119 | * @param string $title |
||
| 120 | * @param string $description |
||
| 121 | * |
||
| 122 | * @return bool |
||
| 123 | */ |
||
| 124 | 2 | function set ($id, $title, $description) { |
|
| 136 | /** |
||
| 137 | * Delete group |
||
| 138 | * |
||
| 139 | * @param int|int[] $id |
||
| 140 | * |
||
| 141 | * @return bool |
||
| 142 | */ |
||
| 143 | 2 | function del ($id) { |
|
| 144 | 2 | if (is_array($id)) { |
|
| 145 | 2 | foreach ($id as &$i) { |
|
| 146 | 2 | $i = (int)$this->del($i); |
|
| 147 | } |
||
| 148 | 2 | return (bool)array_product($id); |
|
| 149 | } |
||
| 150 | 2 | $id = (int)$id; |
|
| 151 | 2 | if (in_array($id, [User::ADMIN_GROUP_ID, User::USER_GROUP_ID])) { |
|
| 152 | 2 | return false; |
|
| 153 | } |
||
| 154 | 2 | Event::instance()->fire( |
|
| 155 | 2 | 'System/User/Group/del/before', |
|
| 156 | [ |
||
| 157 | 2 | 'id' => $id |
|
| 158 | ] |
||
| 159 | ); |
||
| 160 | 2 | $result = $this->db_prime()->q( |
|
| 161 | [ |
||
| 162 | 2 | "DELETE FROM `[prefix]groups` WHERE `id` = $id", |
|
| 163 | 2 | "DELETE FROM `[prefix]users_groups` WHERE `group` = $id" |
|
| 164 | ] |
||
| 165 | ); |
||
| 166 | 2 | if ($result) { |
|
| 167 | 2 | $this->del_permissions_all($id); |
|
| 168 | 2 | $Cache = $this->cache; |
|
| 169 | unset( |
||
| 170 | 2 | Cache::instance()->{'users/groups'}, |
|
| 171 | 2 | $Cache->$id, |
|
| 172 | 2 | $Cache->all |
|
| 173 | ); |
||
| 174 | 2 | Event::instance()->fire( |
|
| 175 | 2 | 'System/User/Group/del/after', |
|
| 176 | [ |
||
| 177 | 2 | 'id' => $id |
|
| 178 | ] |
||
| 179 | ); |
||
| 180 | } |
||
| 181 | 2 | return (bool)$result; |
|
| 182 | } |
||
| 183 | /** |
||
| 184 | * Get group permissions |
||
| 185 | * |
||
| 186 | * @param int $group |
||
| 187 | * |
||
| 188 | * @return int[]|false |
||
| 189 | */ |
||
| 190 | 4 | function get_permissions ($group) { |
|
| 193 | /** |
||
| 194 | * Set group permissions |
||
| 195 | * |
||
| 196 | * @param array $data |
||
| 197 | * @param int $group |
||
| 198 | * |
||
| 199 | * @return bool |
||
| 200 | */ |
||
| 201 | 4 | function set_permissions ($data, $group) { |
|
| 204 | /** |
||
| 205 | * Delete all permissions of specified group |
||
| 206 | * |
||
| 207 | * @param int $group |
||
| 208 | * |
||
| 209 | * @return bool |
||
| 210 | */ |
||
| 211 | 2 | function del_permissions_all ($group) { |
|
| 214 | } |
||
| 215 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.