From: Sven Schöling Date: Wed, 26 Mar 2014 16:02:45 +0000 (+0100) Subject: :multi filter für ParseFilter X-Git-Tag: release-3.2.0beta~472 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=303a4d5d9c401254c2cf623a702a9e7676fb639f;p=kivitendo-erp.git :multi filter für ParseFilter --- diff --git a/SL/Controller/Helper/ParseFilter.pm b/SL/Controller/Helper/ParseFilter.pm index 9b5eb516e..55e65e1b5 100644 --- a/SL/Controller/Helper/ParseFilter.pm +++ b/SL/Controller/Helper/ParseFilter.pm @@ -103,10 +103,24 @@ sub _parse_filter { my ($key, $value) = ($flattened->[$i], $flattened->[$i+1]); my ($type, $op) = $key =~ m{:(.+)::(.+)}; - ($key, $value) = _apply_all($key, $value, qr/\b:(\w+)/, { %filters, %{ $params{filters} || {} } }); - ($key, $value) = _apply_all($key, $value, qr/\b::(\w+)/, { %methods, %{ $params{methods} || {} } }); - ($key, $value) = _dispatch_custom_filters($params{class}, $with_objects, $key, $value) if $params{class}; - ($key, $value) = _apply_value_filters($key, $value, $type, $op); + if ($key =~ s/:multi//) { + my @multi; + my $orig_key = $key; + for my $value (split / /, $value) { + ($key, $value) = _apply_all($key, $value, qr/\b:(\w+)/, { %filters, %{ $params{filters} || {} } }); + ($key, $value) = _apply_all($key, $value, qr/\b::(\w+)/, { %methods, %{ $params{methods} || {} } }); + ($key, $value) = _dispatch_custom_filters($params{class}, $with_objects, $key, $value) if $params{class}; + ($key, $value) = _apply_value_filters($key, $value, $type, $op); + push @multi, $key, $value; + $key = $orig_key; + } + ($key, $value) = (and => \@multi); + } else { + ($key, $value) = _apply_all($key, $value, qr/\b:(\w+)/, { %filters, %{ $params{filters} || {} } }); + ($key, $value) = _apply_all($key, $value, qr/\b::(\w+)/, { %methods, %{ $params{methods} || {} } }); + ($key, $value) = _dispatch_custom_filters($params{class}, $with_objects, $key, $value) if $params{class}; + ($key, $value) = _apply_value_filters($key, $value, $type, $op); + } push @result, $key, $value if defined $key; } diff --git a/t/controllers/helpers/parse_filter.t b/t/controllers/helpers/parse_filter.t index 856ae2e33..21dbb7442 100644 --- a/t/controllers/helpers/parse_filter.t +++ b/t/controllers/helpers/parse_filter.t @@ -1,6 +1,6 @@ use lib 't'; -use Test::More tests => 28; +use Test::More tests => 30; use Test::Deep; use Data::Dumper; @@ -293,3 +293,32 @@ test { } ] }, 'Regression check: prefixing of fallback filtering in relation with custom filters', class => 'SL::DB::Manager::OrderItem'; +test { + 'description:substr:multi::ilike' => 'term1 term2', +}, { + query => [ + and => [ + description => { ilike => '%term1%' }, + description => { ilike => '%term2%' }, + ] + ] +}, 'simple :multi'; + +test { + part => { + 'all:substr:multi::ilike' => 'term1 term2', + }, +}, { + query => [ + and => [ + or => [ + 'part.partnumber' => { ilike => '%term1%' }, + 'part.description' => { ilike => '%term1%' }, + ], + or => [ + 'part.partnumber' => { ilike => '%term2%' }, + 'part.description' => { ilike => '%term2%' }, + ], + ] + ], +}, 'complex :multi with custom dispatch and prefix', class => 'SL::DB::Manager::OrderItem';