You are here

public function SqlBase::query in Zircon Profile 8

Same name in this branch
  1. 8 core/modules/views/src/Plugin/views/pager/SqlBase.php \Drupal\views\Plugin\views\pager\SqlBase::query()
  2. 8 core/modules/migrate/src/Plugin/migrate/source/SqlBase.php \Drupal\migrate\Plugin\migrate\source\SqlBase::query()
Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Plugin/views/pager/SqlBase.php \Drupal\views\Plugin\views\pager\SqlBase::query()

Modify the query for paging

This is called during the build phase and can directly modify the query.

Overrides PagerPluginBase::query

1 call to SqlBase::query()
Mini::query in core/modules/views/src/Plugin/views/pager/Mini.php
Modify the query for paging
1 method overrides SqlBase::query()
Mini::query in core/modules/views/src/Plugin/views/pager/Mini.php
Modify the query for paging

File

core/modules/views/src/Plugin/views/pager/SqlBase.php, line 210
Contains \Drupal\views\Plugin\views\pager\SqlBase.

Class

SqlBase
A common base class for sql based pager.

Namespace

Drupal\views\Plugin\views\pager

Code

public function query() {
  if ($this
    ->itemsPerPageExposed()) {
    $query = $this->view
      ->getRequest()->query;
    $items_per_page = $query
      ->get('items_per_page');
    if ($items_per_page > 0) {
      $this->options['items_per_page'] = $items_per_page;
    }
    elseif ($items_per_page == 'All' && $this->options['expose']['items_per_page_options_all']) {
      $this->options['items_per_page'] = 0;
    }
  }
  if ($this
    ->isOffsetExposed()) {
    $query = $this->view
      ->getRequest()->query;
    $offset = $query
      ->get('offset');
    if (isset($offset) && $offset >= 0) {
      $this->options['offset'] = $offset;
    }
  }
  $limit = $this->options['items_per_page'];
  $offset = $this->current_page * $this->options['items_per_page'] + $this->options['offset'];
  if (!empty($this->options['total_pages'])) {
    if ($this->current_page >= $this->options['total_pages']) {
      $limit = $this->options['items_per_page'];
      $offset = $this->options['total_pages'] * $this->options['items_per_page'];
    }
  }
  $this->view->query
    ->setLimit($limit);
  $this->view->query
    ->setOffset($offset);
}