Exemple #1
0
 public function getPermissions($roleId = null)
 {
     if (!$roleId) {
         return null;
     }
     // Check if the table exists (patch not installed yet)
     $db = ConnectionManager::getDataSource('default');
     $tables = $db->listSources();
     if (!in_array($this->tablePrefix . 'role_permission_roles', $tables)) {
         $permissions['full_permissions'] = $roleId == 1;
         $permissions['limited_admin'] = false;
         $permissions['manage_events'] = false;
         $permissions['manage_own_events'] = false;
         $permissions['create_templates'] = false;
         $permissions['create_reports'] = false;
         return $permissions;
     }
     $permissions = array();
     $rolePermissionsAssigned = array();
     App::uses('RolePermissionRole', 'Model');
     $RolePermissionRoleModel = new RolePermissionRole();
     App::uses('RolePermission', 'Model');
     $RolePermissionModel = new RolePermission();
     $params = array();
     $params['recursive'] = 1;
     $params['fields'] = array('id', 'role_id');
     $params['contain']['RolePermission']['fields'] = array('alias');
     $params['conditions']['role_id'] = $roleId;
     if ($rolePermissionRoles = $RolePermissionRoleModel->find('all', $params)) {
         foreach ($rolePermissionRoles as $rolePermissionRole) {
             $permissions[$rolePermissionRole['RolePermission']['alias']] = $rolePermissionRole['RolePermissionRole']['role_id'] == $roleId;
             $rolePermissionsAssigned[] = $rolePermissionRole['RolePermission']['id'];
         }
     }
     $params = array();
     $params['recursive'] = -1;
     $params['conditions']['id !='] = $rolePermissionsAssigned;
     if ($rolePermissions = $RolePermissionModel->find('all', $params)) {
         foreach ($rolePermissions as $rolePermission) {
             if (!isset($permissions[$rolePermission['RolePermission']['alias']])) {
                 $permissions[$rolePermission['RolePermission']['alias']] = false;
             }
         }
     }
     return $permissions;
 }
 public static function GetByPermissionId($permission_id)
 {
     return RolePermission::find('all', array('permission_id' => $permission_id));
 }