Lines 22-27
use strict;
Link Here
|
22 |
use warnings; |
22 |
use warnings; |
23 |
|
23 |
|
24 |
use CGI qw ( -utf8 ); |
24 |
use CGI qw ( -utf8 ); |
|
|
25 |
use URI::Escape; |
25 |
use C4::Auth; |
26 |
use C4::Auth; |
26 |
|
27 |
|
27 |
use C4::Context; |
28 |
use C4::Context; |
Lines 40-50
my $op = $query->param('op') || '';
Link Here
|
40 |
my $authtypecode = $query->param('authtypecode') || ''; |
41 |
my $authtypecode = $query->param('authtypecode') || ''; |
41 |
my $dbh = C4::Context->dbh; |
42 |
my $dbh = C4::Context->dbh; |
42 |
|
43 |
|
43 |
my $startfrom = $query->param('startfrom'); |
44 |
my $startfrom = $query->param('startfrom') || 1; |
|
|
45 |
my $resultsperpage = $query->param('resultsperpage') || 20; |
44 |
my $authid = $query->param('authid'); |
46 |
my $authid = $query->param('authid'); |
45 |
$startfrom = 0 if ( !defined $startfrom ); |
|
|
46 |
my ( $template, $loggedinuser, $cookie ); |
47 |
my ( $template, $loggedinuser, $cookie ); |
47 |
my $resultsperpage; |
|
|
48 |
|
48 |
|
49 |
my $authority_types = Koha::Authority::Types->search({}, { order_by => ['authtypetext']}); |
49 |
my $authority_types = Koha::Authority::Types->search({}, { order_by => ['authtypetext']}); |
50 |
|
50 |
|
Lines 57-64
if ( $op eq "do_search" ) {
Link Here
|
57 |
my @value = $query->multi_param('value'); |
57 |
my @value = $query->multi_param('value'); |
58 |
$value[0] ||= q||; |
58 |
$value[0] ||= q||; |
59 |
|
59 |
|
60 |
$resultsperpage = $query->param('resultsperpage'); |
|
|
61 |
$resultsperpage = 20 if ( !defined $resultsperpage ); |
62 |
my @tags; |
60 |
my @tags; |
63 |
my $builder = Koha::SearchEngine::QueryBuilder->new( |
61 |
my $builder = Koha::SearchEngine::QueryBuilder->new( |
64 |
{ index => $Koha::SearchEngine::AUTHORITIES_INDEX } ); |
62 |
{ index => $Koha::SearchEngine::AUTHORITIES_INDEX } ); |
Lines 66-78
if ( $op eq "do_search" ) {
Link Here
|
66 |
{ index => $Koha::SearchEngine::AUTHORITIES_INDEX } ); |
64 |
{ index => $Koha::SearchEngine::AUTHORITIES_INDEX } ); |
67 |
my $search_query = $builder->build_authorities_query_compat( \@marclist, \@and_or, |
65 |
my $search_query = $builder->build_authorities_query_compat( \@marclist, \@and_or, |
68 |
\@excluding, \@operator, \@value, $authtypecode, $orderby ); |
66 |
\@excluding, \@operator, \@value, $authtypecode, $orderby ); |
69 |
# use Data::Dumper; |
|
|
70 |
# die Dumper(\@marclist, \@and_or, |
71 |
# \@excluding, \@operator, \@value, $authtypecode, $orderby, $query); |
72 |
# The searchengine API expects pages to start at page 1 |
73 |
$startfrom = $startfrom // 0; |
74 |
my ( $results, $total ) = |
67 |
my ( $results, $total ) = |
75 |
$searcher->search_auth_compat( $search_query, $startfrom+1, $resultsperpage ); |
68 |
$searcher->search_auth_compat( $search_query, $startfrom, $resultsperpage ); |
76 |
( $template, $loggedinuser, $cookie ) = get_template_and_user( |
69 |
( $template, $loggedinuser, $cookie ) = get_template_and_user( |
77 |
{ |
70 |
{ |
78 |
template_name => "opac-authoritiessearchresultlist.tt", |
71 |
template_name => "opac-authoritiessearchresultlist.tt", |
Lines 84-131
if ( $op eq "do_search" ) {
Link Here
|
84 |
); |
77 |
); |
85 |
|
78 |
|
86 |
# multi page display gestion |
79 |
# multi page display gestion |
87 |
my $displaynext = 0; |
80 |
my $value_url = uri_escape_utf8($value[0]); |
88 |
my $displayprev = $startfrom; |
81 |
my $base_url = "opac-authorities-home.pl?" |
89 |
$total ||= 0; |
82 |
."marclist=$marclist[0]" |
90 |
if ( ( $total - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) { |
83 |
."&and_or=$and_or[0]" |
91 |
$displaynext = 1; |
84 |
."&excluding=$excluding[0]" |
92 |
} |
85 |
."&operator=$operator[0]" |
93 |
|
86 |
."&value=$value_url" |
94 |
my @field_data = ( |
87 |
."&resultsperpage=$resultsperpage" |
95 |
{ term => "marclist", val => $marclist[0] }, |
88 |
."&type=opac" |
96 |
{ term => "and_or", val => $and_or[0] }, |
89 |
."&op=do_search" |
97 |
{ term => "excluding", val => $excluding[0] }, |
90 |
."&authtypecode=$authtypecode" |
98 |
{ term => "operator", val => $operator[0] }, |
91 |
."&orderby=$orderby"; |
99 |
{ term => "value", val => $value[0] }, |
92 |
|
100 |
); |
93 |
my $from = ( $startfrom - 1 ) * $resultsperpage + 1; |
101 |
|
|
|
102 |
my @numbers = (); |
103 |
|
104 |
if ( $total > $resultsperpage ) { |
105 |
for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) { |
106 |
if ( $i < 16 ) { |
107 |
my $highlight = 0; |
108 |
( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 ); |
109 |
push @numbers, |
110 |
{ |
111 |
number => $i, |
112 |
highlight => $highlight, |
113 |
searchdata => \@field_data, |
114 |
startfrom => ( $i - 1 ) |
115 |
}; |
116 |
} |
117 |
} |
118 |
} |
119 |
|
120 |
my $from = $startfrom * $resultsperpage + 1; |
121 |
my $to; |
94 |
my $to; |
|
|
95 |
if ( !defined $total ) { |
96 |
$total = 0; |
97 |
} |
122 |
|
98 |
|
123 |
if ( $total < ( ( $startfrom + 1 ) * $resultsperpage ) ) { |
99 |
if ( $total < $startfrom * $resultsperpage ) { |
124 |
$to = $total; |
100 |
$to = $total; |
125 |
} |
101 |
} |
126 |
else { |
102 |
else { |
127 |
$to = ( ( $startfrom + 1 ) * $resultsperpage ); |
103 |
$to = $startfrom * $resultsperpage; |
128 |
} |
104 |
} |
|
|
105 |
|
106 |
$template->param( result => $results ) if $results; |
107 |
|
108 |
$template->param( |
109 |
pagination_bar => pagination_bar( |
110 |
$base_url, int( $total / $resultsperpage ) + 1, |
111 |
$startfrom, 'startfrom' |
112 |
), |
113 |
total => $total, |
114 |
from => $from, |
115 |
to => $to, |
116 |
); |
117 |
|
129 |
unless (C4::Context->preference('OPACShowUnusedAuthorities')) { |
118 |
unless (C4::Context->preference('OPACShowUnusedAuthorities')) { |
130 |
# TODO implement usage counts |
119 |
# TODO implement usage counts |
131 |
# my @usedauths = grep { $_->{used} > 0 } @$results; |
120 |
# my @usedauths = grep { $_->{used} > 0 } @$results; |
Lines 162-183
if ( $op eq "do_search" ) {
Link Here
|
162 |
} |
151 |
} |
163 |
} |
152 |
} |
164 |
|
153 |
|
165 |
$template->param( result => $results ) if $results; |
|
|
166 |
$template->param( orderby => $orderby ); |
154 |
$template->param( orderby => $orderby ); |
167 |
$template->param( |
155 |
$template->param( |
168 |
startfrom => $startfrom, |
156 |
startfrom => $startfrom, |
169 |
displaynext => $displaynext, |
|
|
170 |
displayprev => $displayprev, |
171 |
resultsperpage => $resultsperpage, |
157 |
resultsperpage => $resultsperpage, |
172 |
startfromnext => $startfrom + 1, |
|
|
173 |
startfromprev => $startfrom - 1, |
174 |
searchdata => \@field_data, |
175 |
countfuzzy => !(C4::Context->preference('OPACShowUnusedAuthorities')), |
158 |
countfuzzy => !(C4::Context->preference('OPACShowUnusedAuthorities')), |
176 |
total => $total, |
|
|
177 |
from => $from, |
178 |
to => $to, |
179 |
resultcount => scalar @$results, |
159 |
resultcount => scalar @$results, |
180 |
numbers => \@numbers, |
|
|
181 |
authtypecode => $authtypecode, |
160 |
authtypecode => $authtypecode, |
182 |
authtypetext => $authority_types->find($authtypecode)->authtypetext, |
161 |
authtypetext => $authority_types->find($authtypecode)->authtypetext, |
183 |
isEDITORS => $authtypecode eq 'EDITORS', |
162 |
isEDITORS => $authtypecode eq 'EDITORS', |
184 |
- |
|
|