Lines 21-26
use Mojo::Base 'Mojolicious::Controller';
Link Here
|
21 |
|
21 |
|
22 |
use Koha::Biblios; |
22 |
use Koha::Biblios; |
23 |
use Koha::RecordProcessor; |
23 |
use Koha::RecordProcessor; |
|
|
24 |
use Koha::SearchEngine::Search; |
24 |
use C4::Biblio qw( DelBiblio ); |
25 |
use C4::Biblio qw( DelBiblio ); |
25 |
|
26 |
|
26 |
use List::MoreUtils qw( any ); |
27 |
use List::MoreUtils qw( any ); |
Lines 142-147
sub delete {
Link Here
|
142 |
}; |
143 |
}; |
143 |
} |
144 |
} |
144 |
|
145 |
|
|
|
146 |
=head3 get_biblios_public |
147 |
|
148 |
Controller function that handles retrieving biblios by querying the database |
149 |
via the searchengine that's currently in use. Use the q_ccl query paramater. |
150 |
|
151 |
=cut |
152 |
|
153 |
sub get_biblios_public { |
154 |
|
155 |
my $c = shift->openapi->valid_input or return; |
156 |
|
157 |
my $requested_content_type = $c->req->headers->header('Accept'); |
158 |
my $searcher = Koha::SearchEngine::Search->new( { index => 'biblios' } ); |
159 |
my $query = $c->validation->param('q_ccl'); |
160 |
my $record_processor = Koha::RecordProcessor->new( |
161 |
{ |
162 |
filters => 'ViewPolicy', |
163 |
options => { |
164 |
interface => 'opac', |
165 |
} |
166 |
} |
167 |
); |
168 |
|
169 |
my ( $error, $results, $total_hits ) = |
170 |
$searcher->simple_search_compat( $query, 0, undef ); |
171 |
|
172 |
if ( !$total_hits ) { |
173 |
return $c->render( |
174 |
status => 404, |
175 |
openapi => { |
176 |
error => 'Nothing found.' |
177 |
} |
178 |
); |
179 |
} |
180 |
|
181 |
sub format_record_by_content_type { |
182 |
my ($args) = @_; |
183 |
|
184 |
if ( $args->{'content_type'} eq 'application/marc-in-json' ) { |
185 |
for my $record ( @{ $args->{'records'} } ) { |
186 |
$record = $record->to_mij; |
187 |
} |
188 |
return ( q{[} . ( join q{,}, @{ $args->{'records'} } ) . q{]} ); |
189 |
} |
190 |
|
191 |
# Insert additional content types here or above, you know .. alphabetically |
192 |
} |
193 |
|
194 |
sub process_record { |
195 |
my ($args) = @_; |
196 |
|
197 |
my $biblionumber = |
198 |
$args->{'searcher'}->extract_biblionumber( $args->{'record'} ); |
199 |
my $biblio = Koha::Biblios->find( { biblionumber => $biblionumber } ); |
200 |
|
201 |
if ( |
202 |
!( |
203 |
$args->{'patron'} |
204 |
&& $args->{'patron'}->category->override_hidden_items |
205 |
) |
206 |
) |
207 |
{ |
208 |
if ( $biblio->hidden_in_opac( { rules => $args->{'rules'} } ) ) { |
209 |
next; |
210 |
} |
211 |
} |
212 |
|
213 |
$args->{'processor'}->process( $args->{'record'} ); |
214 |
|
215 |
return $args->{'record'}; |
216 |
} |
217 |
|
218 |
return try { |
219 |
|
220 |
my $marcflavour = C4::Context->preference('marcflavour'); |
221 |
|
222 |
# Apply framework's filtering to MARC::Record object |
223 |
|
224 |
my $patron = $c->stash('koha.user'); |
225 |
my $opachiddenitems_rules = |
226 |
C4::Context->yaml_preference('OpacHiddenItems'); |
227 |
|
228 |
my @records; |
229 |
for my $result ( @{$results} ) { |
230 |
|
231 |
if ( ref($result) eq q{} ) { next; } |
232 |
|
233 |
push @records, |
234 |
process_record( |
235 |
{ |
236 |
searcher => $searcher, |
237 |
processor => $record_processor, |
238 |
record => $result, |
239 |
patron => $patron, |
240 |
rules => $opachiddenitems_rules |
241 |
} |
242 |
); |
243 |
} |
244 |
|
245 |
my $response = |
246 |
format_record_by_content_type( |
247 |
{ content_type => $requested_content_type, records => \@records } ); |
248 |
|
249 |
$c->respond_to( |
250 |
mij => { |
251 |
status => 200, |
252 |
format => 'mij', |
253 |
data => $response |
254 |
}, |
255 |
any => { |
256 |
status => 406, |
257 |
openapi => [ 'application/marc-in-json', ] |
258 |
} |
259 |
); |
260 |
} |
261 |
catch { |
262 |
$c->unhandled_exception($_); |
263 |
}; |
264 |
} |
265 |
|
145 |
=head3 get_public |
266 |
=head3 get_public |
146 |
|
267 |
|
147 |
Controller function that handles retrieving a single biblio object |
268 |
Controller function that handles retrieving a single biblio object |