Skip to content

Commit

Permalink
[VUFIND-1698] FOLIO: use allowed-service-points API.
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Oct 10, 2024
1 parent affa94b commit af34571
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion module/VuFind/src/VuFind/ILS/Driver/Folio.php
Original file line number Diff line number Diff line change
Expand Up @@ -1745,6 +1745,38 @@ protected function performHoldRequest(array $requestBody): array
];
}

/**
* Get allowed service points for a request.
*
* @param string $instanceId Instance UUID being requested
* @param string $requesterId Patron UUID placing request
* @param string $operation Operation type (default = create)
*
* @return array
*/
public function getAllowedServicePoints(
string $instanceId,
string $requesterId,
string $operation = 'create'
): array {
try {
// circulation.requests.allowed-service-points.get
$response = $this->makeRequest(
'GET',
'/circulation/requests/allowed-service-points?'
. http_build_query(compact('instanceId', 'requesterId', 'operation'))
);
if (!$response->isSuccess()) {
$this->warning('Unexpected service point lookup response: ' . $response->getBody());
return [];
}
} catch (\Exception $e) {
$this->warning('Exception during allowed service point lookup: ' . (string)$e);
return [];
}
return json_decode($response->getBody(), true);
}

/**
* Place Hold
*
Expand All @@ -1768,9 +1800,9 @@ public function placeHold($holdDetails)
$requiredBy = !empty($holdDetails['requiredByTS'])
? gmdate('Y-m-d', $holdDetails['requiredByTS']) : null;

$instance = $this->getInstanceByBibId($holdDetails['id']);
$isTitleLevel = ($holdDetails['level'] ?? '') === 'title';
if ($isTitleLevel) {
$instance = $this->getInstanceByBibId($holdDetails['id']);
$baseParams = [
'instanceId' => $instance->id,
'requestLevel' => 'Title',
Expand Down Expand Up @@ -1803,7 +1835,19 @@ public function placeHold($holdDetails)
if (!empty($holdDetails['comment'])) {
$requestBody['patronComments'] = $holdDetails['comment'];
}
$allowed = $this->getAllowedServicePoints($instance->id, $holdDetails['patron']['id']);
foreach ($this->getRequestTypeList($preferredRequestType) as $requestType) {
// Skip illegal request types, if we have validation data available:
if (!empty($allowed)) {
if (
// Unsupported request type:
!isset($allowed[$requestType])
// Unsupported pickup location:
|| !in_array($holdDetails['pickUpLocation'], array_column($allowed[$requestType] ?? [], 'id'))
) {
continue;
}
}
$requestBody['requestType'] = $requestType;
$result = $this->performHoldRequest($requestBody);
if ($result['success']) {
Expand Down

0 comments on commit af34571

Please sign in to comment.