You are here

public function Date::query in Zircon Profile 8

Same name in this branch
  1. 8 core/modules/views/src/Plugin/views/sort/Date.php \Drupal\views\Plugin\views\sort\Date::query()
  2. 8 core/modules/datetime/src/Plugin/views/sort/Date.php \Drupal\datetime\Plugin\views\sort\Date::query()
Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Plugin/views/sort/Date.php \Drupal\views\Plugin\views\sort\Date::query()

Called to add the sort to a query.

Overrides SortPluginBase::query

1 call to Date::query()
Date::query in core/modules/datetime/src/Plugin/views/sort/Date.php
Override query to provide 'second' granularity.
2 methods override Date::query()
Date::query in core/modules/datetime/src/Plugin/views/sort/Date.php
Override query to provide 'second' granularity.
StatisticsLastUpdated::query in core/modules/comment/src/Plugin/views/sort/StatisticsLastUpdated.php
Called to add the sort to a query.

File

core/modules/views/src/Plugin/views/sort/Date.php, line 52
Contains \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
        ->addOrderBy($this->tableAlias, $this->realField, $this->options['order']);
      return;
    case 'minute':
      $formula = $this
        ->getDateFormat('YmdHi');
      break;
    case 'hour':
      $formula = $this
        ->getDateFormat('YmdH');
      break;
    case 'day':
      $formula = $this
        ->getDateFormat('Ymd');
      break;
    case 'month':
      $formula = $this
        ->getDateFormat('Ym');
      break;
    case 'year':
      $formula = $this
        ->getDateFormat('Y');
      break;
  }

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