Skip to content
Permalink
Browse files

Move start/end calculation into datasource.

  • Loading branch information...
dereuromark committed Jun 7, 2018
1 parent 7505bb8 commit 80e813a0704160cd5248c6c7499fb17b952dabfa
@@ -200,12 +200,23 @@ public function paginate($object, array $params = [], array $settings = [])
$directionDefault = current($defaults['order']);
}
$start = 0;
if ($count >= 1) {
$start = (($page - 1) * $limit) + 1;
}
$end = $start + $limit - 1;
if ($count < $end) {
$end = $count;
}
$paging = [
'finder' => $finder,
'page' => $page,
'current' => $numResults,
'count' => $count,
'perPage' => $limit,
'start' => $start,
'end' => $end,
'prevPage' => $page > 1,
'nextPage' => $count > ($page * $limit),
'pageCount' => $pageCount,
@@ -686,14 +686,6 @@ public function counter($options = [])
if (!$paging['pageCount']) {
$paging['pageCount'] = 1;
}
$start = 0;
if ($paging['count'] >= 1) {
$start = (($paging['page'] - 1) * $paging['perPage']) + 1;
}
$end = $start + $paging['perPage'] - 1;
if ($paging['count'] < $end) {
$end = $paging['count'];
}
switch ($options['format']) {
case 'range':
@@ -709,8 +701,8 @@ public function counter($options = [])
'pages' => $paging['pageCount'],
'current' => $paging['current'],
'count' => $paging['count'],
'start' => $start,
'end' => $end
'start' => $paging['start'],
'end' => $paging['end']
]);
$map += [
@@ -182,7 +182,10 @@ public function testPaginateCustomFinder()
$this->Paginator->paginate($table, [], $settings);
$pagingParams = $this->Paginator->getPagingParams();
$this->assertEquals('popular', $pagingParams['PaginatorPosts']['finder']);
$this->assertSame('popular', $pagingParams['PaginatorPosts']['finder']);
$this->assertSame(1, $pagingParams['PaginatorPosts']['start']);
$this->assertSame(2, $pagingParams['PaginatorPosts']['end']);
}
/**
@@ -2746,6 +2746,8 @@ public function testCounter()
'limit' => 3,
'sort' => 'Client.name',
'order' => 'DESC',
'start' => 1,
'end' => 3,
]
]);
$input = 'Page {{page}} of {{pages}}, showing {{current}} records out of {{count}} total, ';
@@ -2787,6 +2789,8 @@ public function testCounterBigNumbers()
'limit' => 5000,
'sort' => 'Client.name',
'order' => 'DESC',
'start' => 4566001,
'end' => 234567,
]
]);
@@ -2950,6 +2954,8 @@ public function testWithZeroPages()
'nextPage' => false,
'pageCount' => 0,
'limit' => 10,
'start' => 0,
'end' => 0,
]
]);

0 comments on commit 80e813a

Please sign in to comment.
You can’t perform that action at this time.