From 538536da73681719a1c2d7349a6d729bad7f39f4 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 Signed-off-by: Jonathan Druart --- 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 5f5b7eb50a..55a9bf6c31 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.39.5