ForumManager::lastVisit

protected ForumManager::lastVisit($nid, AccountInterface $account)

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 309

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', array('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;
}
doc_Drupal
2016-10-29 09:17:12
Comments
Leave a Comment

Please login to continue.