You are here

function date_api_argument_handler::summary_query in Date 6

Same name and namespace in other branches
  1. 6.2 includes/date_api_argument_handler.inc \date_api_argument_handler::summary_query()

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.

File

./date_api.views.inc, line 229
Defines date-related Views data and plugins:

Class

date_api_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;
  }
  $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']));
  $this
    ->ensure_my_table();

  // Make sure this field is added to the query so we have all necessary tables.
  $this->query
    ->add_field($field['table_name'], $field['field_name']);

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