Merge pull request #5248 from solgenomics/topic/batch_update_trials
[sgn.git] / lib / CXGN / BrAPI / Pagination.pm
blob31082342a0825f2c1d2fec265b01f0a705563466
1 package CXGN::BrAPI::Pagination;
3 use Moose;
4 use Data::Dumper;
6 sub pagination_response {
7 my $self = shift;
8 my $data_count = shift;
9 my $page_size = shift;
10 my $page = shift;
12 $page_size += 0; # convert from string to int
13 $page += 0; # convert from string to int?
15 my $total_pages_decimal = $data_count/$page_size;
16 my $total_pages = ($total_pages_decimal == int $total_pages_decimal) ? $total_pages_decimal : int($total_pages_decimal + 1);
17 my %pagination = (pageSize=>$page_size, currentPage=>$page, totalCount=>$data_count, totalPages=>$total_pages);
18 return \%pagination;
21 sub paginate_array {
22 my $self = shift;
23 my $data = shift;
24 my $page_size = shift;
25 my $page = shift;
26 my $total_count = $data ? scalar(@$data) : 0;
27 my $start = $page_size*$page;
28 my $end = $page_size*($page+1)-1;
29 my @data_window;
30 for( my $i = $start; $i <= $end; $i++ ) {
31 if ($data->[$i]) {
32 push @data_window, $data->[$i];
35 my $pagination = $self->pagination_response($total_count, $page_size, $page);
36 return (\@data_window, $pagination);