You are here

function views_php_pager_helper::synchronize in Views PHP 6

1 call to views_php_pager_helper::synchronize()
views_php_pager_helper::slice in ./views_php.module

File

./views_php.module, line 214
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 synchronize() {
  if (!empty($this->view->pager['use_pager'])) {

    // dump information about what we already know into the globals
    global $pager_page_array, $pager_total, $pager_total_items;

    // total rows in query
    $pager_total_items[$this->view->pager['element']] = $this->view->total_rows;

    // total pages
    $pager_total[$this->view->pager['element']] = ceil($pager_total_items[$this->view->pager['element']] / $this->view->pager['items_per_page']);

    // What page was requested:
    $pager_page_array = isset($_GET['page']) ? explode(',', $_GET['page']) : array();

    // If the requested page was within range. $this->pager['current_page']
    // defaults to 0 so we don't need to set it in an out-of-range condition.
    if (!empty($pager_page_array[$this->view->pager['element']])) {
      $page = intval($pager_page_array[$this->view->pager['element']]);
      if ($page > 0 && $page < $pager_total[$this->view->pager['element']]) {
        $this->view->pager['current_page'] = $page;
      }
    }
    $pager_page_array[$this->view->pager['element']] = $this->view->pager['current_page'];
  }
}