function _forum_topics_unread

_forum_topics_unread($term, $uid)

Calculates the number of new posts in a forum that the user has not yet read.

Nodes are new if they are newer than NODE_NEW_LIMIT.

Parameters

$term: The term ID of the forum.

$uid: The user ID.

Return value

The number of new posts in the forum that have not been read by the user.

File

modules/forum/forum.module, line 883
Provides discussion forums.

Code

function _forum_topics_unread($term, $uid) {
  $query = db_select('node', 'n');
  $query->join('forum', 'f', 'n.vid = f.vid AND f.tid = :tid', array(':tid' => $term));
  $query->leftJoin('history', 'h', 'n.nid = h.nid AND h.uid = :uid', array(':uid' => $uid));
  $query->addExpression('COUNT(n.nid)', 'count');
  return $query
  ->condition('status', 1)
    ->condition('n.created', NODE_NEW_LIMIT, '>')
    ->isNull('h.nid')
    ->addTag('node_access')
    ->execute()
    ->fetchField();
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!forum!forum.module/function/_forum_topics_unread/7.x