Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pagination for FindAll method #427

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/DataService/DataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -802,13 +802,13 @@ public function Add($entity)
$this->verifyOperationAccess($entity, __FUNCTION__);
if ($this->isJsonOnly($entity)) {
$this->forceJsonSerializers();
}
}

$httpsPostBody = $this->executeObjectSerializer($entity, $urlResource);
// Builds resource Uri
$resourceURI = implode(CoreConstants::SLASH_CHAR, array('company', $this->serviceContext->realmId, $urlResource));

$uri = $this->handleTaxService($entity, $resourceURI);
$uri = $this->handleTaxService($entity, $resourceURI);
// Send request
return $this->sendRequestParseResponseBodyAndHandleHttpError($entity, $uri, $httpsPostBody, DataService::ADD);
}
Expand Down Expand Up @@ -948,7 +948,7 @@ public function DownloadPDF($entity, $dir=null, $returnPdfString = false)
return $responseBody;
} else {
$this->lastError = false;

return $this->processDownloadedContent(new ContentWriter($responseBody), $responseCode, $dir, $this->getExportFileNameForPDF($entity, "pdf"));
}
}
Expand Down Expand Up @@ -1008,7 +1008,7 @@ public function Query($query, $startPosition = null, $maxResults = null, $includ

$httpsUri = implode(CoreConstants::SLASH_CHAR, array('company', $this->serviceContext->realmId, 'query'));
$httpsPostBody = $this->appendPaginationInfo($query, $startPosition, $maxResults);

if(!is_null($includes)) {
$httpsUri .= "?include=$includes";
}
Expand Down Expand Up @@ -1079,7 +1079,7 @@ private function appendPaginationInfo($query, $startPosition, $maxResults){
* @param int $pageSize
* @return array Returns an array of entities of specified type.
*/
public function FindAll($entityName, $pageNumber = 0, $pageSize = 500)
public function FindAll($entityName, $pageNumber = 1, $pageSize = 500)
{
$this->serviceContext->IppConfiguration->Logger->RequestLog->Log(TraceLevel::Info, "Called Method FindAll.");

Expand All @@ -1097,7 +1097,10 @@ public function FindAll($entityName, $pageNumber = 0, $pageSize = 500)
}

$httpsUri = implode(CoreConstants::SLASH_CHAR, array('company', $this->serviceContext->realmId, 'query'));
$httpsPostBody = "select * from $entityName startPosition $pageNumber maxResults $pageSize";

$startPosition = (($pageNumber - 1) * $pageSize) + 1;

$httpsPostBody = "select * from $entityName startPosition $startPosition maxResults $pageSize";

$requestParameters = $this->getPostRequestParameters($httpsUri, $httpsContentType);
$restRequestHandler = $this->getRestHandler();
Expand Down