You are here

function view::synchronize_pager in Views (for Drupal 7) 6.2

Synchronize views pager with global pager variables

1 call to view::synchronize_pager()
view::execute in includes/view.inc
Execute the view's query.

File

includes/view.inc, line 138
view.inc Provides the view object type and associated methods.

Class

view
An object to contain all of the data to generate a view, plus the member functions to build the view query, execute the query and render the output.

Code

function synchronize_pager() {
  if (!empty($this->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->pager['element']] = $this->total_rows;

    // total pages
    $pager_total[$this->pager['element']] = ceil($pager_total_items[$this->pager['element']] / $this->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->pager['element']])) {
      $page = intval($pager_page_array[$this->pager['element']]);
      if ($page > 0 && $page < $pager_total[$this->pager['element']]) {
        $this->pager['current_page'] = $page;
      }
    }
    $pager_page_array[$this->pager['element']] = $this->pager['current_page'];
  }
}