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

FOLIO: Limit request pickupLocation options by item location #3876

Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions config/vufind/Folio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ defaultRequiredDate = 0:1:0
; "pickUpLocation", "proxiedUsers" and "requestGroup"
extraHoldFields = requiredByDate:pickUpLocation

; When the extra hold field pickUpLocation is used, this can be used to limit the
; pickup location (service point) options to those whose assigned locations include the
; requested item's effective location. Only applicable to item-level requests.
;limitPickupLocations = itemEffectiveLocation

; By default, a "Hold" type request is placed when an item is unavailable and a Page
; when an item is available. This setting overrides the default behavior for
; unavailable items and for all title-level requests. Legal values: "Page", "Hold" or
Expand Down
52 changes: 42 additions & 10 deletions module/VuFind/src/VuFind/ILS/Driver/Folio.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,7 @@ protected function getInstanceById(
if ($itemId == null) {
throw new \Exception('No IDs provided to getInstanceObject.');
}
$response = $this->makeRequest(
'GET',
'/item-storage/items/' . $itemId
);
$item = json_decode($response->getBody());
$item = $this->getItemById($itemId);
$holdingId = $item->holdingsRecordId;
}
$response = $this->makeRequest(
Expand All @@ -374,6 +370,23 @@ protected function getInstanceById(
return json_decode($response->getBody());
}

/**
* Get an item record by its UUID.
*
* @param string $itemId UUID
*
* @return \stdClass The item
*/
protected function getItemById($itemId)
{
$response = $this->makeRequest(
'GET',
'/item-storage/items/' . $itemId
);
$item = json_decode($response->getBody());
return $item;
}

/**
* Given an instance object or identifer, or a holding or item identifier,
* determine an appropriate value to use as VuFind's bibliographic ID.
Expand Down Expand Up @@ -552,7 +565,8 @@ protected function getLocations()
$name = $location->discoveryDisplayName ?? $location->name;
$code = $location->code;
$isActive = $location->isActive ?? true;
$locationMap[$location->id] = compact('name', 'code', 'isActive');
$servicePointIds = $location->servicePointIds;
$locationMap[$location->id] = compact('name', 'code', 'isActive', 'servicePointIds');
}
$this->putCachedData($cacheKey, $locationMap);
}
Expand All @@ -572,6 +586,7 @@ protected function getLocationData($locationId)
$name = '';
$code = '';
$isActive = true;
$servicePointIds = [];
if (array_key_exists($locationId, $locationMap)) {
return $locationMap[$locationId];
} else {
Expand All @@ -586,10 +601,11 @@ protected function getLocationData($locationId)
$name = $location->discoveryDisplayName ?? $location->name;
$code = $location->code;
$isActive = $location->isActive ?? $isActive;
$servicePointIds = $location->servicePointIds;
}
}

return compact('name', 'code', 'isActive');
return compact('name', 'code', 'isActive', 'servicePointIds');
}

/**
Expand Down Expand Up @@ -1394,18 +1410,34 @@ public function renewMyItems($renewDetails)
*/
public function getPickupLocations($patron, $holdInfo = null)
{
$limitedServicePoints = null;
if (
str_contains($this->config['Holds']['limitPickupLocations'] ?? '', 'itemEffectiveLocation')
// If there's no item ID, it must be a title-level hold,
// so limiting by itemEffectiveLocation does not apply
&& $holdInfo['item_id'] ?? false
demiankatz marked this conversation as resolved.
Show resolved Hide resolved
) {
$item = $this->getItemById($holdInfo['item_id']);
$itemLocationId = $item->effectiveLocationId;
$limitedServicePoints = $this->getLocationData($itemLocationId)['servicePointIds'];
}

$query = ['query' => 'pickupLocation=true'];
$locations = [];
foreach (
$this->getPagedResults(
'servicepoints',
'/service-points',
$query
) as $servicepoint
) as $servicePoint
) {
if ($limitedServicePoints && !in_array($servicePoint->id, $limitedServicePoints)) {
continue;
}

$locations[] = [
'locationID' => $servicepoint->id,
'locationDisplay' => $servicepoint->discoveryDisplayName,
'locationID' => $servicePoint->id,
'locationDisplay' => $servicePoint->discoveryDisplayName,
];
}
return $locations;
Expand Down
Loading