From 6ce44660fa589abea3838ef35c92f28715b241c0 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 Signed-off-by: Lari Taskula Signed-off-by: Kyle M Hall --- 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..55a9bf6 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.10.2