You are here

function advanced_forum_last_post_in_topic in Advanced Forum 6.2

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

Get the comment id of the last post in a topic.

Parameters

$node: Node object

Return value

cid of last post.

1 call to advanced_forum_last_post_in_topic()
advanced_forum_last_post_link in ./advanced_forum.module
Get a link to the last post in a topic.

File

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

Code

function advanced_forum_last_post_in_topic($nid) {
  $node = node_load($nid);
  if (module_exists('nodecomment') && nodecomment_get_comment_type($node->type)) {

    // Nodecomment module version
    $query = 'SELECT nc.cid
              FROM {node_comments} nc
                INNER JOIN {node} n ON nc.nid = n.nid
              WHERE nc.nid = %d AND n.status = 1
              ORDER BY nc.cid DESC';
    $result = db_result(db_query_range($query, $nid, 0, 1));
  }
  else {

    // Comment module version
    $query = 'SELECT c.cid
              FROM {comments} c
              WHERE c.nid = %d AND c.status = %d
              ORDER BY c.cid DESC';
    $result = db_result(db_query_range($query, $nid, COMMENT_PUBLISHED, 0, 1));
  }
  return $result;
}