function ForumManager::lastVisit

Same name and namespace in other branches
  1. 9 core/modules/forum/src/ForumManager.php \Drupal\forum\ForumManager::lastVisit()
  2. 10 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
Gets list of forum topics.

File

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

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 isset($this->history[$nid]) ? $this->history[$nid] : HISTORY_READ_LIMIT;
}

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