class views_php_pager_helper in Views PHP 6
Helper class to deal with pager differences between Views 2 and 3.
Hierarchy
- class \views_php_pager_helper
Expanded class hierarchy of views_php_pager_helper
File
- ./
views_php.module, line 171 - Allows to use PHP in views.
View source
class views_php_pager_helper {
function __construct($view) {
$this->view = $view;
if (version_compare(views_api_version(), '3', '<')) {
// Views 2
$this->pager = $this->view->pager;
$this->view
->set_items_per_page(0);
}
else {
// Views 3
$this->pager = array(
'limit' => $this->view->query->limit,
'offset' => $this->view->query->offset,
'use_pager' => $this->view->query->pager
->use_pager(),
);
$this->view->query
->set_limit(0);
$this->view->query
->set_offset(0);
}
}
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;
}
}
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'];
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
views_php_pager_helper:: |
function | |||
views_php_pager_helper:: |
function | |||
views_php_pager_helper:: |
function |