From: Iain Patterson Date: Mon, 4 Apr 2016 13:09:29 +0000 (-0400) Subject: Fixed pagination of orders. X-Git-Tag: 2016-04-04~1 X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=018b041d077a8740dde27529a1ffc32f4610b7ef;p=readifood.git Fixed pagination of orders. Pagination starts at page 1 not offset 0. --- diff --git a/lib/functions.php b/lib/functions.php index 424d340..9690d5d 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -22,11 +22,11 @@ } function pagination() { - $offset = 0; + $offset = 1; $per_page = $GLOBALS['default_page_size']; parse_str($_SERVER['QUERY_STRING'], $params); - if (array_key_exists('page', $params)) if (is_numeric($params['page'])) $offset = $params['page'] - 1; + if (array_key_exists('page', $params)) if (is_numeric($params['page'])) $offset = $params['page']; if (array_key_exists('size', $params)) if (is_numeric($params['size'])) $per_page = $params['size']; return array($offset, $per_page); @@ -45,13 +45,11 @@ if (! $pager->haveToPaginate()) return; list($offset, $per_page) = pagination(); - $offset++; - - $links = array(); $pages = ceil($pager->getNbResults() / $per_page); $pages++; + $links = array(); $links[] = page_link('First', 1, $offset, $pages, $per_page); $links[] = page_link('Previous', $offset - 1, $offset, $pages, $per_page); foreach ($pager->getLinks($n) as $link) $links[] = page_link($link, $link, $offset, $pages, $per_page); diff --git a/lib/order.php b/lib/order.php index 6a242e7..622ad18 100644 --- a/lib/order.php +++ b/lib/order.php @@ -52,7 +52,7 @@ # XXX: Doesn't work. #if (isset($state_mask)) $q->useOrderStateQuery()->addSelectQuery($latest_state, 'latestState')->where("order_id=latestState.order_id")->where("state & $state_mask")->endUse(); if (isset($state_mask)) $q->filterById($order_ids); - $orders = $q->orderByDate('desc')->paginate($offset, $per_page); + $orders = $q->orderByDate('desc')->orderById('desc')->paginate($offset, $per_page); if (count($orders)) { foreach ($orders as $order) { echo "
\n" . get_order_summary($order) . "
\n";