public function logged_in($role = NULL, $all_required = TRUE)
{
$status = FALSE;
// Get the user from the session
$user = $this->get_user();
if (is_object($user) and $user instanceof Model_User and $user->loaded()) {
// Everything is okay so far
$status = TRUE;
if (!empty($role)) {
// Multiple roles to check
if (is_array($role)) {
// set initial status
$status = (bool) $all_required;
// Check each role
foreach ($role as $_role) {
if (!is_object($_role)) {
$_role = ORM::factory('role', array('name' => $_role));
}
// If the user doesn't have the role
if (!$user->has('roles', $_role)) {
// Set the status false and get outta here
$status = FALSE;
if ($all_required) {
break;
}
} elseif (!$all_required) {
$status = TRUE;
break;
}
}
} else {
if (!is_object($role)) {
// Load the role
$role = ORM::factory('role', array('name' => $role));
}
// Check that the user has the given role
$status = $user->has('roles', $role);
}
}
}
return $status;
}