View | Details | Raw Unified | Return to bug 23763
Collapse All | Expand All

(-)a/catalogue/search.pl (-58 / +10 lines)
Lines 598-663 for (my $i=0;$i<@servers;$i++) { Link Here
598
                    $line->{'incart'} = 1;
598
                    $line->{'incart'} = 1;
599
                }
599
                }
600
            }
600
            }
601
            $template->param(SEARCH_RESULTS => \@newresults);
601
            my( $page_numbers, $hits_to_paginate, $pages, $current_page_number, $previous_page_offset, $next_page_offset, $last_page_offset ) =
602
            ## FIXME: add a global function for this, it's better than the current global one
602
                Koha::SearchEngine::Search->pagination_bar({
603
            ## Build the page numbers on the bottom of the page
603
                    hits => $hits,
604
            my @page_numbers;
604
                    max_result_window => $searcher->max_result_window,
605
            my $max_result_window = $searcher->max_result_window;
605
                    results_per_page => $results_per_page,
606
            my $hits_to_paginate = ($max_result_window && $max_result_window < $hits) ? $max_result_window : $hits;
606
                    offset => $offset,
607
                    sort_by => \@sort_by
608
                 });
607
            $template->param( hits_to_paginate => $hits_to_paginate );
609
            $template->param( hits_to_paginate => $hits_to_paginate );
608
            # total number of pages there will be
610
            $template->param(SEARCH_RESULTS => \@newresults);
609
            my $pages = ceil($hits_to_paginate / $results_per_page);
610
            my $last_page_offset = ( $pages -1 ) * $results_per_page;
611
            # default page number
612
            my $current_page_number = 1;
613
            $current_page_number = ($offset / $results_per_page + 1) if $offset;
614
            my $previous_page_offset;
615
            if ( $offset >= $results_per_page ) {
616
                $previous_page_offset = $offset - $results_per_page;
617
            }
618
            my $next_page_offset = $offset + $results_per_page;
619
            # If we're within the first 10 pages, keep it simple
620
            #warn "current page:".$current_page_number;
621
            if ($current_page_number < 10) {
622
                # just show the first 10 pages
623
                # Loop through the pages
624
                my $pages_to_show = 10;
625
                $pages_to_show = $pages if $pages<10;
626
                for (my $i=1; $i<=$pages_to_show;$i++) {
627
                    # the offset for this page
628
                    my $this_offset = (($i*$results_per_page)-$results_per_page);
629
                    # the page number for this page
630
                    my $this_page_number = $i;
631
                    # put it in the array
632
                    push @page_numbers,
633
                      { offset    => $this_offset,
634
                        pg        => $this_page_number,
635
                        # it should only be highlighted if it's the current page
636
                        highlight => $this_page_number == $current_page_number,
637
                        sort_by   => join ' ', @sort_by
638
                      };
639
                                
640
                }
641
                        
642
            }
643
644
            # now, show twenty pages, with the current one smack in the middle
645
            else {
646
                for (my $i=$current_page_number; $i<=($current_page_number + 20 );$i++) {
647
                    my $this_offset = ((($i-9)*$results_per_page)-$results_per_page);
648
                    my $this_page_number = $i-9;
649
                    if ( $this_page_number <= $pages ) {
650
                        push @page_numbers,
651
                          { offset    => $this_offset,
652
                            pg        => $this_page_number,
653
                            highlight => $this_page_number == $current_page_number,
654
                            sort_by   => join ' ', @sort_by
655
                          };
656
                    }
657
                }
658
            }
659
            # FIXME: no previous_page_offset when pages < 2
611
            # FIXME: no previous_page_offset when pages < 2
660
            $template->param(   PAGE_NUMBERS => \@page_numbers,
612
            $template->param(   PAGE_NUMBERS => $page_numbers,
661
                                last_page_offset => $last_page_offset,
613
                                last_page_offset => $last_page_offset,
662
                                previous_page_offset => $previous_page_offset) unless $pages < 2;
614
                                previous_page_offset => $previous_page_offset) unless $pages < 2;
663
            $template->param(   next_page_offset => $next_page_offset) unless $pages eq $current_page_number;
615
            $template->param(   next_page_offset => $next_page_offset) unless $pages eq $current_page_number;
(-)a/opac/opac-search.pl (-60 / +13 lines)
Lines 875-942 for (my $i=0;$i<@servers;$i++) { Link Here
875
                OPACItemsResultsDisplay => (C4::Context->preference("OPACItemsResultsDisplay")),
875
                OPACItemsResultsDisplay => (C4::Context->preference("OPACItemsResultsDisplay")),
876
                suppress_result_number => $hide,
876
                suppress_result_number => $hide,
877
                            );
