Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 303a4d5d

Von Sven Schöling vor mehr als 10 Jahren hinzugefügt

  • ID 303a4d5d9c401254c2cf623a702a9e7676fb639f
  • Vorgänger 46e1177c
  • Nachfolger 57faab8f

:multi filter für ParseFilter

Unterschiede anzeigen:

SL/Controller/Helper/ParseFilter.pm
103 103
    my ($key, $value) = ($flattened->[$i], $flattened->[$i+1]);
104 104
    my ($type, $op)   = $key =~ m{:(.+)::(.+)};
105 105

  
106
    ($key, $value) = _apply_all($key, $value, qr/\b:(\w+)/,  { %filters, %{ $params{filters} || {} } });
107
    ($key, $value) = _apply_all($key, $value, qr/\b::(\w+)/, { %methods, %{ $params{methods} || {} } });
108
    ($key, $value) = _dispatch_custom_filters($params{class}, $with_objects, $key, $value) if $params{class};
109
    ($key, $value) = _apply_value_filters($key, $value, $type, $op);
106
    if ($key =~ s/:multi//) {
107
      my @multi;
108
      my $orig_key = $key;
109
      for my $value (split / /, $value) {
110
        ($key, $value) = _apply_all($key, $value, qr/\b:(\w+)/,  { %filters, %{ $params{filters} || {} } });
111
        ($key, $value) = _apply_all($key, $value, qr/\b::(\w+)/, { %methods, %{ $params{methods} || {} } });
112
        ($key, $value) = _dispatch_custom_filters($params{class}, $with_objects, $key, $value) if $params{class};
113
        ($key, $value) = _apply_value_filters($key, $value, $type, $op);
114
        push @multi, $key, $value;
115
        $key = $orig_key;
116
      }
117
      ($key, $value) = (and => \@multi);
118
    } else {
119
      ($key, $value) = _apply_all($key, $value, qr/\b:(\w+)/,  { %filters, %{ $params{filters} || {} } });
120
      ($key, $value) = _apply_all($key, $value, qr/\b::(\w+)/, { %methods, %{ $params{methods} || {} } });
121
      ($key, $value) = _dispatch_custom_filters($params{class}, $with_objects, $key, $value) if $params{class};
122
      ($key, $value) = _apply_value_filters($key, $value, $type, $op);
123
    }
110 124

  
111 125
    push @result, $key, $value if defined $key;
112 126
  }
t/controllers/helpers/parse_filter.t
1 1
use lib 't';
2 2

  
3
use Test::More tests => 28;
3
use Test::More tests => 30;
4 4
use Test::Deep;
5 5
use Data::Dumper;
6 6

  
......
293 293
   }
294 294
 ]
295 295
}, 'Regression check: prefixing of fallback filtering in relation with custom filters', class => 'SL::DB::Manager::OrderItem';
296
test {
297
  'description:substr:multi::ilike' => 'term1 term2',
298
}, {
299
  query => [
300
    and => [
301
      description => { ilike => '%term1%' },
302
      description => { ilike => '%term2%' },
303
    ]
304
  ]
305
}, 'simple :multi';
306

  
307
test {
308
  part => {
309
    'all:substr:multi::ilike' => 'term1 term2',
310
  },
311
}, {
312
  query => [
313
    and => [
314
      or => [
315
        'part.partnumber'  => { ilike => '%term1%' },
316
        'part.description' => { ilike => '%term1%' },
317
      ],
318
      or => [
319
        'part.partnumber'  => { ilike => '%term2%' },
320
        'part.description' => { ilike => '%term2%' },
321
      ],
322
    ]
323
  ],
324
}, 'complex :multi with custom dispatch and prefix', class => 'SL::DB::Manager::OrderItem';

Auch abrufbar als: Unified diff