You are here

function node_gallery_api_views_handler_comments_count::query in Node Gallery 7

Called to add the field to a query.

Overrides views_handler_field::query

File

includes/views/node_gallery_api_views_handler_comments_count.inc, line 10
Creates an comments count handler that totals all comments made on a gallery and all images within it

Class

node_gallery_api_views_handler_comments_count
@file Creates an comments count handler that totals all comments made on a gallery and all images within it

Code

function query() {
  $this
    ->ensure_my_table();
  $sql = "SELECT COUNT(*) FROM {comments} c\n      LEFT JOIN {node_gallery_relationship} ngi on c.nid = ngi.nid\n      LEFT JOIN {node} n on c.nid = n.nid\n      WHERE (ngi.ngid = node.nid or n.nid = node.nid) AND n.status = 1";
  $this->field_alias = $this->query
    ->add_field(NULL, "({$sql})", 'comments_count');
}