877
                            );
878
	    if (C4::Context->preference("OPACLocalCoverImages")){
878
            if (C4::Context->preference("OPACLocalCoverImages")){
879
		$template->param(OPACLocalCoverImages => 1);
879
            $template->param(OPACLocalCoverImages => 1);
880
		$template->param(OPACLocalCoverImagesPriority => C4::Context->preference("OPACLocalCoverImagesPriority"));
880
            $template->param(OPACLocalCoverImagesPriority => C4::Context->preference("OPACLocalCoverImagesPriority"));
881
	    }
881
            }
882
            ## Build the page numbers on the bottom of the page
882
            ## Build the page numbers on the bottom of the page
883
            my @page_numbers;
883
            my ( $page_numbers, $hits_to_paginate, $pages, $current_page_number, $previous_page_offset, $next_page_offset, $last_page_offset ) =
884
            my $max_result_window = $searcher->max_result_window;
884
                Koha::SearchEngine::Search->pagination_bar({
885
            my $hits_to_paginate = ($max_result_window && $max_result_window < $hits) ? $max_result_window : $hits;
885
                    hits => $hits,
886
                    max_result_window => $searcher->max_result_window,
887
                    results_per_page => $results_per_page,
888
                    offset => $offset,
889
                    sort_by => \@sort_by
890
                });
886
            $template->param( hits_to_paginate => $hits_to_paginate );
891
            $template->param( hits_to_paginate => $hits_to_paginate );
887
            # total number of pages there will be
892
            $template->param(   PAGE_NUMBERS => $page_numbers,
888
            my $pages = ceil($hits_to_paginate / $results_per_page);
889
            my $last_page_offset = ( $pages - 1 ) * $results_per_page;
890
            # default page number
891
            my $current_page_number = 1;
892
            if ($offset) {
893
                $current_page_number = ( $offset / $results_per_page + 1 );
894
            }
895
            my $previous_page_offset;
896
            if ( $offset >= $results_per_page ) {
897
                $previous_page_offset = $offset - $results_per_page;
898
            }
899
            my $next_page_offset = $offset + $results_per_page;
900
            # If we're within the first 10 pages, keep it simple
901
            #warn "current page:".$current_page_number;
902
            if ($current_page_number < 10) {
903
                # just show the first 10 pages
904
                # Loop through the pages
905
                my $pages_to_show = 10;
906
                $pages_to_show = $pages if $pages<10;
907
                for ($i=1; $i<=$pages_to_show;$i++) {
908
                    # the offset for this page
909
                    my $this_offset = (($i*$results_per_page)-$results_per_page);
910
                    # the page number for this page
911
                    my $this_page_number = $i;
912
                    # put it in the array
913
                    push @page_numbers,
914
                      { offset    => $this_offset,
915
                        pg        => $this_page_number,
916
                        highlight => $this_page_number == $current_page_number,
917
                        sort_by   => join ' ', @sort_by
918
                      };
919
920
                }
921
                        
922
            }
923
            # now, show twenty pages, with the current one smack in the middle
924
            else {
925
                for ($i=$current_page_number; $i<=($current_page_number + 20 );$i++) {
926
                    my $this_offset = ((($i-9)*$results_per_page)-$results_per_page);
927
                    my $this_page_number = $i-9;
928
                    if ( $this_page_number <= $pages ) {
929
                        push @page_numbers,
930
                          { offset    => $this_offset,
931
                            pg        => $this_page_number,
932
                            highlight => $this_page_number == $current_page_number,
933
                            sort_by => join ' ', @sort_by
934
                          };
935
                    }
936
                }
937
                        
938
            }
939
            $template->param(   PAGE_NUMBERS => \@page_numbers,
940
                                last_page_offset => $last_page_offset,
893
                                last_page_offset => $last_page_offset,
941
                                previous_page_offset => $previous_page_offset) unless $pages < 2;
894
                                previous_page_offset => $previous_page_offset) unless $pages < 2;
942
            $template->param(next_page_offset => $next_page_offset) unless $pages eq $current_page_number;
895
            $template->param(next_page_offset => $next_page_offset) unless $pages eq $current_page_number;
(-)a/t/Koha/SearchEngine/Search.t (-2 / +1 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 5;
20
use Test::More tests => 1;
21
use Test::Exception;
21
use Test::Exception;
22
22
23
use t::lib::Mocks;
23
use t::lib::Mocks;
24
- 

Return to bug 23763