コード例 #1
0
 public function test_item_count_on_last_page()
 {
     $lpc = PagerCalculator::calculate_item_count_on_last_page(40, 18);
     $this->assertEquals(4, $lpc);
     $lpc = PagerCalculator::calculate_item_count_on_last_page(36, 18);
     $this->assertEquals(0, $lpc);
     $lpc = PagerCalculator::calculate_item_count_on_last_page(6, 18);
     $this->assertEquals(6, $lpc);
 }
コード例 #2
0
ファイル: functions.php プロジェクト: sztanpet/aoiboard
function render_iterator($class, $page_limit, $template)
{
    list($params, $limit, $page) = build_iterator_where($page_limit);
    $item_count = ORM::count($class, $params);
    $pager_calculator = new PagerCalculator($item_count, $limit);
    $page = $pager_calculator->calculate($page);
    $offset = $pager_calculator->get_offset();
    $limit = $pager_calculator->get_limit();
    $maxpage = $pager_calculator->get_maxpage();
    $items = ORM::all($class, $params, array('ctime', 'desc'), array($offset, $limit));
    $urlparams = array('page' => $page, 'nick' => isset($params['nick']) && $params['nick'] !== null ? rawurlencode($params['nick']) : null, 'day' => isset($params['ctime']) && isset($_GET['day']) ? $_GET['day'] : null, 'week' => isset($params['ctime']) && isset($_GET['week']) ? $_GET['week'] : null, 'url' => isset($params['original_url']) && isset($_GET['url']) ? $_GET['url'] : null, 'limit' => $limit != $page_limit && isset($_GET['limit']) ? $limit : null);
    extract($GLOBALS);
    // since this is an ajax query with only the data included, we can set expires header safely when not on the last page
    if (is_xhr_request() && $page !== $maxpage) {
        header('Expires: ' . date('r', strtotime('+1 week', $_SERVER['REQUEST_TIME'])));
    }
    include APPROOT . '/' . $template;
}