diff --git a/src/Zendesk/API/Resources/Core/AppInstallations.php b/src/Zendesk/API/Resources/Core/AppInstallations.php index b774b87a..004deff6 100644 --- a/src/Zendesk/API/Resources/Core/AppInstallations.php +++ b/src/Zendesk/API/Resources/Core/AppInstallations.php @@ -8,6 +8,7 @@ use Zendesk\API\Traits\Resource\Find; use Zendesk\API\Traits\Resource\FindAll; use Zendesk\API\Traits\Resource\Update; +use Zendesk\API\Traits\Utility\Pagination\ObpStrategy; /** * The AppInstallations class exposes methods seen at @@ -123,4 +124,8 @@ public function update($id = null, array $updateResourceFields = [], $routeKey = $updateResourceFields ); } + + private function paginationStrategyClass() { + return ObpStrategy::class; + } } diff --git a/src/Zendesk/API/Resources/Core/Tickets.php b/src/Zendesk/API/Resources/Core/Tickets.php index 5388a167..e109ebed 100755 --- a/src/Zendesk/API/Resources/Core/Tickets.php +++ b/src/Zendesk/API/Resources/Core/Tickets.php @@ -457,8 +457,4 @@ public function merge(array $params = []) return $response; } - - protected function paginatedPath() { - return 'tickets'; - } } diff --git a/src/Zendesk/API/Resources/Core/Users.php b/src/Zendesk/API/Resources/Core/Users.php index 58ad367c..1840f300 100755 --- a/src/Zendesk/API/Resources/Core/Users.php +++ b/src/Zendesk/API/Resources/Core/Users.php @@ -50,20 +50,6 @@ class Users extends ResourceAbstract */ protected $identities; - /** - * Usage: - * foreach ($usersIterator as $user) { - * process($user) - * } - * - * @return PaginationIterator to fetch all pages. - */ - public function iterator() - { - $strategy = new CbpStrategy($this, 'users', 2); - return new PaginationIterator($strategy); - } - /** * {@inheritdoc} */ diff --git a/src/Zendesk/API/Traits/Resource/FindAll.php b/src/Zendesk/API/Traits/Resource/FindAll.php index e1b0b18f..15564c66 100644 --- a/src/Zendesk/API/Traits/Resource/FindAll.php +++ b/src/Zendesk/API/Traits/Resource/FindAll.php @@ -38,7 +38,8 @@ public function findAll(array $params = [], $routeKey = __FUNCTION__) ); } - // TODO: own trait? + // TODO: own trait + // TODO: page size 100 /** * Usage: * foreach ($ticketsIterator as $ticket) { @@ -50,7 +51,7 @@ public function findAll(array $params = [], $routeKey = __FUNCTION__) public function iterator() { $strategyClass = $this->paginationStrategyClass(); - $strategy = new $strategyClass($this, $this->paginatedPath(), 2); + $strategy = new $strategyClass($this, $this->resourcesRoot(), 2); return new PaginationIterator($strategy); } @@ -59,8 +60,7 @@ private function paginationStrategyClass() { return CbpStrategy::class; } - // TODO: abstract - protected function paginatedPath() { - return "/"; + protected function resourcesRoot() { + return $this->objectNamePlural; } } diff --git a/src/Zendesk/API/Traits/Utility/Pagination/ObpStrategy.php b/src/Zendesk/API/Traits/Utility/Pagination/ObpStrategy.php index fd703c89..cd15990a 100644 --- a/src/Zendesk/API/Traits/Utility/Pagination/ObpStrategy.php +++ b/src/Zendesk/API/Traits/Utility/Pagination/ObpStrategy.php @@ -2,6 +2,11 @@ namespace Zendesk\API\Traits\Utility\Pagination; + +/** + * Offset Based Pagination + * Can also be used for no pagination + */ class ObpStrategy extends PaginationStrategy { private $pageNumber = 0; @@ -11,6 +16,7 @@ public function getPage() ++$this->pageNumber; $params = ['page' => $this->pageNumber, 'page_size' => $this->pageSize]; $response = $this->resourcesRoot->findAll($params); + return $response->{$this->resourcesKey}; } diff --git a/src/Zendesk/API/Traits/Utility/Pagination/PaginationIterator.php b/src/Zendesk/API/Traits/Utility/Pagination/PaginationIterator.php index bc553aeb..c44681ca 100644 --- a/src/Zendesk/API/Traits/Utility/Pagination/PaginationIterator.php +++ b/src/Zendesk/API/Traits/Utility/Pagination/PaginationIterator.php @@ -48,6 +48,7 @@ private function getPageIfNecessary() return; } + // TODO: don't keep all pages $this->page = array_merge($this->page, $this->strategy->getPage()); }