X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FHelper%2FParseFilter.pm;h=9b5eb516ea87edf83c87fd5e95d970195ab59f55;hb=db3b23aa8ab6baaa3854259b59b033fbd23541ad;hp=1d0515cc86533e13616f2265ddb2c223f06fb822;hpb=c312836ce432677d4f7876f1e3a2b6d99f433cd6;p=kivitendo-erp.git diff --git a/SL/Controller/Helper/ParseFilter.pm b/SL/Controller/Helper/ParseFilter.pm index 1d0515cc8..9b5eb516e 100644 --- a/SL/Controller/Helper/ParseFilter.pm +++ b/SL/Controller/Helper/ParseFilter.pm @@ -22,6 +22,7 @@ my %filters = ( my %methods = ( enable => sub { ;;;; }, + eq_ignore_empty => sub { ($_[0] // '') eq '' ? () : +{ eq => $_[0] } }, map { # since $_ is an alias it can't be used in a closure. even "".$_ or "$_" # does not work, we need a real copy. @@ -100,16 +101,31 @@ sub _parse_filter { my @result; for (my $i = 0; $i < scalar @$flattened; $i += 2) { 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); - push @result, $key, $value; + push @result, $key, $value if defined $key; } return \@result; } +sub _apply_value_filters { + my ($key, $value, $type, $op) = @_; + + return ($key, $value) unless $key && $value && $type && $op && (ref($value) eq 'HASH'); + + if (($type eq 'date') && ($op eq 'le')) { + my $date = delete $value->{le}; + $value->{lt} = $date->add(days => 1); + } + + return ($key, $value); +} + sub _dispatch_custom_filters { my ($class, $with_objects, $key, $value) = @_; @@ -383,6 +399,11 @@ Adds "%" at the end of the string. Adds "% .. %" around the search string. +=item eq_ignore_empty + +Ignores this item if it's empty. Otherwise compares it with the +standard SQL C<=> operator. + =back =head2 METHODS (leading with ::)