You are here

function advanced_forum_first_new_comment in Advanced Forum 6

Same name and namespace in other branches
  1. 5 advanced_forum.module \advanced_forum_first_new_comment()
  2. 6.2 advanced_forum.module \advanced_forum_first_new_comment()
  3. 7.2 advanced_forum.module \advanced_forum_first_new_comment()

Returns the ID of the first unread comment.

Parameters

$nid: Node ID

$timestamp: Date/time used to override when the user last viewed the node.

Return value

Comment ID

1 call to advanced_forum_first_new_comment()
advanced_forum_first_new_post_link in ./advanced_forum.module
Returns a link directly to the first new post in a topic.

File

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

Code

function advanced_forum_first_new_comment($nid, $timestamp = 0) {
  global $user;
  if ($user->uid) {

    // Retrieve the timestamp at which the current user last viewed the
    // specified node.
    if (!$timestamp) {
      $timestamp = node_last_viewed($nid);
    }

    // Set the timestamp to the limit if the node was last read past the cutoff
    $timestamp = $timestamp > NODE_NEW_LIMIT ? $timestamp : NODE_NEW_LIMIT;

    // Use the timestamp to retrieve the oldest new comment.
    $query = 'SELECT c.cid
              FROM {node} n
              INNER JOIN {comments} c ON n.nid = c.nid
              WHERE n.nid = %d AND timestamp > %d AND c.status = %d ORDER BY c.cid';
    $result = db_result(db_query_range($query, $nid, $timestamp, COMMENT_PUBLISHED, 0, 1));
    return $result;
  }
  else {
    return 0;
  }
}