bug fixed: on admin/stopwords, the calculation of the number of pages to
authorplg <plg>
Fri, 7 Apr 2006 08:24:36 +0000 (08:24 +0000)
committerplg <plg>
Fri, 7 Apr 2006 08:24:36 +0000 (08:24 +0000)
display in the pagination bar was wrong on extreme case (when number of
items equals the pagesize). Calculation replaced by a generic function
getnbpages in C4::Koha. This function could be useful elsewhere than in
stpwords management screen and avoid calculation bugs as I did.

C4/Koha.pm
admin/stopwords.pl

index abd6512..48f4d67 100644 (file)
@@ -62,6 +62,7 @@ Koha.pm provides many functions for Koha scripts.
                        &getauthtypes &getauthtype
                        &getallthemes &getalllanguages
                        &getallbranches &getletters
+                        getnbpages
                        $DEBUG);
 
 use vars qw();
@@ -732,6 +733,18 @@ sub getallthemes {
     return @themes;
 }
 
+=item getnbpages
+
+Returns the number of pages to display in a pagination bar, given the number
+of items and the number of items per page.
+
+=cut
+
+sub getnbpages {
+    my ($nb_items, $nb_items_per_page) = @_;
+
+    return int(($nb_items - 1) / $nb_items_per_page) + 1;
+}
 
 1;
 __END__
index 8d26716..da465c8 100755 (executable)
@@ -29,6 +29,7 @@ use strict;
 use CGI;
 use List::Util qw/min/;
 
+use C4::Koha;
 use C4::Context;
 use C4::Output;
 use C4::Search;
@@ -161,7 +162,7 @@ $template->param(
     loop => \@loop,
     pagination_bar => pagination_bar(
         $script_name,
-        int(scalar(@results) / $pagesize) + 1,
+        getnbpages(scalar @results, $pagesize),
         $page,
         'page'
     )