You are here

function advanced_forum_unread_replies_in_forum in Advanced Forum 6.2

Same name and namespace in other branches
  1. 7.2 advanced_forum.module \advanced_forum_unread_replies_in_forum()

Calculates the number of unread replies for each forum and returns the count for the requested forum.

1 call to advanced_forum_unread_replies_in_forum()
advanced_forum_process_forum in includes/advanced_forum_preprocess_forum_list.inc
Prepare an individual forum for display.

File

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

Code

function advanced_forum_unread_replies_in_forum($tid, $uid) {
  static $result_cache = NULL;
  if (is_NULL($result_cache)) {
    $result_cache = array();
    if (module_exists("nodecomment")) {
      $sql = "SELECT COUNT(nc.cid) AS count, f.tid\n              FROM {node_comments} nc\n              INNER JOIN {forum} f ON nc.nid = f.nid\n              INNER JOIN {node} n ON nc.cid = n.nid\n              INNER JOIN {node} tn ON nc.nid = tn.nid and f.vid = tn.vid\n              LEFT JOIN {history} h ON nc.nid = h.nid AND h.uid = %d\n              WHERE n.status = 1 AND n.changed > %d AND (n.changed > h.timestamp OR h.timestamp IS NULL)\n              GROUP BY f.tid";
      $sql = db_rewrite_sql($sql, 'nc', 'cid');
    }
    else {
      $sql = "SELECT COUNT(c.cid) AS count, f.tid\n              FROM {comments} c\n              INNER JOIN {forum} f ON c.nid = f.nid\n              INNER JOIN {node} n ON f.vid = n.vid\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 f.tid";
      $sql = db_rewrite_sql($sql, 'c', 'cid');
    }
    $result = db_query($sql, $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;
}