comment_get_display_ordinal
- Versions
- 7
comment_get_display_ordinal($cid, $node_type)
Get the display ordinal for a comment, starting from 0.
Count the number of comments which appear before the comment we want to display, taking into account display settings and threading.
see comment_get_display_page()
Parameters
$cid The comment ID.
$node_type The node type of the comment's parent.
Return value
The display ordinal for the comment.
Code
modules/comment/comment.module, line 1597
<?php
function comment_get_display_ordinal($cid, $node_type) {
// Count how many comments (c1) are before $cid (c2) in display order. This is
// the 0-based display ordinal.
$query = db_select('comment', 'c1');
$query->innerJoin('comment', 'c2', 'c2.nid = c1.nid');
$query->addExpression('COUNT(*)', 'count');
$query->condition('c2.cid', $cid);
if (!user_access('administer comments')) {
$query->condition('c1.status', COMMENT_PUBLISHED);
}
$mode = variable_get('comment_default_mode_' . $node_type, COMMENT_MODE_THREADED);
if ($mode == COMMENT_MODE_FLAT) {
// For flat comments, cid is used for ordering comments due to
// unpredicatable behavior with timestamp, so we make the same assumption
// here.
$query->condition('c1.cid', $cid, '<');
}
else {
// For threaded comments, the c.thread column is used for ordering. We can
// use the vancode for comparison, but must remove the trailing slash.
// @see comment_build_multiple().
$query->where('SUBSTRING(c1.thread, 1, (LENGTH(c1.thread) -1)) < SUBSTRING(c2.thread, 1, (LENGTH(c2.thread) -1))');
}
return $query->execute()->fetchField();
}
?>Login or register to post comments 