Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 8a5a3e9c

Von Sven Schöling vor etwa 11 Jahren hinzugefügt

  • ID 8a5a3e9c4f991f278171843a6335bcb4724bd03f
  • Vorgänger 4f949248
  • Nachfolger 26813507

Doku

Unterschiede anzeigen:

SL/Controller/Helper/GetModels/Filtered.pm
122 122

  
123 123
=head1 NAME
124 124

  
125
SL::Controller::Helper::Filtered - A helper for semi-automatic handling
126
of filtered lists of database models in a controller
125
SL::Controller::Helper::GetModels::Filtered - Filter handling plugin for GetModels
127 126

  
128 127
=head1 SYNOPSIS
129 128

  
130 129
In a controller:
131 130

  
132
  use SL::Controller::Helper::GetModels;
133
  use SL::Controller::Helper::Filtered;
134

  
135
  __PACKAGE__->make_filter(
136
    MODEL       => 'Part',
137
    ONLY        => [ qw(list) ],
138
    FORM_PARAMS => [ qw(filter) ],
139
  );
131
  SL::Controller::Helper::GetModels->new(
132
    ...
133
    filtered => {
134
      filter      => HASHREF,
135
      launder_to  => HASHREF | SUBNAME | '__INPLACE__',
136
    }
140 137

  
141
  sub action_list {
142
    my ($self) = @_;
138
    OR
143 139

  
144
    my $filtered_models = $self->get_models(%addition_filters);
145
    $self->render('controller/list', ENTRIES => $filtered_models);
146
  }
140
    filtered => 0,
141
  );
147 142

  
148 143

  
149 144
=head1 OVERVIEW
150 145

  
151
This helper module enables use of the L<SL::Controller::Helper::ParseFilter>
152
methods in conjunction with the L<SL::Controller::Helper::GetModels> style of
153
plugins. Additional filters can be defined in the database models and filtering
154
can be reduced to a minimum of work.
155

  
156
This plugin can be combined with L<SL::Controller::Sorted> and
157
L<SL::Controller::Paginated> for filtered, sorted and paginated lists.
158

  
159
The controller has to provive information where to look for filter information
160
at compile time. This call is L<make_filtered>.
146
This C<GetModels> plugin enables use of the
147
L<SL::Controller::Helper::ParseFilter> methods. Additional filters can be
148
defined in the database models and filtering can be reduced to a minimum of
149
work.
161 150

  
162 151
The underlying functionality that enables the use of more than just
163 152
the paginate helper is provided by the controller helper
164
C<GetModels>. See the documentation for L<SL::Controller::Sorted> for
153
C<GetModels>. See the documentation for L<SL::Controller::Helper::GetModels> for
165 154
more information on it.
166 155

  
167
=head1 PACKAGE FUNCTIONS
168

  
169
=over 4
170

  
171
=item C<make_filtered %filter_spec>
172

  
173
This function must be called by a controller at compile time. It is
174
uesd to set the various parameters required for this helper to do its
175
magic.
176

  
177
Careful: If you want to use this in conjunction with
178
L<SL:Controller::Helper::Paginated>, you need to call C<make_filtered> first,
179
or the paginating will not get all the relevant information to estimate the
180
number of pages correctly. To ensure this does not happen, this module will
181
croak when it detects such a scenario.
182

  
183
The hash C<%filter_spec> can include the following parameters:
156
=head1 OPTIONS
184 157

  
185 158
=over 4
186 159

  
187
=item * C<MODEL>
188

  
189
Optional. A string: the name of the Rose database model that is used
190
as a default in certain cases. If this parameter is missing then it is
191
derived from the controller's package (e.g. for the controller
192
C<SL::Controller::BackgroundJobHistory> the C<MODEL> would default to
193
C<BackgroundJobHistory>).
194

  
195
=item * C<FORM_PARAMS>
160
=item * C<filter>
196 161

  
197
Optional. Indicates a key in C<$::form> to be used as filter.
162
Optional. Indicates a key in C<source> to be used as filter.
198 163

  
199
Defaults to the values C<filter> if missing.
164
Defaults to the value C<filter> if missing.
200 165

  
201
=item * C<LAUNDER_TO>
166
=item * C<launder_to>
202 167

  
203
Option. Indicates a target for laundered filter arguments in the controller.
168
Optional. Indicates a target for laundered filter arguments in the controller.
204 169
Can be set to C<undef> to disable laundering, and can be set to method named or
205 170
hash keys of the controller. In the latter case the laundered structure will be
206 171
put there.
207 172

  
208
Defaults to inplace laundering which is not normally settable.
173
Defaults to the controller. Laundered values will end up in C<SELF.filter> for
174
template purposes.
209 175

  
210
=item * C<ONLY>
211

  
212
Optional. An array reference containing a list of action names for
213
which the paginate parameters should be saved. If missing or empty then
214
all actions invoked on the controller are monitored.
215

  
216
=back
176
Setting this to the special value C<__INPLACE__> will cause inplace laundering.
217 177

  
218 178
=back
219 179

  
220
=head1 INSTANCE FUNCTIONS
180
=head1 FILTER FORMAT
221 181

  
222
These functions are called on a controller instance.
182
See L<SL::Controller::Helper::ParseFilter> for a description of the filter format.
223 183

  
224
=over 4
184
=head1 CUSTOM FILTERS
225 185

  
226
=item C<get_current_filter_params>
186
C<Filtered> will honor custom filters defined in RDBO managers. See
187
L<SL::DB::Helper::Filtered> for an explanation fo those.
227 188

  
228
Returns a hash to be used in manager C<get_all> calls or to be passed on to
229
GetModels. Will only work if the get_models chain has been called at least
230
once, because only then the full parameters can get parsed and stored. Will
231
croak otherwise.
189
=head1 BUGS
232 190

  
233
=item C<disable_filtering>
191
=over 4
234 192

  
235
Disable filtering for the duration of the current action. Can be used
236
when using the attribute C<ONLY> to L<make_filtered> does not
237
cover all cases.
193
=item * There is currently no easy way to filter for CVars.
238 194

  
239 195
=back
240 196

  
241
=head1 BUGS
242

  
243
Nothing here yet.
244

  
245 197
=head1 AUTHOR
246 198

  
247 199
Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>

Auch abrufbar als: Unified diff