示例#1
0
function process_request()
{
    $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
    $order = isset($_GET['order']) ? $_GET['order'] : 'id';
    if (!in_array($order, ['id', 'price'])) {
        include 'templates/404.php';
        return;
    }
    if ($page <= 0) {
        include 'templates/404.php';
        return;
    }
    $total_rows = pdb_get_total_rows();
    $total_pages = ceil($total_rows / PAGINATION_ROWS_PER_PAGE);
    if ($page > $total_pages) {
        include 'templates/404.php';
        return;
    }
    $rows = pagination_get_page($page - 1, $order);
    if ($rows === false || $total_rows === false) {
        include 'templates/error.php';
        return;
    }
    $_VIEW['items'] = $rows;
    $_VIEW['order'] = $order;
    $_VIEW['page'] = $page;
    $_VIEW['total_pages'] = $total_pages;
    include 'templates/view_all.php';
}
示例#2
0
function __pagination_find_block($mc_handler, $block_key_generator, $comparator)
{
    $total_rows = pdb_get_total_rows();
    $total_pages = ceil($total_rows / PAGINATION_ROWS_PER_PAGE);
    $item_block_idx = floor($total_pages / PAGINATION_WARM_PAGES_STEP);
    while ($item_block_idx >= 0) {
        $block_data = memcache_get($mc_handler, $block_key_generator($item_block_idx));
        if ($block_data == false) {
            $item_block_idx--;
        } else {
            if ($comparator($block_data)) {
                $item_block_idx--;
            } else {
                break;
            }
        }
    }
    if ($item_block_idx < 0) {
        $item_block_idx = 0;
    }
    if ($block_data) {
        return [$item_block_idx, $block_data];
    }
    return false;
}