Esempio n. 1
0
 /**
  * Return the application groups
  * 
  * @var array
  * @return mixed
  * 
  */
 public static function get_groups(array $params = array('sys' => false))
 {
     $app_groups = \Groups\Model\Group::all();
     if ($params['sys'] === true) {
         $groups = array(0 => '-- Any --', -1 => 'Guests', -2 => 'Authenticated');
     }
     foreach ($app_groups as $group) {
         $groups[$group->id] = $group->name;
     }
     if (isset($params['to_json']) and $params['to_json'] === true) {
         return json_encode($groups);
     }
     return $groups;
 }
Esempio n. 2
0
 public static function group_has_role($module, $role)
 {
     // User with id 1 should be administrator
     if (self::$user->id == 1) {
         return true;
     }
     // Get the user Group
     if (!isset(self::$user->group_id)) {
         return false;
     }
     self::$user_group = \Groups\Model\Group::find(self::$user->group_id);
     if (!isset(self::$user_group) or empty(self::$user_group)) {
         //Group was not found
         return false;
     }
     if (self::$user_group->slug == 'admin') {
         // this is an administrator
         return true;
     }
     $permission = Permission::where_group_id(self::$user->group->id)->where_module_name($module)->first();
     if (!isset($permission) or empty($permission)) {
         // The role is not even in the permissions table
         return false;
     }
     $roles = json_decode($permission->roles, true);
     if (!isset($roles) or empty($roles)) {
         //failed to decode json from permissions table
         return false;
     }
     return $find_role = array_filter($roles, function ($roles) use($role) {
         if ($roles['slug'] == $role and $roles['value'] == true) {
             return true;
         }
         return false;
     });
 }