Revision 91a56629
Von Moritz Bunkus vor mehr als 9 Jahren hinzugefügt
SL/Controller/Helper/GetModels/Filtered.pm | ||
---|---|---|
8 | 8 |
use List::MoreUtils qw(uniq); |
9 | 9 |
|
10 | 10 |
use Rose::Object::MakeMethods::Generic ( |
11 |
scalar => [ qw(filter_args filter_params orig_filter filter) ], |
|
12 |
'scalar --get_set_init' => [ qw(form_params launder_to laundered) ],
|
|
11 |
scalar => [ qw(filter_args filter_params orig_filter filter no_launder) ],
|
|
12 |
'scalar --get_set_init' => [ qw(form_params laundered) ], |
|
13 | 13 |
); |
14 | 14 |
|
15 | 15 |
sub init { |
... | ... | |
39 | 39 |
class => $self->get_models->manager, |
40 | 40 |
with_objects => $params{with_objects}, |
41 | 41 |
); |
42 |
my $laundered; |
|
43 |
if ($self->launder_to eq '__INPLACE__') {
|
|
44 |
# nothing to do |
|
45 |
} elsif ($self->launder_to) {
|
|
46 |
$laundered = {};
|
|
47 |
$parse_filter_args{launder_to} = $laundered; |
|
42 |
|
|
43 |
# Store laundered result in $self->laundered.
|
|
44 |
|
|
45 |
if (!$self->no_launder) {
|
|
46 |
$self->laundered({});
|
|
47 |
$parse_filter_args{launder_to} = $self->laundered;
|
|
48 | 48 |
} else { |
49 |
$self->laundered(undef); |
|
49 | 50 |
$parse_filter_args{no_launder} = 1; |
50 | 51 |
} |
51 | 52 |
|
52 | 53 |
my %calculated_params = SL::Controller::Helper::ParseFilter::parse_filter($filter, %parse_filter_args); |
53 | 54 |
%calculated_params = $self->merge_args(\%calculated_params, \%filter_args, \%params); |
54 | 55 |
|
55 |
if ($laundered) { |
|
56 |
if ($self->get_models->controller->can($self->launder_to)) {
|
|
57 |
$self->get_models->controller->${\ $self->launder_to }($laundered);
|
|
56 |
if ($self->laundered) {
|
|
57 |
if ($self->get_models->controller->can('filter')) {
|
|
58 |
$self->get_models->controller->filter($self->laundered);
|
|
58 | 59 |
} else { |
59 |
$self->get_models->controller->{$self->launder_to} = $laundered;
|
|
60 |
$self->get_models->controller->{filter} = $self->laundered;
|
|
60 | 61 |
} |
61 | 62 |
} |
62 | 63 |
|
63 |
# Store laundered result in $self->laundered. |
|
64 |
$self->laundered($laundered // $filter) unless $parse_filter_args{no_launder}; |
|
65 |
|
|
66 | 64 |
# $::lxdebug->dump(0, "get_current_filter_params: ", \%calculated_params); |
67 | 65 |
|
68 | 66 |
$self->filter_params(\%calculated_params); |
... | ... | |
110 | 108 |
'filter' |
111 | 109 |
} |
112 | 110 |
|
113 |
sub init_launder_to { |
|
114 |
'filter' |
|
115 |
} |
|
116 |
|
|
117 | 111 |
sub init_laundered { |
118 | 112 |
my ($self) = @_; |
119 | 113 |
|
... | ... | |
141 | 135 |
... |
142 | 136 |
filtered => { |
143 | 137 |
filter => HASHREF, |
144 |
launder_to => HASHREF | SUBNAME | '__INPLACE__',
|
|
138 |
no_launder => 0 | 1,
|
|
145 | 139 |
} |
146 | 140 |
|
147 | 141 |
OR |
... | ... | |
171 | 165 |
|
172 | 166 |
Defaults to the value C<filter> if missing. |
173 | 167 |
|
174 |
=item * C<launder_to> |
|
175 |
|
|
176 |
Optional. Indicates a target for laundered filter arguments in the controller. |
|
177 |
Can be set to C<undef> to disable laundering, and can be set to method named or |
|
178 |
hash keys of the controller. In the latter case the laundered structure will be |
|
179 |
put there. |
|
180 |
|
|
181 |
Defaults to the controller. Laundered values will end up in C<SELF.filter> for |
|
182 |
template purposes. |
|
168 |
=item * C<no_launder> |
|
183 | 169 |
|
184 |
Setting this to the special value C<__INPLACE__> will cause inplace laundering.
|
|
170 |
Optional. If given and trueish then laundering is disabled.
|
|
185 | 171 |
|
186 | 172 |
=back |
187 | 173 |
|
Auch abrufbar als: Unified diff
GetModels Filtered: manuelles Setzen von launder_to entfernt
Dies ist ein Zwischenschritt. Das Ziel ist, den gelaunderten Filter nur
noch im Filtered-Plugin selber zu speichern und ihn von dort abzuholen.
Da launder_to bisher noch nirgends benutzt wird, sondern immer nur der
Default, kann es problemlos entfernt werden.