|
Lines 121-134
sub list {
Link Here
|
| 121 |
$filtered_params //={}; |
121 |
$filtered_params //={}; |
| 122 |
my @query_params_array; |
122 |
my @query_params_array; |
| 123 |
my $query_params; |
123 |
my $query_params; |
| 124 |
if ( exists $reserved_params->{query} and defined $reserved_params->{query} ) { |
124 |
|
| 125 |
push @query_params_array, fix_query({ query => $reserved_params->{query} }); |
125 |
# FIXME The following lines are an ugly fix to deal with isbn and ean searches |
| 126 |
} |
126 |
# This must NOT be reused or extended |
| 127 |
if ( exists $reserved_params->{q} and defined $reserved_params->{q}) { |
127 |
# Instead we need a better and global solution in a Koha::*Biblio method |
| 128 |
push @query_params_array, fix_query({ query => decode_json($reserved_params->{q}) }); |
128 |
for my $q ( qw( q query x-koha-query ) ) { |
| 129 |
} |
129 |
next unless $reserved_params->{$q}; |
| 130 |
if ( exists $reserved_params->{'x-koha-query'} and defined $reserved_params->{'x-koha-query'} ) { |
130 |
$reserved_params->{$q} =~ s|"biblio.isbn":|"biblio.biblioitem.isbn":|g; |
| 131 |
push @query_params_array, fix_query({ query => decode_json($reserved_params->{'x-koha-query'}) });; |
131 |
$reserved_params->{$q} =~ s|"biblio.ean":|"biblio.biblioitem.ean":|g; |
|
|
132 |
push @query_params_array, $reserved_params->{$q}; |
| 132 |
} |
133 |
} |
| 133 |
|
134 |
|
| 134 |
if(scalar(@query_params_array) > 1) { |
135 |
if(scalar(@query_params_array) > 1) { |
|
Lines 292-369
sub delete {
Link Here
|
| 292 |
}; |
293 |
}; |
| 293 |
} |
294 |
} |
| 294 |
|
295 |
|
| 295 |
=head2 Internal methods |
|
|
| 296 |
|
| 297 |
=head3 fix_query |
| 298 |
|
| 299 |
my $query = fix_query($query); |
| 300 |
|
| 301 |
This method takes care of recursively fixing queries that should be done |
| 302 |
against biblioitems (instead if biblio as exposed on the API) |
| 303 |
|
| 304 |
=cut |
| 305 |
|
| 306 |
sub fix_query { |
| 307 |
my ($args) = @_; |
| 308 |
|
| 309 |
my $query = $args->{query}; |
| 310 |
my $biblioitem_fields = { |
| 311 |
'biblio.age_restriction' => 'biblio.biblioitem.age_restriction', |
| 312 |
'biblio.cn_class' => 'biblio.biblioitem.cn_class', |
| 313 |
'biblio.cn_item' => 'biblio.biblioitem.cn_item', |
| 314 |
'biblio.cn_sort' => 'biblio.biblioitem.cn_sort', |
| 315 |
'biblio.cn_source' => 'biblio.biblioitem.cn_source', |
| 316 |
'biblio.cn_suffix' => 'biblio.biblioitem.cn_suffix', |
| 317 |
'biblio.collection_issn' => 'biblio.biblioitem.collection_issn', |
| 318 |
'biblio.collection_title' => 'biblio.biblioitem.collection_title', |
| 319 |
'biblio.collection_volume' => 'biblio.biblioitem.collection_volume', |
| 320 |
'biblio.ean' => 'biblio.biblioitem.ean', |
| 321 |
'biblio.edition_statement' => 'biblio.biblioitem.edition_statement', |
| 322 |
'biblio.illustrations' => 'biblio.biblioitem.illustrations', |
| 323 |
'biblio.isbn' => 'biblio.biblioitem.isbn', |
| 324 |
'biblio.issn' => 'biblio.biblioitem.issn', |
| 325 |
'biblio.item_type' => 'biblio.biblioitem.item_type', |
| 326 |
'biblio.lc_control_number' => 'biblio.biblioitem.lc_control_number', |
| 327 |
'biblio.material_size' => 'biblio.biblioitem.material_size', |
| 328 |
'biblio.notes' => 'biblio.biblioitem.notes', |
| 329 |
'biblio.number' => 'biblio.biblioitem.number', |
| 330 |
'biblio.pages' => 'biblio.biblioitem.pages', |
| 331 |
'biblio.publication_place' => 'biblio.biblioitem.publication_place', |
| 332 |
'biblio.publication_year' => 'biblio.biblioitem.publication_year', |
| 333 |
'biblio.publisher' => 'biblio.biblioitem.publisher', |
| 334 |
'biblio.serial_total_issues' => 'biblio.biblioitem.serial_total_issues', |
| 335 |
'biblio.url' => 'biblio.biblioitem.url', |
| 336 |
'biblio.volume' => 'biblio.biblioitem.volume', |
| 337 |
'biblio.volume_date' => 'biblio.biblioitem.volume_date', |
| 338 |
'biblio.volume_description' => 'biblio.biblioitem.volume_description', |
| 339 |
}; |
| 340 |
|
| 341 |
if ( ref($query) eq 'HASH' ) { |
| 342 |
foreach my $key (keys %{$query}) { |
| 343 |
if ( exists $biblioitem_fields->{$key}) { |
| 344 |
my $subq = delete $query->{$key}; |
| 345 |
$query->{$biblioitem_fields->{$key}} = (ref($subq) eq 'HASH') |
| 346 |
? fix_query({ query => $subq }) |
| 347 |
: $subq; |
| 348 |
} |
| 349 |
else { |
| 350 |
$query->{$key} = fix_query({ query => $query->{$key} }); |
| 351 |
} |
| 352 |
} |
| 353 |
} |
| 354 |
elsif ( ref($query) eq 'ARRAY' ) { |
| 355 |
my @accum; |
| 356 |
foreach my $item (@{$query}) { |
| 357 |
push @accum, fix_query({ query => $item }); |
| 358 |
} |
| 359 |
$query = \@accum; |
| 360 |
} |
| 361 |
else { # scalar |
| 362 |
$query = $biblioitem_fields->{$query} |
| 363 |
if exists $biblioitem_fields->{$query}; |
| 364 |
} |
| 365 |
|
| 366 |
return $query; |
| 367 |
} |
| 368 |
|
| 369 |
1; |
296 |
1; |
| 370 |
- |
|
|