From: Iain Patterson Date: Mon, 4 Apr 2016 13:19:57 +0000 (-0400) Subject: Remove placeholder pagination code. X-Git-Tag: 2016-04-04^0 X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=6cbb29ad097d97f152a4318ddb0bc2498b2f6ca7;p=readifood.git Remove placeholder pagination code. Pagination was always a planned feature. Until now, however, it was never implemented. Now that it is in place we can remove the placeholder for the assumed implementation style which was eventually not used. --- diff --git a/lib/functions.php b/lib/functions.php index 9690d5d..2c0fdea 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -22,14 +22,14 @@ } function pagination() { - $offset = 1; + $first_page = 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']; + if (array_key_exists('page', $params)) if (is_numeric($params['page'])) $first_page = $params['page']; if (array_key_exists('size', $params)) if (is_numeric($params['size'])) $per_page = $params['size']; - return array($offset, $per_page); + return array($first_page, $per_page); } function page_link($alt, $n, $cur, $max, $size) { @@ -44,17 +44,17 @@ function show_pagination($pager, $n = 5) { if (! $pager->haveToPaginate()) return; - list($offset, $per_page) = pagination(); + list($first_page, $per_page) = pagination(); $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); - $links[] = page_link('Next', $offset + 1, $offset, $pages, $per_page); - $links[] = page_link('Last', $pages, $offset, $pages, $per_page); + $links[] = page_link('First', 1, $first_page, $pages, $per_page); + $links[] = page_link('Previous', $first_page - 1, $first_page, $pages, $per_page); + foreach ($pager->getLinks($n) as $link) $links[] = page_link($link, $link, $first_page, $pages, $per_page); + $links[] = page_link('Next', $first_page + 1, $first_page, $pages, $per_page); + $links[] = page_link('Last', $pages, $first_page, $pages, $per_page); echo "

Page: "; echo implode(' / ', $links); diff --git a/lib/order.php b/lib/order.php index 622ad18..3e3556f 100644 --- a/lib/order.php +++ b/lib/order.php @@ -42,8 +42,8 @@ exit; } - function show_orders($offset, $per_page, $requester_ids = null, $beneficiary_ids = null, $state_mask = null) { - list($offset, $per_page) = pagination(); + function show_orders($requester_ids = null, $beneficiary_ids = null, $state_mask = null) { + list($first_page, $per_page) = pagination(); /* XXX: Use Propel methods. */ if (isset($state_mask)) $order_ids = get_order_ids_by_state($state_mask); $q = new OrderQuery; @@ -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')->orderById('desc')->paginate($offset, $per_page); + $orders = $q->orderByDate('desc')->orderById('desc')->paginate($first_page, $per_page); if (count($orders)) { foreach ($orders as $order) { echo "
\n" . get_order_summary($order) . "
\n"; @@ -62,7 +62,7 @@ else echo " none"; } - function show_city_orders($offset, $per_page, $city_name, $city_id = null, $state_mask = null) { + function show_city_orders($city_name, $city_id = null, $state_mask = null) { if (isset($city_id)) $city = get_city_by_id($city_id); else if ($city_name) $city = get_city_by_name($city_name); if ($city) { @@ -71,32 +71,32 @@ foreach ($contacts as $contact) $beneficiary_ids[] = $contact->getId(); echo "

Orders in city " . $city->getLink(get_city_displayname($city)) . ":"; - return show_orders($offset, $per_page, null, $beneficiary_ids, $state_mask); + return show_orders(null, $beneficiary_ids, $state_mask); } else echo "

No such city!

\n"; } - function show_requester_orders($offset, $per_page, $contact_name, $contact_id = null, $state_mask = null) { + function show_requester_orders($contact_name, $contact_id = null, $state_mask = null) { if (isset($contact_id)) $contact = get_contact_by_id($contact_id); else if ($contact_name) $contact = get_contact_by_name($contact_name); if ($contact) { echo "

Orders from referrer " . $contact->getLink() . ":"; - return show_orders($offset, $per_page, $contact->getId(), null, $state_mask); + return show_orders($contact->getId(), null, $state_mask); } else echo "

No such contact!

\n"; } - function show_beneficiary_orders($offset, $per_page, $contact_name, $contact_id = null, $state_mask = null) { + function show_beneficiary_orders($contact_name, $contact_id = null, $state_mask = null) { if (isset($contact_id)) $contact = get_contact_by_id($contact_id); else if ($contact_name) $contact = get_contact_by_name($contact_name); if ($contact) { echo "

Orders to beneficiary " . $contact->getLink() . ":"; - return show_orders($offset, $per_page, null, $contact->getId(), $state_mask); + return show_orders(null, $contact->getId(), $state_mask); } else echo "

No such contact!

\n"; } - function show_area_orders($offset, $per_page, $area_name, $area_id = null, $state_mask = null) { + function show_area_orders($area_name, $area_id = null, $state_mask = null) { if (isset($area_id)) $area = get_area_by_id($area_id); else if ($area_name) $area = get_area_by_name($area_name); if ($area) { @@ -105,7 +105,7 @@ foreach ($contacts as $contact) $contact_ids[] = $contact->getId(); echo "

Orders in area " . $area->getLink() . ":"; - return show_orders($offset, $per_page, null, $contact_ids, $state_mask); + return show_orders(null, $contact_ids, $state_mask); } else echo "

No such area!

\n"; } @@ -636,7 +636,7 @@ $area = $q->findOneById($area_id); $city = get_area_city($area); if ($city) $city_id = $city->getId(); - show_area_orders(0, 10, $parameters[2], $area_id, $state_mask); + show_area_orders($parameters[2], $area_id, $state_mask); break; case "city": @@ -644,7 +644,7 @@ $_POST['city_id'] = $city_id; $q = new CityQuery; $city = $q->findOneById($city_id); - show_city_orders(0, 10, $parameters[2], $city_id, $state_mask); + show_city_orders($parameters[2], $city_id, $state_mask); break; } } @@ -655,7 +655,7 @@ $contact_id = $parameters[3]; $q = new ContactQuery; $contact = $q->findOneById($contact_id); - show_requester_orders(0, 10, $parameters[2], $contact_id, $state_mask); + show_requester_orders($parameters[2], $contact_id, $state_mask); break; } } @@ -666,7 +666,7 @@ $contact_id = $parameters[3]; $q = new ContactQuery; $hub = $q->findOneById($contact_id); - show_beneficiary_orders(0, 10, $parameters[2], $contact_id, $state_mask); + show_beneficiary_orders($parameters[2], $contact_id, $state_mask); break; } } @@ -694,7 +694,7 @@ } } else if (isset($id)) show_order($id); - else if ($state_mask) show_orders(0, 10, null, null, $state_mask); + else if ($state_mask) show_orders(null, null, $state_mask); show_order_forms($city_id, $state_mask); show_add_new_order_form($city_id);