Source
protected static function render($page, $num_rows, $num_pages, CUrl $url, $limit_exceeded, $rows_per_page) {
<?php
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
/**
* Pager helper for data pagination.
*/
class CPagerHelper {
/**
* Number of page buttons (use odd number).
*/
const RANGE = 11;
/**
* Create paging line based on count of data rows and trim data rows accordingly.
*
* @param int $page page to display
* @param array $rows data rows
* @param string $sort_order data sort order: ZBX_SORT_UP or ZBX_SORT_DOWN
* @param CUrl $url data list URL
*
* @return CTag paging line
*/
public static function paginate($page, &$rows, $sort_order, CUrl $url) {
$data = self::prepareData($page, count($rows));
$paging = self::render($data['page'], $data['num_rows'], $data['num_pages'], clone $url,
$data['limit_exceeded'], $data['rows_per_page']
);
$start = ($data['page'] - 1) * $data['rows_per_page'];
$end = min($data['num_rows'], $start + $data['rows_per_page']);
$offset = ($sort_order == ZBX_SORT_DOWN) ? $data['offset_down'] : $data['offset_up'];
// Trim given rows for the current page.
$rows = array_slice($rows, $start + $offset, $end - $start, true);
return $paging;
}
/**
* Reset page number.
*/
public static function resetPage() {
CProfile::delete('web.pager.entity');
CProfile::delete('web.pager.page');
}
/**
* Save page number for given entity.
*
* @param string $entity
* @param int $page
*/
public static function savePage($entity, $page) {
CProfile::update('web.pager.entity', $entity, PROFILE_TYPE_STR);
CProfile::update('web.pager.page', $page, PROFILE_TYPE_INT);
}
/**
* Load stored page number for given entity.
*
* @param string $entity
* @param mixed $first_page substitute return value for the first page
*
* @return mixed page number (or the $first_page if wasn't stored or first page was stored)
*/
public static function loadPage($entity, $first_page = 1) {
if ($entity !== CProfile::get('web.pager.entity')) {
return $first_page;
}
$page = CProfile::get('web.pager.page', 1);
return ($page == 1) ? $first_page : $page;
}
/**