You are here

function advanced_forum_unread_comments_in_forum in Advanced Forum 5

Same name and namespace in other branches
  1. 6 advanced_forum.module \advanced_forum_unread_comments_in_forum()

Returns the number of unread posts in a given forum for a given user

1 call to advanced_forum_unread_comments_in_forum()
advanced_forum_preprocess_forum_list in ./advanced_forum.module
Preprocesses template variables for the forum list template.

File

./advanced_forum.module, line 1581
Enables the look and feel of other popular forum software.

Code

function advanced_forum_unread_comments_in_forum($tid, $uid) {
  static $result_cache = NULL;
  if (is_null($result_cache)) {
    $result_cache = array();
    $vid = variable_get('forum_nav_vocabulary', '');
    $sql = "SELECT COUNT(c.cid) AS count, tn.tid\n            FROM {comments} c\n            INNER JOIN {term_node} tn ON c.nid = tn.nid\n            INNER JOIN {term_data} td ON td.tid = tn.tid AND td.vid = %d\n            LEFT JOIN {history} h ON c.nid = h.nid AND h.uid = %d\n            WHERE c.status = 0 AND c.timestamp > %d AND (c.timestamp > h.timestamp OR h.timestamp IS NULL)\n            GROUP BY tn.tid";
    $sql = db_rewrite_sql($sql, 'c', 'cid');
    $result = db_query($sql, $vid, $uid, NODE_NEW_LIMIT);
    while ($row = db_fetch_array($result)) {
      $result_cache[$row['tid']] = $row['count'];
    }
  }
  return isset($result_cache[$tid]) ? $result_cache[$tid] : 0;
}