You are here

function date_views_argument_handler::summary_query in Date 7

Create a summary query that matches the granularity.

Needed or Views will do a groupby on the complete date instead of only the part of the date actually used in the argument.

Overrides views_handler_argument_formula::summary_query

File

date_views/includes/date_views_argument_handler.inc, line 226
Date API views argument handler.

Class

date_views_argument_handler
Date API argument handler.

Code

function summary_query() {
  $this
    ->get_query_fields();

  // No way to do summaries on more than one field at a time.
  if (count($this->query_fields) > 1) {
    return;
  }

  // Cause query->ensure_table to perform the correct join.
  $this->table = $this->query_fields[0]['field']['table_name'];
  $this
    ->ensure_my_table();
  $field = $this->query_fields[0]['field'];
  $date_handler = $this->query_fields[0]['date_handler'];

  // Get the SQL format for this granularity, like Y-m,
  // and use that as the grouping value.
  $format = $date_handler
    ->views_formats($this->options['granularity'], 'sql');
  $this->formula = $date_handler
    ->sql_format($format, $date_handler
    ->sql_field($field['fullname']));

  // Add the computed field.
  $this->base_alias = $this->name_alias = $this->query
    ->add_field(NULL, $this->formula, $field['query_name']);
  $this->query
    ->set_count_field(NULL, $this->formula, $field['query_name']);
  return $this
    ->summary_basics(FALSE);
}