You are here

public function views_handler_sort_date::query in Views (for Drupal 7) 7.3

Same name and namespace in other branches
  1. 6.3 handlers/views_handler_sort_date.inc \views_handler_sort_date::query()
  2. 6.2 handlers/views_handler_sort_date.inc \views_handler_sort_date::query()

Called to add the sort to a query.

Overrides views_handler_sort::query

1 method overrides views_handler_sort_date::query()
views_handler_sort_ncs_last_updated::query in modules/comment/views_handler_sort_ncs_last_updated.inc
Called to add the sort to a query.

File

handlers/views_handler_sort_date.inc, line 54
Definition of views_handler_sort_date.

Class

views_handler_sort_date
Basic sort handler for dates.

Code

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