1 views_handler_sort_date.inc views_handler_sort_date::query()

Called to add the sort to a query.

Overrides views_handler_sort::query

File

core/modules/views/handlers/views_handler_sort_date.inc, line 47
Definition of views_handler_sort_date.

Class

views_handler_sort_date
Basic sort handler for dates.

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 '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']);
}