From: Iain Patterson Date: Tue, 29 Mar 2016 16:04:50 +0000 (-0400) Subject: Pagination for orders. X-Git-Tag: 2016-03-29^0 X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=0a03172fb7157b21a81907bd7f1c6aef41c52d29;p=readifood.git Pagination for orders. --- diff --git a/lib/constants.php b/lib/constants.php index dcffda2..83d93e5 100644 --- a/lib/constants.php +++ b/lib/constants.php @@ -1,6 +1,9 @@ $max) return $alt; + $params = array('page' => $n); + if ($size != $GLOBALS['default_page_size']) $params['size'] = $size; + $url = http_build_query($params); + return "$alt "; + } + + function show_pagination($pager, $n = 5) { + if (! $pager->haveToPaginate()) return; + + list($offset, $per_page) = pagination(); + $offset++; + + $links = array(); + + $pages = ceil($pager->getNbResults() / $per_page); + $pages++; + + $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); + $links[] = page_link('Next', $offset + 1, $offset, $pages, $per_page); + $links[] = page_link('Last', $pages, $offset, $pages, $per_page); + + echo "

Page: "; + echo implode(' / ', $links); + echo "

\n"; + } + function get_city_by_name($name, $postcode_area = null, $verbose = true) { $q = new CityQuery; diff --git a/lib/order.php b/lib/order.php index ac3cdfe..6a242e7 100644 --- a/lib/order.php +++ b/lib/order.php @@ -43,6 +43,7 @@ } function show_orders($offset, $per_page, $requester_ids = null, $beneficiary_ids = null, $state_mask = null) { + list($offset, $per_page) = pagination(); /* XXX: Use Propel methods. */ if (isset($state_mask)) $order_ids = get_order_ids_by_state($state_mask); $q = new OrderQuery; @@ -51,11 +52,12 @@ # 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()->find(); + $orders = $q->orderByDate('desc')->paginate($offset, $per_page); if (count($orders)) { foreach ($orders as $order) { echo "
\n" . get_order_summary($order) . "
\n"; } + show_pagination($orders); } else echo " none"; }