Skip to content

Commit

Permalink
Pagination/AbstractStrategy shouldGetPage($current_page)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecoologic committed Nov 17, 2023
1 parent b978d74 commit ef32bb4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ protected function pageSize()
}

abstract public function page($getPageFn);
abstract public function shouldGetPage($position);
abstract public function shouldGetPage($current_page);
}
2 changes: 1 addition & 1 deletion src/Zendesk/API/Traits/Utility/Pagination/CbpStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function page($getPageFn)
return $this->latestResponse->{$this->resourcesKey};
}

public function shouldGetPage($position) {
public function shouldGetPage($current_page) {
return !$this->started || $this->hasMore;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Zendesk/API/Traits/Utility/Pagination/ObpStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function page($getPageFn)
return $response->{$this->resourcesKey};
}

public function shouldGetPage($position) {
return $this->pageNumber == 0 || $position >= $this->pageNumber * $this->pageSize();
public function shouldGetPage($current_page) {
return $this->pageNumber == 0 || count($current_page) == 0;
}
}
10 changes: 5 additions & 5 deletions src/Zendesk/API/Traits/Utility/Pagination/PaginationIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PaginationIterator implements Iterator
private $strategy;
private $method;
private $position = 0;
private $items = [];
private $page = [];

/**
* @param mixed using trait FindAll. The resources collection, Eg: `$client->tickets()` which uses FindAll
Expand Down Expand Up @@ -56,8 +56,8 @@ public function valid()
#[\ReturnTypeWillChange]
public function current()
{
if (isset($this->items[$this->position])) {
return $this->items[$this->position];
if (isset($this->page[$this->position])) {
return $this->page[$this->position];
} else {
return null;
}
Expand All @@ -74,14 +74,14 @@ public function latestResponse()
}
private function getPageIfNeeded()
{
if (isset($this->items[$this->position]) || !$this->strategy->shouldGetPage($this->position)) {
if (isset($this->page[$this->position]) || !$this->strategy->shouldGetPage($this->page)) {
return;
}

$getPageFn = function () {
return $this->clientList->{$this->method}($this->strategy->params());
};
$this->items = $this->strategy->page($getPageFn);
$this->page = $this->strategy->page($getPageFn);
$this->position = 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function page($getPageFn)
return $response->{$this->resourcesKey};
}

public function shouldGetPage($position) {
public function shouldGetPage($current_page) {
return !$this->started;
}
}

0 comments on commit ef32bb4

Please sign in to comment.