You are here

function views_date_format_sql_handler_date::query in Views Date Format SQL 7.3

Called to add the field to a query.

Overrides views_handler_field::query

File

includes/views_date_format_sql_handler_date.inc, line 31
This file contains the class to override views_handler_field_date.

Class

views_date_format_sql_handler_date
Allows to removes the date formatting from render() and put it in query().

Code

function query() {
  if ($this->options['format_date_sql'] != TRUE) {
    return parent::query();
  }
  $this
    ->ensure_my_table();

  // Add the field.
  $params = $this->options['group_type'] != 'group' ? array(
    'function' => $this->options['group_type'],
  ) : array();
  $format = $this->options['date_format'];
  $custom_format = $this->options['custom_date_format'];
  $format_string = _views_date_format_sql_get_date_format($format, $custom_format);
  $formula = views_date_sql_format($format_string, "{$this->table_alias}.{$this->real_field}");
  $this->field_alias = $this->query
    ->add_field(NULL, $formula, "{$this->table_alias}_{$this->real_field}", $params);
  $this->query
    ->add_groupby($this->field_alias);
  $this
    ->add_additional_fields();
}