function ForumManager::lastVisit

Same name in other branches
  1. 9 core/modules/forum/src/ForumManager.php \Drupal\forum\ForumManager::lastVisit()
  2. 8.9.x core/modules/forum/src/ForumManager.php \Drupal\forum\ForumManager::lastVisit()
  3. 11.x 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.

1 call to ForumManager::lastVisit()
ForumManager::getTopics in core/modules/forum/src/ForumManager.php

File

core/modules/forum/src/ForumManager.php, line 322

Class

ForumManager
Provides forum manager service.

Namespace

Drupal\forum

Code

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.