From 899ccae2c8e1914df7846ed68f4303cbcd7179a3 Mon Sep 17 00:00:00 2001 From: Martin Stenberg Date: Tue, 25 Aug 2015 20:21:25 +0200 Subject: [PATCH] Bug 14715: results per page setting for catalog search Add new select field to catalog search results pages which allows user to set number of results to be shown per page. Setting saved in cookie "results_per_page". --- C4/Search.pm | 4 ++-- catalogue/search.pl | 8 ++++---- .../prog/en/modules/catalogue/results.tt | 23 ++++++++++++++++++---- .../opac-tmpl/bootstrap/en/modules/opac-results.tt | 15 ++++++++++++++ opac/opac-search.pl | 14 +++++++++---- 5 files changed, 50 insertions(+), 14 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index d9a193c..35a698f 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -439,7 +439,7 @@ sub getRecords { # loop through the results $results_hash->{'hits'} = $size; my $times; - if ( $offset + $results_per_page <= $size ) { + if ( $results_per_page != 'all' && ($offset + $results_per_page <= $size) ) { $times = $offset + $results_per_page; } else { @@ -1874,7 +1874,7 @@ sub searchResults { # handle which records to actually retrieve my $times; - if ( $hits && $offset + $results_per_page <= $hits ) { + if ( $hits && $results_per_page != 'all' && ($offset + $results_per_page <= $hits) ) { $times = $offset + $results_per_page; } else { diff --git a/catalogue/search.pl b/catalogue/search.pl index 3fa25c0..11261c2 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -465,10 +465,9 @@ for (my $ii = 0; $ii < @operands; ++$ii) # Params that can only have one value my $scan = $params->{'scan'}; my $count = C4::Context->preference('numSearchResults') || 20; -my $results_per_page = $params->{'count'} || $count; -my $offset = $params->{'offset'} || 0; +my $results_per_page = $params->{'results_per_page'} || $cgi->cookie("results_per_page") || $count; my $page = $cgi->param('page') || 1; -#my $offset = ($page-1)*$results_per_page; +my $offset = $results_per_page != 'all' ? ($page-1)*$results_per_page : 0; my $hits; my $expanded_facet = $params->{'expand'}; @@ -555,6 +554,7 @@ for (my $i=0;$i<@servers;$i++) { my $server = $servers[$i]; if ($server =~/biblioserver/) { # this is the local bibliographic server $hits = $results_hashref->{$server}->{"hits"}; + $results_per_page = $hits if $results_per_page == 'all'; my $page = $cgi->param('page') || 0; my @newresults = searchResults('intranet', $query_desc, $hits, $results_per_page, $offset, $scan, $results_hashref->{$server}->{"RECORDS"}); @@ -618,7 +618,7 @@ for (my $i=0;$i<@servers;$i++) { if ($query_desc || $limit_desc) { $template->param(searchdesc => 1); } - $template->param(results_per_page => $results_per_page); + $template->param(results_per_page => $results_per_page == $hits ? 'all' : $results_per_page); # must define a value for size if not present in DB # in order to avoid problems generated by the default size value in TT foreach my $line (@newresults) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt index 3cecf8a..191ad07 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt @@ -95,9 +95,13 @@ $("#forgetholdfor").click(function(){ $(".btn-group").removeClass("open"); return false; }); -$('#sortbyform').find("input:submit").hide(); +$('#resultoptionsform').find("input:submit").hide(); $('#sort_by').change(function() { - $('#sortbyform').submit(); + $('#resultoptionsform').submit(); + }); +$('#results_per_page').change(function() { + $.cookie('results_per_page', $(this).val()); + $('#resultoptionsform').submit(); }); var param1 = "