You are here

function views_php_pager_helper::slice in Views PHP 6

File

./views_php.module, line 189
Allows to use PHP in views.

Class

views_php_pager_helper
Helper class to deal with pager differences between Views 2 and 3.

Code

function slice() {
  if (isset($this->pager) && $this->pager['use_pager']) {
    if (version_compare(views_api_version(), '3', '<')) {

      // Views 2
      $this->view->pager = $this->pager;
      if (method_exists($this->view, 'synchronize_pager')) {
        $this->view
          ->synchronize_pager();
      }
      else {
        $this
          ->synchronize();
      }
      $offset = $this->view->pager['current_page'] * $this->view->pager['items_per_page'] + $this->view->pager['offset'];
      $limit = $this->view->pager['items_per_page'];
    }
    else {

      // Views 3
      $this->view->query->pager->total_items = $this->view->total_rows;
      $this->view->query->pager
        ->update_page_info();
      $this->view->query->pager
        ->query();
      $offset = $this->view->query->offset;
      $limit = $this->view->query->limit;
    }
    $results = array_slice($this->view->result, $offset, $limit);
    $this->view->result = $results;
  }
}