You are here

function commerce_reports_handler_field_date::query in Commerce Reporting 7.3

Adds the date to the query. Adds GROUP BY and ORDER BY clause.

Overrides views_handler_field::query

File

includes/views/commerce_reports_handler_field_date.inc, line 213
Views field handler for the created date on orders.

Class

commerce_reports_handler_field_date
@file Views field handler for the created date on orders.

Code

function query() {
  $this
    ->ensure_my_table();
  $this->field_alias = sprintf("%s_%s_granularity", $this->table_alias, $this->real_field);
  $params = $this->options['group_type'] != 'group' ? array(
    'function' => $this->options['group_type'],
  ) : array();
  $this->query
    ->add_field($this->table_alias, $this->real_field, $this->field_alias, $params);

  // We group by the field using a SQL function to transform the timestamp to certain formats.
  // This way the database does the aggregation for us.
  $field_name = views_date_sql_format($this
    ->getFormat(), $this->table_alias . '.' . $this->real_field);
  $this->query
    ->add_groupby($field_name);
  $end_date = $this->endDate + $this
    ->getInterval();
  $this->query
    ->add_where_expression(0, "{$this->table_alias}.{$this->real_field} BETWEEN {$this->startDate} AND {$end_date}");
  $this
    ->add_additional_fields();
}