Skip to content

Commit

Permalink
Merge pull request #33 from luyadev/all-pages-per-page-param
Browse files Browse the repository at this point in the history
add all pages per page
  • Loading branch information
nadar authored Dec 29, 2020
2 parents cb6c125 + 0faf323 commit 158cc7e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](http://semver.org/).

## 2.8.0
## 2.8.0 (29. December 2020)

+ [#33](https://github.com/luyadev/luya-headless/pull/33) Option to provide the `per-page` value when retrieving all pages with method `allPages(Client $client, $perPage = 50)`.
+ [#32](https://github.com/luyadev/luya-headless/pull/32) Prepared unit tests for PHP 8.0 and 7.0

## 2.7.0 (1. September 2020)
Expand Down
8 changes: 5 additions & 3 deletions src/endpoint/ActiveEndpointRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,21 @@ public function all(Client $client)
* Iteratrs trough all pages and returns an arry with the models.
*
* @param Client $client
* @param integer $perPage The amount of items which can be loaded per requests, this is commonly limited on the api side. If you are
* aware of the max limit this value can be increased.
* @return static
*/
public function allPages(Client $client)
public function allPages(Client $client, $perPage = 50)
{
$data = [];
$first = $this->setPerPage(50)->all($client);
$first = $this->setPerPage($perPage)->all($client);
foreach ($first->getModels() as $key => $model) {
$data[$key] = $model;
}

$start = $first->getCurrentPage() + 1;
for ($i=$start; $i<=$first->getPageCount(); $i++) {
$find = $this->setPage($i)->setPerPage(50)->all($client);
$find = $this->setPage($i)->setPerPage($perPage)->all($client);
foreach ($find->getModels() as $key => $model) {
$data[$key] = $model;
}
Expand Down

0 comments on commit 158cc7e

Please sign in to comment.