From a99a31d6e4bb41691a28ddb1ce9f20e5219ec4e1 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 4 Sep 2012 15:26:20 +0200 Subject: [PATCH] =?utf8?q?Paginate-Controller-Helper:=20Parameter=C3=BCber?= =?utf8?q?gabe=20f=C3=BCr=20Berechnung=20Objektanzahl=20erm=C3=B6glichen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/Helper/Paginated.pm | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/SL/Controller/Helper/Paginated.pm b/SL/Controller/Helper/Paginated.pm index 0e2560d76..5792f6336 100644 --- a/SL/Controller/Helper/Paginated.pm +++ b/SL/Controller/Helper/Paginated.pm @@ -54,7 +54,10 @@ sub get_current_paginate_params { per_page => ($params{per_page} * 1) || $spec->{PER_PAGE}, ); - my $calculated_params = "SL::DB::Manager::$spec->{MODEL}"->paginate(%paginate_params, args => {}); + my $paginate_args = ref($spec->{PAGINATE_ARGS}) eq 'CODE' ? $spec->{PAGINATE_ARGS}->($self) + : $spec->{PAGINATE_ARGS} ? do { my $sub = $spec->{PAGINATE_ARGS}; $self->$sub() } + : {}; + my $calculated_params = "SL::DB::Manager::$spec->{MODEL}"->paginate(%paginate_params, args => $paginate_args); %paginate_params = ( %paginate_params, num_pages => $calculated_params->{max}, @@ -211,6 +214,19 @@ derived from the controller's package (e.g. for the controller C the C would default to C). +=item * C + +Optional. Either a code reference or the name of function to be called +on the controller importing this helper. + +If this funciton is given then the paginate helper calls it whenever +it has to count the total number of models for calculating the number +of pages to display. The function must return a hash reference with +elements suitable for passing to a Rose model manager's C +function. + +This can be used e.g. when filtering is used. + =item * C Optional. An integer: the number of models to return per page. -- 2.20.1