return array($name, $id, $args);
}
+ function pagination() {
+ $offset = 0;
+ $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('size', $params)) if (is_numeric($params['size'])) $per_page = $params['size'];
+
+ return array($offset, $per_page);
+ }
+
+ function page_link($alt, $n, $cur, $max, $size) {
+ $links = array();
+ if ($n < 1 || $n == $cur || $n > $max) return $alt;
+ $params = array('page' => $n);
+ if ($size != $GLOBALS['default_page_size']) $params['size'] = $size;
+ $url = http_build_query($params);
+ return "<a href=\"?$url\">$alt</a> ";
+ }
+
+ 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 "<p>Page: ";
+ echo implode(' / ', $links);
+ echo "</p>\n";
+ }
+
function get_city_by_name($name, $postcode_area = null, $verbose = true) {
$q = new CityQuery;
}
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;
# 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 "<br>\n" . get_order_summary($order) . "<br>\n";
}
+ show_pagination($orders);
}
else echo " none";
}