From 5233ed07e4b6ca8698277a8915f520b800498b00 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 14 May 2013 15:11:11 +0200 Subject: [PATCH] MT11899: Improve the previous and next items on the shelf browser The next and previous links should be a link to the next and previous items in the list. Before this patch, the previous was the first on the list and the next was the last. For example: [<] [1] [2] [3] [4] [5] [6] [>] Before this patch, the next and previous links were the same as the 1 and 6. Now, the next and previous links are the same as ... 0 and 7. Test plan: - On a detail biblio page, click on a "Browse shelf" link. - Play with the next and previous links. http://bugs.koha-community.org/show_bug.cgi?id=10856 --- C4/ShelfBrowser.pm | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/C4/ShelfBrowser.pm b/C4/ShelfBrowser.pm index c885d90..067e8af 100644 --- a/C4/ShelfBrowser.pm +++ b/C4/ShelfBrowser.pm @@ -172,7 +172,7 @@ sub GetNearbyItems { my $sth_prev_items = $dbh->prepare($prev_query . $query_cond . ' ORDER BY cn_sort DESC, itemnumber LIMIT ?'); my $sth_next_items = $dbh->prepare($next_query . $query_cond . ' ORDER BY cn_sort, itemnumber LIMIT ?'); - push @params, $num_each_side; + push @params, $num_each_side + 1; $sth_prev_items->execute(@params); $sth_next_items->execute(@params); @@ -185,11 +185,17 @@ sub GetNearbyItems { $prev_itemnumber, $prev_biblionumber ); - $next_itemnumber = $next_items[-1]->{itemnumber} if @next_items; - $next_biblionumber = $next_items[-1]->{biblionumber} if @next_items; + if ( @next_items and $#next_items > $num_each_side - 1 ) { + my $next_item = pop @next_items; + $next_itemnumber = $next_item->{itemnumber}; + $next_biblionumber = $next_item->{biblionumber}; + } - $prev_itemnumber = $prev_items[0]->{itemnumber} if @prev_items; - $prev_biblionumber = $prev_items[0]->{biblionumber} if @prev_items; + if ( @prev_items and $#prev_items > $num_each_side - 1 ) { + my $prev_item = shift @prev_items; + $prev_itemnumber = $prev_item->{itemnumber}; + $prev_biblionumber = $prev_item->{biblionumber}; + } my %result = ( next => \@next_items, -- 1.7.10.4