Skip to content

Commit

Permalink
reset the internal array to avoid miestorious positional bug
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeZ99 committed Apr 13, 2016
1 parent 4e39c4c commit 2b5e236
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/doofinder_management_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,16 @@ public function getScrolledItemsPage($dType, $scrollId = null) {
* It only paginates forward. Can't go backwards
* @param string $dType Type of the items to list
* @param string $scrollId identifier of the pagination set
* @return array Assoc array with scroll_id and paginated results
* @return array Assoc array with scroll_id ,paginated results and total results.
*/

$params = $scrollId ? array("scroll_id"=>$scrollId) : null;

$result = $this->dma->managementApiCall(
'GET', $this->hashid.'/items/'.$dType,
$params
);

return array(
'scroll_id' => $result['response']['scroll_id'],
'results' => $result['response']['results'],
Expand Down Expand Up @@ -375,19 +377,19 @@ function __construct($searchEngine, $dType){
}

private function fetchResults(){
$apiResults = $this->searchEngine->getScrolledItemsPage($this->dType);
$apiResults = $this->searchEngine->getScrolledItemsPage($this->dType, $this->scrollId);
$this->total = $apiResults['total'];
$this->resultsPage = $apiResults['results'];
$this->scrollId = $apiResults['scroll_id'];
$this->currentItem = each($this->resultsPage);
}

function rewind() {
$this->scrollId = null;
$this->fetchResults();
}

function valid(){
print "\nValid? ".$this->position.", ".$this->total;
return $this->position < $this->total;
}

Expand All @@ -404,6 +406,7 @@ function next(){
$this->currentItem = each($this->resultsPage);
if(!$this->currentItem and $this->position < $this->total){
$this->fetchResults();
reset($this->resultsPage);
$this->currentItem = each($this->resultsPage);
}
}
Expand Down

0 comments on commit 2b5e236

Please sign in to comment.