public function Date::query

Called to add the sort to a query.

Overrides SortPluginBase::query

1 method overrides Date::query()
NcsLastUpdated::query in drupal/core/modules/comment/lib/Drupal/comment/Plugin/views/sort/NcsLastUpdated.php
Called to add the sort to a query.

File

drupal/core/modules/views/lib/Drupal/views/Plugin/views/sort/Date.php, line 54
Definition of Drupal\views\Plugin\views\sort\Date.

Class

Date
Basic sort handler for dates.

Namespace

Drupal\views\Plugin\views\sort

Code

public function query() {
  $this
    ->ensureMyTable();
  switch ($this->options['granularity']) {
    case 'second':
    default:
      $this->query
        ->add_orderby($this->tableAlias, $this->realField, $this->options['order']);
      return;
    case 'minute':
      $formula = $this
        ->getSQLFormat('YmdHi');
      break;
    case 'hour':
      $formula = $this
        ->getSQLFormat('YmdH');
      break;
    case 'day':
      $formula = $this
        ->getSQLFormat('Ymd');
      break;
    case 'month':
      $formula = $this
        ->getSQLFormat('Ym');
      break;
    case 'year':
      $formula = $this
        ->getSQLFormat('Y');
      break;
  }

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