Skip to content

Commit

Permalink
add links to response
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizer committed Aug 25, 2017
1 parent 15f7e67 commit 0641d40
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/union/UnionPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,24 @@ private function getData()
}

public function linksJson() {
$parameters = $this->parameters;
$pagination = [];
$page = $this->currentPage;
$pages = $this->count;
$pages = intval($this->total / $this->perPage);
$pages_float = $this->total / $this->perPage;
if ($pages_float > $pages) {
$pages = $pages + 1;
}
dump($pages, $this->total, $this->perPage);
if ($page > 3) {
$parameters[ $this->pageName ] = 1;
$url = $this->url . '?' . http_build_query($parameters, '', '&');
$pagination [] = ["text" => 1, "url" => $url, "current" => false, "disabled" => false, "page" => 1];
$pagination [] = ["text" => "...", "url" => "", "current" => false, "disabled" => true, "page" => 0];
}
// dump($page - 2, $page + 5, $pages);
for ($i = ($page - 2); $i < ($page + 5); $i++) {
if ($i > 0 AND $i < $pages+1) {
if ($i > 0 AND $i < $pages) {
if ($i == ($page)) {
$pagination [] = ["text" => $i, "url" => "", "current" => true, "disabled" => false, "page" => $page];
} else {
Expand All @@ -139,8 +146,11 @@ public function linksJson() {

public function links()
{
$pagesCount = ceil($this->total / $this->perPage);

$pagesCount = intval($this->total / $this->perPage);
$pages_float = $this->total / $this->perPage;
if ($pages_float > $pagesCount) {
$pagesCount = $pagesCount + 1;
}
if ($pagesCount == 1 || $pagesCount == 0) {
return '';
}
Expand Down Expand Up @@ -207,16 +217,21 @@ public function getPaginate() {
$data = $this->getData();
$this->hasMore = $this->total > $this->perPage;
$this->count = count($data);
$pagesCount = intval($this->total/$this->perPage);
$pages_float = $this->total / $this->perPage;
if ($pages_float > $pagesCount) {
$pagesCount = $pagesCount + 1;
}
$response = [
"current_page" => $this->currentPage,
"data" => $data,
"from" => ($this->perPage * $this->currentPage) + 1,
"last_page" => $this->total/$this->perPage,
"from" => ($this->perPage * ($this->currentPage - 1)) + 1,
"last_page" => $pagesCount,
"next_page_url" => $this->getNextUrl(),
"path" => $this->url,
"per_page" => $this->perPage,
"prev_page_url" => $this->getPrevUrl(),
"to" => ($this->perPage * $this->currentPage) + $this->count,
"to" => ($this->perPage * ($this->currentPage-1)) + $this->count,
"total" => $this->total,
];
return $response;
Expand Down

0 comments on commit 0641d40

Please sign in to comment.