You are here

function _forum_topics_unread in Drupal 7

Same name and namespace in other branches
  1. 4 modules/forum.module \_forum_topics_unread()
  2. 5 modules/forum/forum.module \_forum_topics_unread()
  3. 6 modules/forum/forum.module \_forum_topics_unread()

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.

2 calls to _forum_topics_unread()
ForumTestCase::testForum in modules/forum/forum.test
Tests forum functionality through the admin and user interfaces.
template_preprocess_forum_list in modules/forum/forum.module
Preprocesses variables for forum-list.tpl.php.

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