Traq\Permissions::getPermissions PHP Méthode

getPermissions() public static méthode

Returns default and added permissions.
public static getPermissions ( $withCategories = false ) : array
Résultat array
    public static function getPermissions($withCategories = false)
    {
        $permissions = array_merge_recursive(static::getDefaults(true), static::$permissions);
        if ($withCategories) {
            return $permissions;
        } else {
            $flatPermissions = [];
            foreach ($permissions as $category => $perms) {
                $flatPermissions = $flatPermissions + $perms;
            }
            return $flatPermissions;
        }
    }

Usage Example

Exemple #1
0
 protected function savePermissions($type)
 {
     foreach (Request::$post['permissions'] as $group => $perms) {
         $permissions = [];
         if ($group == 'defaults') {
             foreach (PermissionsAPI::getPermissions() as $name => $default) {
                 if (isset($perms[$name])) {
                     $permissions[$name] = true;
                 } else {
                     $permissions[$name] = false;
                 }
             }
             $this->db->update(PREFIX . 'permissions', ['permissions' => json_encode($permissions)], ['type' => $type, 'type_id' => 0, 'project_id' => 0]);
         } else {
             // Ignore 'null' values
             foreach ($perms as $name => $value) {
                 if ($value == '1' || $value == '0') {
                     $permissions[$name] = (bool) $value;
                 }
             }
             // If there are no permissions, delete the row
             if (!count($permissions)) {
                 $this->db->delete(PREFIX . 'permissions', ['type' => $type, 'type_id' => $group, 'project_id' => 0]);
             } else {
                 // Check if the row exists already
                 $query = queryBuilder()->select('id')->from(PREFIX . 'permissions')->where('type = ?')->andWhere('type_id = ?')->andWhere('project_id = ?')->setParameter(0, $type)->setParameter(1, $group)->setParameter(2, 0)->execute();
                 // Update the row
                 if ($query->rowCount()) {
                     $this->db->update(PREFIX . 'permissions', ['permissions' => json_encode($permissions)], ['type' => $type, 'type_id' => $group, 'project_id' => 0]);
                 } else {
                     // Insert a new row
                     $this->db->insert(PREFIX . 'permissions', ['type' => $type, 'type_id' => $group, 'project_id' => 0, 'permissions' => json_encode($permissions)]);
                 }
             }
         }
     }
 }
All Usage Examples Of Traq\Permissions::getPermissions