public function logged_in($role = NULL)
{
$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))
{
// 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))
{
$status = FALSE;
break;
}
}
}
// Single role to check
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;
}
public function logged_in($role = NULL)
{
$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))
{
// THE PROBLEM BEGINS HERE, WE HAVE TO SAY THE STATUS IS FALSE
// REMEMBER, IT WILL ONLY HAPPEN WHEN WE'RE CHECKING THE ROLE. IT WON'T
// DISTURB IN CASE WE JUST WANT TO KNOW WHETER THE USER IS LOGGED IN OR NOT
$status = FALSE;
// 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))
{
// IF WE DON'T GET THE ROLE, WE REMAIN $status AS FALSE
$status = FALSE;
//break;
}else{
// JUST WHEN WE FOUND ONE ADMITTED ROLE, WE SAY
// EVERYTHING IS OKAY, AND WE BREAK THE FOREACH
$status = TRUE;
break;
}
}
}
// Single role to check
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;
}
It looks like you're new here. If you want to get involved, click one of these buttons!