/** * Return all users * * @return array */ public function all($type = false) { if ($type === false) { // Return all users from database return DB::select()->from($this->table)->execute($this->db_instance)->as_array(); } // Return only users from specific groups (admin or front) $group = new \Sentry_Group(); $groups = $group->all($type); $users = array(); foreach ($groups as $group) { $group_users = new \Sentry_Group($group['id']); $users = array_merge($users, $group_users->users()); } return $users; }
/** * Removes this user from the group. * * @param string|int Group ID or group name * @return bool * @throws SentryUserException */ public function remove_from_group($id) { if (!$this->in_group($id)) { throw new SentryUserException(__('sentry::sentry.user_not_in_group', array('group' => $id))); } $field = 'name'; if (is_numeric($id)) { $field = 'id'; } try { $group = new Sentry_Group($id); } catch (SentryGroupNotFoundException $e) { throw new SentryUserException($e->getMessage()); } $delete = DB::connection($this->db_instance)->table($this->table_usergroups)->where('user_id', '=', $this->user['id'])->where('group_id', '=', $group->get('id'))->delete(); // remove from array $field = 'name'; if (is_numeric($id)) { $field = 'id'; } foreach ($this->groups as $key => $group) { if ($group[$field] == $id) { unset($this->groups[$key]); } } return (bool) $delete; }