You are here

function commerce_reports_handler_sort_date::query in Commerce Reporting 7.4

Called to add the sort to a query.

Overrides views_handler_sort_date::query

File

includes/views/handlers/commerce_reports_handler_sort_date.inc, line 22
Definition of commerce_reports_handler_sort_date.

Class

commerce_reports_handler_sort_date
Extends views_handler_sort_date to add Week granularity

Code

function query() {
  $this
    ->ensure_my_table();
  switch ($this->options['granularity']) {
    case 'second':
    default:
      $this->query
        ->add_orderby($this->table_alias, $this->real_field, $this->options['order']);
      return;
    case 'minute':
      $formula = views_date_sql_format('YmdHi', "{$this->table_alias}.{$this->real_field}");
      break;
    case 'hour':
      $formula = views_date_sql_format('YmdH', "{$this->table_alias}.{$this->real_field}");
      break;
    case 'day':
      $formula = views_date_sql_format('Ymd', "{$this->table_alias}.{$this->real_field}");
      break;
    case 'week':
      $formula = views_date_sql_format('YW', "{$this->table_alias}.{$this->real_field}");
      break;
    case 'month':
      $formula = views_date_sql_format('Ym', "{$this->table_alias}.{$this->real_field}");
      break;
    case 'year':
      $formula = views_date_sql_format('Y', "{$this->table_alias}.{$this->real_field}");
      break;
  }

  // Add the field.
  $this->query
    ->add_orderby(NULL, $formula, $this->options['order'], $this->table_alias . '_' . $this->field . '_' . $this->options['granularity']);
}