You are here

function sort_comments_query_comment_filter_alter in Sort Comments 7

File

./sort_comments.module, line 16

Code

function sort_comments_query_comment_filter_alter(QueryAlterableInterface $query) {
  if (($node = $query
    ->getMetaData('node')) && get_class($query) == 'PagerDefault') {
    $sort = variable_get('comment_default_sorting_' . $node->type, SORT_COMMENTS_OLDER_FIRST);
    if ($sort == SORT_COMMENTS_NEWER_FIRST) {
      $orderby =& $query
        ->getOrderBy();
      $expressions =& $query
        ->getExpressions();
      if (isset($orderby['torder'])) {
        unset($expressions['torder']);
        unset($orderby['torder']);
        $orderby['c.thread'] = 'DESC';
      }
      else {
        $orderby['c.cid'] = 'DESC';
      }
    }
  }
}