You are here

public function Date::query in Views (for Drupal 7) 8.3

Called to add the sort to a query.

Overrides SortPluginBase::query

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

File

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