Skip to content

Commit

Permalink
refactor: make more readdable
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <[email protected]>
  • Loading branch information
vitormattos committed Oct 31, 2024
1 parent 0a0e74e commit 12123ea
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions lib/Helper/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,33 @@ public function setRouteName(string $routeName = ''): self {

public function getPagination(?int $page, ?int $length, array $filter = []): array {
$this->setMaxPerPage($length);
$pagination['total'] = $this->count();
if ($pagination['total'] > $length) {
$pagination['current'] = $this->linkToRoute($page, $length, $filter);
$pagination['next'] = $this->hasNextPage()
? $this->linkToRoute($this->getNextPage(), $length, $filter)
: null;
$pagination['prev'] = $this->hasPreviousPage()
? $this->linkToRoute($this->getPreviousPage(), $length, $filter)
: null;
$pagination['last'] = $this->hasNextPage()
? $this->linkToRoute($this->getNbPages(), $length, $filter)
: null;
$pagination['first'] = $this->hasPreviousPage()
? $this->linkToRoute(1, $length, $filter)
: null;
} else {
$pagination['current'] = null;
$pagination['next'] = null;
$pagination['prev'] = null;
$pagination['last'] = null;
$pagination['first'] = null;
$total = $this->count();
if ($total > $length) {
return [
'total' => $total,
'current' => $this->linkToRoute($page, $length, $filter),
'next' => $this->hasNextPage()
? $this->linkToRoute($this->getNextPage(), $length, $filter)
: null,
'prev' => $this->hasPreviousPage()
? $this->linkToRoute($this->getPreviousPage(), $length, $filter)
: null,
'last' => $this->hasNextPage()
? $this->linkToRoute($this->getNbPages(), $length, $filter)
: null,
'first' => $this->hasPreviousPage()
? $this->linkToRoute(1, $length, $filter)
: null,
];
}
return $pagination;
return [
'total' => $total,
'current' => null,
'next' => null,
'prev' => null,
'last' => null,
'first' => null,
];
}

private function linkToRoute(int $page, int $length, array $filter): string {
Expand Down

0 comments on commit 12123ea

Please sign in to comment.