function login_history_last_login in Login History 7
Same name and namespace in other branches
- 8 login_history.module \login_history_last_login()
- 6 login_history.module \login_history_last_login()
Provide data about the last login for a user.
Parameters
object $account: Optional user object. The only thing that really matters is the uid.
string $device_id: Optional device id to look for.
int $login_id_to_avoid: An optional login id primary key to exclude from results.
Return value
object|false An object containing information about the last login or FALSE if no result is found.
2 calls to login_history_last_login()
- login_history_block_view in ./
login_history.module - Implements hook_block_view().
- login_history_send_mail_new_login_device in ./
login_history.module - Determines if an email should be sent to a visitor for a login on a "new" device.
File
- ./
login_history.module, line 260 - The login history module.
Code
function login_history_last_login($account = NULL, $device_id = NULL, $login_id_to_avoid = NULL) {
if (user_is_anonymous()) {
return;
}
if (empty($account)) {
global $user;
$account = $user;
}
$select = db_select('login_history', 'lh')
->fields('lh', array(
'login',
'hostname',
'one_time',
'user_agent',
'device_id',
))
->condition('lh.uid', $account->uid)
->range(0, 1);
if (!empty($device_id)) {
$select
->condition('lh.device_id', $device_id);
}
if (!empty($login_id_to_avoid)) {
$select
->condition('lh.login_id', $login_id_to_avoid, '<>');
}
$last_login = $select
->execute()
->fetchAll();
return reset($last_login);
}