/**
* Updates last visit time of user
*
* @param integer $timeStamp The timestamp, defaults to 'now'.
* @param integer $userId The user id (optional).
*
* @return boolean False if an error occurs
*
* @since 1.7.0
*/
public function setLastVisit($timeStamp = null, $userId = null)
{
// Check for User ID
if (\is_null($userId)) {
if (isset($this)) {
$userId = $this->id;
} else {
jexit('No userid in setLastVisit');
}
}
// If no timestamp value is passed to function, then current time is used.
if ($timeStamp === null) {
$timeStamp = 'now';
}
$date = Factory::getDate($timeStamp);
$userId = (int) $userId;
$lastVisit = $date->toSql();
// Update the database row for the user.
$db = $this->_db;
$query = $db->getQuery(true)->update($db->quoteName($this->_tbl))->set($db->quoteName('lastvisitDate') . ' = :lastvisitDate')->where($db->quoteName('id') . ' = :id')->bind(':lastvisitDate', $lastVisit)->bind(':id', $userId, ParameterType::INTEGER);
$db->setQuery($query);
$db->execute();
return true;
}