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

(-)a/Koha/REST/V1/Acquisitions/Orders.pm (-16 / +56 lines)
Lines 22-27 use Mojo::Base 'Mojolicious::Controller'; Link Here
22
use Koha::Acquisition::Orders;
22
use Koha::Acquisition::Orders;
23
23
24
use Clone qw( clone );
24
use Clone qw( clone );
25
use JSON;
25
use Scalar::Util qw( blessed );
26
use Scalar::Util qw( blessed );
26
use Try::Tiny qw( catch try );
27
use Try::Tiny qw( catch try );
27
28
Lines 78-85 sub list { Link Here
78
        if ( exists $reserved_params->{_order_by} ) {
79
        if ( exists $reserved_params->{_order_by} ) {
79
            # _order_by passed, fix if required
80
            # _order_by passed, fix if required
80
            for my $p ( @{$reserved_params->{_order_by}} ) {
81
            for my $p ( @{$reserved_params->{_order_by}} ) {
81
                $p =~ s|biblio\.|biblio\.biblioitem\.|g
82
                $p = $c->table_name_fixer($p);
82
                    if $p =~ m/.*(isbn|ean|publisher).*/;
83
            }
83
            }
84
        }
84
        }
85
85
Lines 132-155 sub list { Link Here
132
            }
132
            }
133
        }
133
        }
134
134
135
        if ( defined $reserved_params->{q} || defined $reserved_params->{query} || defined $reserved_params->{'x-koha-query'}) {
135
        if (   defined $reserved_params->{q}
136
            || defined $reserved_params->{query}
137
            || defined $reserved_params->{'x-koha-query'} )
138
        {
139
136
            $filtered_params //={};
140
            $filtered_params //={};
141
137
            my @query_params_array;
142
            my @query_params_array;
138
            my $query_params;
139
143
140
            # FIXME The following lines are an ugly fix to deal with isbn and ean searches
144
            my $json = JSON->new;
141
            # This must NOT be reused or extended
145
142
            # Instead we need a better and global solution in a Koha::*Biblio method
146
            # q is defined as multi => JSON::Validator generates an array
143
            for my $q ( qw( q query x-koha-query ) ) {
147
            # containing the string
144
                next unless $reserved_params->{$q};
148
            foreach my $q ( @{ $reserved_params->{q} } ) {
145
                for my $f ( qw( isbn ean publisher ) ) {
149
                push @query_params_array,
146
                    $reserved_params->{$q} =~ s|"biblio.$f":|"biblio.biblioitem.$f":|g;
150
                  $json->decode( $c->table_name_fixer($q) )
147
                }
151
                  if $q;    # skip if exists but is empty
148
                push @query_params_array, $reserved_params->{$q};
149
            }
152
            }
150
153
151
            if(scalar(@query_params_array) > 1) {
154
            # x-koha-query contains a string
152
                $query_params = {'-and' => \@query_params_array};
155
            push @query_params_array,
156
              $json->decode(
157
                $c->table_name_fixer( $reserved_params->{'x-koha-query'} ) )
158
              if $reserved_params->{'x-koha-query'};
159
160
            # query is already decoded by JSON::Validator at this point
161
            push @query_params_array,
162
              $json->decode(
163
                $c->table_name_fixer(
164
                    $json->encode( $reserved_params->{query} )
165
                )
166
              ) if $reserved_params->{query};
167
168
            my $query_params;
169
170
            if ( scalar(@query_params_array) > 1 ) {
171
                $query_params = { '-and' => \@query_params_array };
153
            }
172
            }
154
            else {
173
            else {
155
                $query_params = $query_params_array[0];
174
                $query_params = $query_params_array[0];
Lines 309-312 sub delete { Link Here
309
    };
328
    };
310
}
329
}
311
330
331
=head2 Internal methods
332
333
=head3 table_name_fixer
334
335
    $q = $c->table_name_fixer( $q );
336
337
The Koha::Biblio representation includes the biblioitem.* attributes. This is handy
338
for API consumers but as they are different tables, converting the queries that mention
339
biblioitem columns can be tricky. This method renames known column names as used on Koha's
340
UI.
341
342
=cut
343
344
sub table_name_fixer {
345
    my ( $self, $q ) = @_;
346
347
    $q =~ s|biblio\.|biblio\.biblioitem\.|g
348
      if $q =~ m/.*(isbn|ean|publisher).*/;
349
350
    return $q;
351
}
352
312
1;
353
1;
313
- 

Return to bug 30165