From 5ac12a49a3e8eca98155de78c2408aa93ce2b5dc Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 26 Sep 2017 15:12:19 -0300 Subject: [PATCH] Bug 19369: Add helper function for pagination attributes generation This patch introduces a new helper function to the Koha::REST::Plugin::Pagination plugin, called 'dbic_merge_pagination'. This simple function adds SQL::Abstract pagination attributes ('page' and 'rows') to the passed $filter hashref. To test: - Apply this patches - Run: $ koha-shell kohadev k$ cd kohaclone k$ prove t/Koha/REST/Plugin/Pagination.t => SUCCESS: Tests pass! - Sign off :-D Sponsored-by: Camden County --- Koha/REST/Plugin/Pagination.pm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Koha/REST/Plugin/Pagination.pm b/Koha/REST/Plugin/Pagination.pm index 5f5b7eb..c7e3e30 100644 --- a/Koha/REST/Plugin/Pagination.pm +++ b/Koha/REST/Plugin/Pagination.pm @@ -107,6 +107,32 @@ It also adds X-Total-Count, containing the total results count. return $c; } ); + +=head3 dbic_merge_pagination + + $filter = $c->dbic_merge_pagination({ + filter => $filter, + params => { + page => $params->{_page}, + per_page => $params->{_per_page} + } + }); + +Adds I and I elements to the filter parameter. + +=cut + + $app->helper( + 'dbic_merge_pagination' => sub { + my ( $c, $args ) = @_; + my $filter = $args->{filter}; + + $filter->{page} = $args->{params}->{_page}; + $filter->{rows} = $args->{params}->{_per_page}; + + return $filter; + } + ); } =head2 Internal methods -- 2.7.4