diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetUserTransactions.php b/module/VuFind/src/VuFind/AjaxHandler/GetUserTransactions.php index 27e8eabe1a29685f5ac776d8395d5ea5714ad482..453f358afbf9aa6d263214dd649760cb872e6a24 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetUserTransactions.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetUserTransactions.php @@ -40,6 +40,13 @@ use Laminas\Mvc\Controller\Plugin\Params; */ class GetUserTransactions extends AbstractIlsAndUserAction { + /** + * Paginator + * + * @var \VuFind\ILS\PaginationHelper + */ + protected $paginator = null; + /** * Handle a request. * @@ -57,25 +64,64 @@ class GetUserTransactions extends AbstractIlsAndUserAction if (!$this->ils->checkCapability('getMyTransactions')) { return $this->formatResponse('', self::STATUS_HTTP_ERROR, 405); } - $items = $this->ils->getMyTransactions($patron); + $counts = [ 'ok' => 0, 'warn' => 0, 'overdue' => 0 ]; - foreach ($items['records'] as $item) { - switch ($item['dueStatus'] ?? '') { - case 'due': - $counts['warn']++; - break; - case 'overdue': - $counts['overdue']++; - break; - default: - $counts['ok']++; - break; + $functionConfig = $this->ils->checkFunction('getMyTransactions', $patron); + $page = 1; + do { + // Try to use large page size, but take ILS limits into account + $pageOptions = $this->getPaginationHelper() + ->getOptions($page, null, 1000, $functionConfig); + $result = $this->ils + ->getMyTransactions($patron, $pageOptions['ilsParams']); + foreach ($result['records'] as $item) { + switch ($item['dueStatus'] ?? '') { + case 'due': + $counts['warn']++; + break; + case 'overdue': + $counts['overdue']++; + break; + default: + $counts['ok']++; + break; + } } - } + $pageEnd = $pageOptions['ilsPaging'] + ? ceil($result['count'] / $pageOptions['limit']) + : 1; + $page++; + } while ($page <= $pageEnd); + return $this->formatResponse($counts); } + + /** + * Set the ILS pagination helper + * + * @param \VuFind\ILS\PaginationHelper $helper Pagination helper + * + * @return void + */ + protected function setPaginationHelper($helper) + { + $this->paginationHelper = $helper; + } + + /** + * Get the ILS pagination helper + * + * @return \VuFind\ILS\PaginationHelper + */ + protected function getPaginationHelper() + { + if (null === $this->paginationHelper) { + $this->paginationHelper = new \VuFind\ILS\PaginationHelper(); + } + return $this->paginationHelper; + } }