function advanced_forum_first_new_comment in Advanced Forum 7.2
Same name and namespace in other branches
- 5 advanced_forum.module \advanced_forum_first_new_comment()
- 6.2 advanced_forum.module \advanced_forum_first_new_comment()
- 6 advanced_forum.module \advanced_forum_first_new_comment()
Returns the ID of the first unread comment.
Parameters
int $nid: Node ID
int $timestamp: Date/time used to override when the user last viewed the node.
Return value
int 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 1090 - 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 = db_select('comment', 'c')
->fields('c', array(
'cid',
))
->condition('nid', $nid)
->condition('changed', $timestamp, '>')
->condition('status', COMMENT_PUBLISHED)
->range(0, 1)
->execute();
return $query
->fetchField();
}
else {
return 0;
}
}