Permalink
Browse files

add support for pagination to librarians/issues. also fixed off by on…

…e issue

with pagination
  • Loading branch information...
1 parent 8c4ec10 commit 0b1fa52a0ca943a568fe3a56ff17b0d525f77dfa @vicapow vicapow committed Mar 13, 2013
Showing with 24 additions and 6 deletions.
  1. +6 −0 libs/OCAL.php
  2. +3 −4 routes/clipart.php
  3. +15 −2 routes/librarians.php
View
@@ -673,6 +673,12 @@ function is_reported($clipart){
WHERE clipart = $clipart";
return $this->db->get_value($query) >= 1;
}
+ function num_reported_clipart(){
+ $query = "SELECT
+ COUNT(*)
+ FROM openclipart_issues";
+ return $this->db->get_value($query);
+ }
function get_reported_clipart($page = 0, $results_per_page = 20){
$start = $page * $results_per_page;
$end = $start + $results_per_page;
View
@@ -6,16 +6,15 @@
});
$app->get("/clipart/latest/:page", function($page) use($app){
- $results_per_page = 24; // results per page
+ $results_per_page = 24;
$total = $app->num_clipart();
-
$start = $page * $results_per_page;
$cliparts = $app->new_clipart(false, $start, $results_per_page);
return $app->render("clipart/list", array(
'cliparts' => $cliparts
, 'title' => 'Latest Clipart'
, 'pagination' => array(
- 'pages' => round( $total / $results_per_page, 0, PHP_ROUND_HALF_UP)
+ 'pages' => round( $total / $results_per_page, 0, PHP_ROUND_HALF_UP) - 1
, 'current' => $page
)
));
@@ -34,7 +33,7 @@
'cliparts' => $cliparts
, 'title' => 'Clipart By Popularity'
, 'pagination' => array(
- 'pages' => round( $total / $results_per_page, 0, PHP_ROUND_HALF_UP)
+ 'pages' => round( $total / $results_per_page, 0, PHP_ROUND_HALF_UP) - 1
, 'current' => $page
)
));
View
@@ -8,11 +8,24 @@
});
$app->get("/librarians/issues", function() use($app){
+ $app->redirect("/librarians/issues/0");
+});
+
+$app->get("/librarians/issues/:page", function($page) use($app){
if( !$app->is("librarian") && !$app->is("admin") )
- return $app->notFound();
+ return $app->notFound();
+ $results_per_page = 24;
+ $total = $app->num_reported_clipart();
+ $start = $page * $results_per_page;
+ $cliparts = $app->get_reported_clipart($page, $results_per_page);
+ if(sizeof($cliparts) === 0) return $app->notFound();
return $app->render("clipart/list", array(
- "cliparts" => $app->get_reported_clipart()
+ "cliparts" => $cliparts
, "title" => "Clipart with issues"
+ , 'pagination' => array(
+ 'pages' => round( $total / $results_per_page, 0, PHP_ROUND_HALF_UP) - 1
+ , 'current' => $page
+ )
));
});

0 comments on commit 0b1fa52

Please sign in to comment.