1 package Koha::SearchFilter;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Koha; if not, see <http://www.gnu.org/licenses>.
18 use JSON qw( encode_json decode_json );
22 use base qw(Koha::Object);
26 Koha::SearchFilter - Koha Search filter object class
34 my ($expanded_limit, $query_limit) = $filter->expand_filter;
36 Returns the filter as an arrayref of limit queries, and the query parts combined
37 into a string suitable to be passed to QueryBuilder
44 my $query_part = $self->query;
45 my $limits_part = $self->limits;
47 my $limits = decode_json($limits_part)->{limits};
49 my $query = decode_json($query_part);
50 my $operators = $query->{operators};
51 my $operands = $query->{operands};
52 my $indexes = $query->{indexes};
55 for( my $i = 0; $i < scalar @$operands; $i++ ){
56 next unless @$operands[$i];
57 my $index = @$indexes[$i] ? @$indexes[$i] . "=" : "";
58 my $query = "(" . @$operands[$i] . ")";
60 $operator = @$operators[$i-1] ? " " . @$operators[$i-1] . " " : scalar @$operands > $i ? " AND " : "" if $i > 0;
61 my $limit = $operator . $index . $query;
62 $query_limit .= $limit;
65 return ($limits, $query_limit);
68 =head2 Internal methods
75 return 'SearchFilter';