Merge branch 'master' of github.com:kivitendo/kivitendo-erp
[kivitendo-erp.git] / SL / Controller / Helper / ParseFilter.pm
index 8b26e88..afe9b7b 100644 (file)
@@ -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.
@@ -80,7 +81,7 @@ sub flatten {
     next if !defined $value || $value eq ''; # 0 is fine
     if ('HASH' eq ref $value) {
       my ($query, $more_objects) = flatten($value, _prefix($prefix, $key));
-      push @result,        @$query if $query;
+      push @result, @$query        if  $query;
       _add_uniq($with_objects, $_) for _prefix($prefix, $key), @$more_objects;
     } else {
       push @result, _prefix($prefix, $key) => $value;
@@ -105,7 +106,7 @@ sub _parse_filter {
     ($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};
 
-    push @result, $key, $value;
+    push @result, $key, $value if defined $key;
   }
   return \@result;
 }
@@ -383,6 +384,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 ::)