Skip to content

Commit

Permalink
Updated the Folio driver to get the correct number of items rather th…
Browse files Browse the repository at this point in the history
…an an estimate.
  • Loading branch information
bbusenius committed Jan 16, 2025
1 parent 1de91b6 commit 379e81f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions module/UChicago/src/UChicago/ILS/Driver/Folio.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@

class Folio extends \VuFind\ILS\Driver\Folio
{
/**
* Get a total count of records from a FOLIO endpoint.
*
* @param string $interface FOLIO api interface to call
* @param array $query Extra GET parameters (e.g. ['query' => 'your cql here'])
*
* @return int
*/
protected function getResultCount(string $interface, array $query = []): int
{
$combinedQuery = array_merge($query, ['limit' => 0]);
$response = $this->makeRequest(
'GET',
$interface,
$combinedQuery
);
$json = json_decode($response->getBody());
return $json->totalRecords ?? 0;
}

/**
* Helper function to retrieve paged results from FOLIO API
*
Expand Down Expand Up @@ -38,6 +58,10 @@ protected function getPagedResults($responseKey, $interface, $query = [], $holdi
throw new ILSException("Error: '$msg' fetching '$responseKey'");
}
$total = $json->totalRecords ?? 0;
if ($responseKey == 'items' && $total >= 1000) {
$realTotal = $this->getResultCount($interface, $query);
$total = $realTotal;
}
if (isset($holdings) && $total === 0 && ($holdings->holdingsTypeId != $eHoldingTypeId
|| $holdings->effectiveLocationId == $onOrderLocId)) {
yield $holdings;
Expand Down

0 comments on commit 379e81f

Please sign in to comment.