protected function ForumManager::lastVisit in Drupal 10
Same name and namespace in other branches
- 8 core/modules/forum/src/ForumManager.php \Drupal\forum\ForumManager::lastVisit()
- 9 core/modules/forum/src/ForumManager.php \Drupal\forum\ForumManager::lastVisit()
Gets the last time the user viewed a node.
Parameters
int $nid: The node ID.
\Drupal\Core\Session\AccountInterface $account: Account to fetch last time for.
Return value
int The timestamp when the user last viewed this node, if the user has previously viewed the node; otherwise HISTORY_READ_LIMIT.
File
- core/
modules/ forum/ src/ ForumManager.php, line 322
Class
- ForumManager
- Provides forum manager service.
Namespace
Drupal\forumCode
protected function lastVisit($nid, AccountInterface $account) {
if (empty($this->history[$nid])) {
$result = $this->connection
->select('history', 'h')
->fields('h', [
'nid',
'timestamp',
])
->condition('uid', $account
->id())
->execute();
foreach ($result as $t) {
$this->history[$t->nid] = $t->timestamp > HISTORY_READ_LIMIT ? $t->timestamp : HISTORY_READ_LIMIT;
}
}
return $this->history[$nid] ?? HISTORY_READ_LIMIT;
}