Bugzilla – Attachment 116516 Details for
Bug 23763
Move pagination calculations to a subroutine
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23763: Make search on staff and opac use new routine
Bug-23763-Make-search-on-staff-and-opac-use-new-ro.patch (text/plain), 10.24 KB, created by
Jonathan Druart
on 2021-02-08 15:44:33 UTC
(
hide
)
Description:
Bug 23763: Make search on staff and opac use new routine
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2021-02-08 15:44:33 UTC
Size:
10.24 KB
patch
obsolete
>From a9e169ad7e6898ed34e92eddb4b1c081db5097cc Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Mon, 7 Oct 2019 14:20:32 +0000 >Subject: [PATCH] Bug 23763: Make search on staff and opac use new routine > >To test: >1 - Apply patch >2 - Search on staff and opac side >3 - Confirm you can paginate results >4 - Confirm you see 10 pages on pagination if under page 10 >5 - Confirm you see 20 pages in pagination if over page 10 >6 - Confirm you can go to first or last page > >Signed-off-by: David Nind <david@davidnind.com> > >Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> > >JD amended patch: perltidy >--- > catalogue/search.pl | 70 ++++++--------------------------- > opac/opac-search.pl | 75 ++++++++---------------------------- > t/Koha/SearchEngine/Search.t | 2 +- > 3 files changed, 28 insertions(+), 119 deletions(-) > >diff --git a/catalogue/search.pl b/catalogue/search.pl >index d354a40eeb..1419759c85 100755 >--- a/catalogue/search.pl >+++ b/catalogue/search.pl >@@ -598,66 +598,20 @@ for (my $i=0;$i<@servers;$i++) { > $line->{'incart'} = 1; > } > } >- $template->param(SEARCH_RESULTS => \@newresults); >- ## FIXME: add a global function for this, it's better than the current global one >- ## Build the page numbers on the bottom of the page >- my @page_numbers; >- my $max_result_window = $searcher->max_result_window; >- my $hits_to_paginate = ($max_result_window && $max_result_window < $hits) ? $max_result_window : $hits; >- $template->param( hits_to_paginate => $hits_to_paginate ); >- # total number of pages there will be >- my $pages = ceil($hits_to_paginate / $results_per_page); >- my $last_page_offset = ( $pages -1 ) * $results_per_page; >- # default page number >- my $current_page_number = 1; >- $current_page_number = ($offset / $results_per_page + 1) if $offset; >- my $previous_page_offset; >- if ( $offset >= $results_per_page ) { >- $previous_page_offset = $offset - $results_per_page; >- } >- my $next_page_offset = $offset + $results_per_page; >- # If we're within the first 10 pages, keep it simple >- #warn "current page:".$current_page_number; >- if ($current_page_number < 10) { >- # just show the first 10 pages >- # Loop through the pages >- my $pages_to_show = 10; >- $pages_to_show = $pages if $pages<10; >- for (my $i=1; $i<=$pages_to_show;$i++) { >- # the offset for this page >- my $this_offset = (($i*$results_per_page)-$results_per_page); >- # the page number for this page >- my $this_page_number = $i; >- # put it in the array >- push @page_numbers, >- { offset => $this_offset, >- pg => $this_page_number, >- # it should only be highlighted if it's the current page >- highlight => $this_page_number == $current_page_number, >- sort_by => join ' ', @sort_by >- }; >- >- } >- >- } >- >- # now, show twenty pages, with the current one smack in the middle >- else { >- for (my $i=$current_page_number; $i<=($current_page_number + 20 );$i++) { >- my $this_offset = ((($i-9)*$results_per_page)-$results_per_page); >- my $this_page_number = $i-9; >- if ( $this_page_number <= $pages ) { >- push @page_numbers, >- { offset => $this_offset, >- pg => $this_page_number, >- highlight => $this_page_number == $current_page_number, >- sort_by => join ' ', @sort_by >- }; >+ my( $page_numbers, $hits_to_paginate, $pages, $current_page_number, $previous_page_offset, $next_page_offset, $last_page_offset ) = >+ Koha::SearchEngine::Search->pagination_bar( >+ { >+ hits => $hits, >+ max_result_window => $searcher->max_result_window, >+ results_per_page => $results_per_page, >+ offset => $offset, >+ sort_by => \@sort_by > } >- } >- } >+ ); >+ $template->param( hits_to_paginate => $hits_to_paginate ); >+ $template->param(SEARCH_RESULTS => \@newresults); > # FIXME: no previous_page_offset when pages < 2 >- $template->param( PAGE_NUMBERS => \@page_numbers, >+ $template->param( PAGE_NUMBERS => $page_numbers, > last_page_offset => $last_page_offset, > previous_page_offset => $previous_page_offset) unless $pages < 2; > $template->param( next_page_offset => $next_page_offset) unless $pages eq $current_page_number; >diff --git a/opac/opac-search.pl b/opac/opac-search.pl >index 743db92f40..d57cabd321 100755 >--- a/opac/opac-search.pl >+++ b/opac/opac-search.pl >@@ -852,68 +852,23 @@ for (my $i=0;$i<@servers;$i++) { > OPACItemsResultsDisplay => (C4::Context->preference("OPACItemsResultsDisplay")), > suppress_result_number => $hide, > ); >- if (C4::Context->preference("OPACLocalCoverImages")){ >- $template->param(OPACLocalCoverImages => 1); >- $template->param(OPACLocalCoverImagesPriority => C4::Context->preference("OPACLocalCoverImagesPriority")); >- } >- ## Build the page numbers on the bottom of the page >- my @page_numbers; >- my $max_result_window = $searcher->max_result_window; >- my $hits_to_paginate = ($max_result_window && $max_result_window < $hits) ? $max_result_window : $hits; >- $template->param( hits_to_paginate => $hits_to_paginate ); >- # total number of pages there will be >- my $pages = ceil($hits_to_paginate / $results_per_page); >- my $last_page_offset = ( $pages - 1 ) * $results_per_page; >- # default page number >- my $current_page_number = 1; >- if ($offset) { >- $current_page_number = ( $offset / $results_per_page + 1 ); >- } >- my $previous_page_offset; >- if ( $offset >= $results_per_page ) { >- $previous_page_offset = $offset - $results_per_page; >- } >- my $next_page_offset = $offset + $results_per_page; >- # If we're within the first 10 pages, keep it simple >- #warn "current page:".$current_page_number; >- if ($current_page_number < 10) { >- # just show the first 10 pages >- # Loop through the pages >- my $pages_to_show = 10; >- $pages_to_show = $pages if $pages<10; >- for ($i=1; $i<=$pages_to_show;$i++) { >- # the offset for this page >- my $this_offset = (($i*$results_per_page)-$results_per_page); >- # the page number for this page >- my $this_page_number = $i; >- # put it in the array >- push @page_numbers, >- { offset => $this_offset, >- pg => $this_page_number, >- highlight => $this_page_number == $current_page_number, >- sort_by => join ' ', @sort_by >- }; >- >- } >- >+ if (C4::Context->preference("OPACLocalCoverImages")){ >+ $template->param(OPACLocalCoverImages => 1); >+ $template->param(OPACLocalCoverImagesPriority => C4::Context->preference("OPACLocalCoverImagesPriority")); > } >- # now, show twenty pages, with the current one smack in the middle >- else { >- for ($i=$current_page_number; $i<=($current_page_number + 20 );$i++) { >- my $this_offset = ((($i-9)*$results_per_page)-$results_per_page); >- my $this_page_number = $i-9; >- if ( $this_page_number <= $pages ) { >- push @page_numbers, >- { offset => $this_offset, >- pg => $this_page_number, >- highlight => $this_page_number == $current_page_number, >- sort_by => join ' ', @sort_by >- }; >+ ## Build the page numbers on the bottom of the page >+ my ( $page_numbers, $hits_to_paginate, $pages, $current_page_number, $previous_page_offset, $next_page_offset, $last_page_offset ) = >+ Koha::SearchEngine::Search->pagination_bar( >+ { >+ hits => $hits, >+ max_result_window => $searcher->max_result_window, >+ results_per_page => $results_per_page, >+ offset => $offset, >+ sort_by => \@sort_by > } >- } >- >- } >- $template->param( PAGE_NUMBERS => \@page_numbers, >+ ); >+ $template->param( hits_to_paginate => $hits_to_paginate ); >+ $template->param( PAGE_NUMBERS => $page_numbers, > last_page_offset => $last_page_offset, > previous_page_offset => $previous_page_offset) unless $pages < 2; > $template->param(next_page_offset => $next_page_offset) unless $pages eq $current_page_number; >diff --git a/t/Koha/SearchEngine/Search.t b/t/Koha/SearchEngine/Search.t >index c7b779a3f5..9dba9f3202 100644 >--- a/t/Koha/SearchEngine/Search.t >+++ b/t/Koha/SearchEngine/Search.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 5; >+use Test::More tests => 1; > use Test::Exception; > > use t::lib::Mocks; >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 23763
:
93824
|
93825
|
114674
|
115720
|
115721
|
116475
|
116476
|
116477
|
116515
| 116516