Skip to content

Commit

Permalink
Merge pull request #45 from nilportugues/2.1.0
Browse files Browse the repository at this point in the history
2.1.0
  • Loading branch information
nilportugues committed Dec 16, 2015
2 parents 1855942 + 1255c40 commit 298233b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
8 changes: 8 additions & 0 deletions src/Http/Request/Parameters/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public function __construct($number, $cursor, $limit, $offset, $size)
$this->size = $size;
}

/**
* @param $size
*/
public function setSize($size)
{
$this->size = (int) $size;
}

/**
* @return int|string
*/
Expand Down
36 changes: 22 additions & 14 deletions src/Server/Actions/ListResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function get(callable $totalAmountCallable, callable $resultsCallable, $r
);
$totalAmount = $totalAmountCallable();

if ($totalAmount > 0 && $this->page->size()>0 && $this->page->number() > ceil($totalAmount / $this->page->size())) {
if ($totalAmount > 0 && $this->page->size() > 0 && $this->page->number() > ceil($totalAmount / $this->page->size())) {
return $this->resourceNotFound(
new ErrorBag([new OufOfBoundsError($this->page->number(), $this->page->size())])
);
Expand Down Expand Up @@ -169,7 +169,7 @@ protected function pagePaginationLinks(
) {
$next = $pageNumber + 1;
$previous = $pageNumber - 1;
$last = ($pageSize == 0) ? 0: ceil($totalPages / $pageSize);
$last = ($pageSize == 0) ? 0 : ceil($totalPages / $pageSize);

$links = array_filter(
[
Expand Down Expand Up @@ -218,20 +218,28 @@ protected function pagePaginatedRoute(
Included $included,
$filters
) {
$fieldKeys = [];
if (false === $fields->isEmpty()) {
$fieldKeys = $fields->get();
foreach ($fieldKeys as &$v) {
$v = implode(',', $v);
}
}

$queryParams = urldecode(
http_build_query(
[
'page' => array_filter(
[
'number' => $pageNumber,
'size' => $pageSize,
]
),
'fields' => $fields->get(),
'filter' => $filters,
'sort' => $sorting->get(),
'include' => $included->get(),
]
array_filter([
'page' => array_filter(
[
'number' => $pageNumber,
'size' => $pageSize,
]
),
'fields' => $fieldKeys,
'filter' => $filters,
'sort' => $sorting->get(),
'include' => $included->get(),
])
)
);

Expand Down

0 comments on commit 298233b

Please sign in to comment.