From 80daed90590b4e40c23c5bef27d5ea7de4aa761d Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Wed, 21 Jun 2017 13:05:40 +0200 Subject: [PATCH] Bug 18833 - plugin unimarc_field_210c pagination error In plugin unimarc_field_210c, the editors search results have pagination. First page works but not other pages. The main problem whas mainly because $startfrom var was missused. It is defined in C4::Output::pagination_bar as page number. This patch corrects by using a $offset var. Also removes dead code, obsoleted by using C4::Output::pagination_bar. Also changes hardcoded results per page from 19 to 20. Test plan : - Use UNIMARC catalogue - Define in framework value builder unimarc_field_210c on 210$c - Create autority type EDITORS with heading 200$b - Create 22 authorities of that type - Index those new authorities - Create a new biblio record - Click on 210$c plugin - Click on "Search" - You see 20 results - Click on page 2 => Without patch you get empty table => With patch you get 2 results - Check that you see "Results 21 to 22 of 22" - Delete 2 autorities and retest --- cataloguing/value_builder/unimarc_field_210c.pl | 52 +++++-------------------- 1 file changed, 9 insertions(+), 43 deletions(-) diff --git a/cataloguing/value_builder/unimarc_field_210c.pl b/cataloguing/value_builder/unimarc_field_210c.pl index fe9f19a..2180694 100755 --- a/cataloguing/value_builder/unimarc_field_210c.pl +++ b/cataloguing/value_builder/unimarc_field_210c.pl @@ -64,10 +64,10 @@ my ($input) = @_; my $resultstring = $query->param('result'); my $dbh = C4::Context->dbh; - my $startfrom=$query->param('startfrom'); - $startfrom=0 if(!defined $startfrom); + my $startfrom = $query->param('startfrom') // 1; # Page number starting at 1 my ($template, $loggedinuser, $cookie); - my $resultsperpage; + my $resultsperpage = $query->param('resultsperpage') // 20; # TODO hardcoded + my $offset = ( $startfrom - 1 ) * $resultsperpage; if ($op eq "do_search") { my @marclist = $query->multi_param('marclist'); @@ -77,15 +77,12 @@ my ($input) = @_; my @value = $query->multi_param('value'); my $orderby = $query->param('orderby'); - $resultsperpage= $query->param('resultsperpage'); - $resultsperpage = 19 if(!defined $resultsperpage); - # builds tag and subfield arrays my @tags; my ($results,$total) = SearchAuthorities( \@tags,\@and_or, \@excluding, \@operator, \@value, - $startfrom*$resultsperpage, $resultsperpage,$authtypecode, $orderby); + $offset, $resultsperpage,$authtypecode, $orderby); # Getting the $b if it exists for (@$results) { @@ -104,49 +101,18 @@ my ($input) = @_; debug => 1, }); - # multi page display gestion - my $displaynext=0; - my $displayprev=$startfrom; - if(($total - (($startfrom+1)*($resultsperpage))) > 0 ) { - $displaynext = 1; - } - - my @numbers = (); - - if ($total>$resultsperpage) { - for (my $i=1; $i<$total/$resultsperpage+1; $i++) { - if ($i<16) { - my $highlight=0; - ($startfrom==($i-1)) && ($highlight=1); - push @numbers, { number => $i, - highlight => $highlight , - startfrom => ($i-1)}; - } - } - } - - my $from = $startfrom*$resultsperpage+1; - my $to; - - if($total < (($startfrom+1)*$resultsperpage)) { - $to = $total; - } else { - $to = (($startfrom+1)*$resultsperpage); - } + # Results displayed in current page + my $from = $offset + 1; + my $to = ( $offset + $resultsperpage > $total ) ? $total : $offset + $resultsperpage; + my $link="../cataloguing/plugin_launcher.pl?plugin_name=unimarc_field_210c.pl&authtypecode=EDITORS&".join("&",map {"value=".$_} @value)."&op=do_search&type=intranet&index=$index"; $template->param(result => $results) if $results; $template->param('index' => scalar $query->param('index')); - $template->param(startfrom=> $startfrom, - displaynext=> $displaynext, - displayprev=> $displayprev, - resultsperpage => $resultsperpage, - startfromnext => $startfrom+1, - startfromprev => $startfrom-1, + $template->param( total=>$total, from=>$from, to=>$to, - numbers=>\@numbers, authtypecode =>$authtypecode, resultstring =>$value[0], pagination_bar => pagination_bar( -- 2.7.4