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
38 id => 'search_filter_id',
39 query => 'filter_query',
40 limits => 'filter_limits',
46 my ($expanded_limit, $query_limit) = $filter->expand_filter;
48 Returns the filter as an arrayref of limit queries, and the query parts combined
49 into a string suitable to be passed to QueryBuilder
56 my $query_part = $self->query;
57 my $limits_part = $self->limits;
59 my $limits = decode_json($limits_part)->{limits};
61 my $query = decode_json($query_part);
62 my $operators = $query->{operators};
63 my $operands = $query->{operands};
64 my $indexes = $query->{indexes};
67 for( my $i = 0; $i < scalar @$operands; $i++ ){
68 next unless @$operands[$i];
69 my $index = @$indexes[$i] ? @$indexes[$i] . "=" : "";
70 my $query = "(" . @$operands[$i] . ")";
72 $operator = @$operators[$i-1] ? " " . @$operators[$i-1] . " " : scalar @$operands > $i ? " AND " : "" if $i > 0;
73 my $limit = $operator . $index . $query;
74 $query_limit .= $limit;
77 return ($limits, $query_limit);
80 =head2 Internal methods
87 return 'SearchFilter';