From 132fcdb71da5929accfea8be45500f5314cdc5b3 Mon Sep 17 00:00:00 2001 From: Maccabee Levine Date: Thu, 22 Aug 2024 18:30:54 +0000 Subject: [PATCH 1/8] FOLIO: Limit hold location options by item location --- config/vufind/Folio.ini | 5 ++++ module/VuFind/src/VuFind/ILS/Driver/Folio.php | 30 +++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/config/vufind/Folio.ini b/config/vufind/Folio.ini index 879a9b75446..e5c40fa9bf6 100644 --- a/config/vufind/Folio.ini +++ b/config/vufind/Folio.ini @@ -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. +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 diff --git a/module/VuFind/src/VuFind/ILS/Driver/Folio.php b/module/VuFind/src/VuFind/ILS/Driver/Folio.php index abec1a2def8..6ff45bc176d 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/Folio.php +++ b/module/VuFind/src/VuFind/ILS/Driver/Folio.php @@ -552,7 +552,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); } @@ -586,10 +587,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'); } /** @@ -1394,6 +1396,20 @@ public function renewMyItems($renewDetails) */ public function getPickupLocations($patron, $holdInfo = null) { + $limitedServicePoints = false; + if ( + str_contains($this->config['Holds']['limitPickupLocations'] ?? '', 'itemEffectiveLocation') + && $holdInfo['item_id'] ?? false + ) { + $response = $this->makeRequest( + 'GET', + '/item-storage/items/' . $holdInfo['item_id'] + ); + $item = json_decode($response->getBody()); + $itemLocationId = $item->effectiveLocationId; + $limitedServicePoints = $this->getLocationData($itemLocationId)['servicePointIds']; + } + $query = ['query' => 'pickupLocation=true']; $locations = []; foreach ( @@ -1401,11 +1417,15 @@ public function getPickupLocations($patron, $holdInfo = null) '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; From 34d0ed44c2f29013b027ca7ad7199c557112db1f Mon Sep 17 00:00:00 2001 From: Maccabee Levine Date: Thu, 22 Aug 2024 18:39:14 +0000 Subject: [PATCH 2/8] Fix phpstan --- module/VuFind/src/VuFind/ILS/Driver/Folio.php | 1 + 1 file changed, 1 insertion(+) diff --git a/module/VuFind/src/VuFind/ILS/Driver/Folio.php b/module/VuFind/src/VuFind/ILS/Driver/Folio.php index 6ff45bc176d..dc7355c067a 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/Folio.php +++ b/module/VuFind/src/VuFind/ILS/Driver/Folio.php @@ -573,6 +573,7 @@ protected function getLocationData($locationId) $name = ''; $code = ''; $isActive = true; + $servicePointIds = []; if (array_key_exists($locationId, $locationMap)) { return $locationMap[$locationId]; } else { From 280269721fb1131d93e9de308bc64c364b58c4d1 Mon Sep 17 00:00:00 2001 From: Maccabee Levine Date: Thu, 22 Aug 2024 20:57:41 +0000 Subject: [PATCH 3/8] Disable this setting by default --- config/vufind/Folio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/vufind/Folio.ini b/config/vufind/Folio.ini index e5c40fa9bf6..443e815b87e 100644 --- a/config/vufind/Folio.ini +++ b/config/vufind/Folio.ini @@ -119,7 +119,7 @@ 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. -limitPickupLocations = itemEffectiveLocation +;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 From 55951bfea0b840401f0dc933a3899d50dc48a2a1 Mon Sep 17 00:00:00 2001 From: Maccabee Levine Date: Thu, 22 Aug 2024 20:58:43 +0000 Subject: [PATCH 4/8] Comment about item-level requests. --- config/vufind/Folio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/vufind/Folio.ini b/config/vufind/Folio.ini index 443e815b87e..6ab52375900 100644 --- a/config/vufind/Folio.ini +++ b/config/vufind/Folio.ini @@ -118,7 +118,7 @@ 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. +; 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 From f74e0c2594d23b3fc2c20e14137cb1bee5b6c754 Mon Sep 17 00:00:00 2001 From: Maccabee Levine Date: Tue, 27 Aug 2024 14:38:03 +0000 Subject: [PATCH 5/8] Init $limitedServicePoints to null --- module/VuFind/src/VuFind/ILS/Driver/Folio.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/VuFind/src/VuFind/ILS/Driver/Folio.php b/module/VuFind/src/VuFind/ILS/Driver/Folio.php index dc7355c067a..48cc17a8a56 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/Folio.php +++ b/module/VuFind/src/VuFind/ILS/Driver/Folio.php @@ -1397,7 +1397,7 @@ public function renewMyItems($renewDetails) */ public function getPickupLocations($patron, $holdInfo = null) { - $limitedServicePoints = false; + $limitedServicePoints = null; if ( str_contains($this->config['Holds']['limitPickupLocations'] ?? '', 'itemEffectiveLocation') && $holdInfo['item_id'] ?? false From 048fe3ee3ddb88fc02a4f5f80924e327e456c6ca Mon Sep 17 00:00:00 2001 From: Maccabee Levine Date: Tue, 27 Aug 2024 20:40:55 +0000 Subject: [PATCH 6/8] Add code comment about item level holds --- module/VuFind/src/VuFind/ILS/Driver/Folio.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/module/VuFind/src/VuFind/ILS/Driver/Folio.php b/module/VuFind/src/VuFind/ILS/Driver/Folio.php index 48cc17a8a56..c4c68f22ddb 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/Folio.php +++ b/module/VuFind/src/VuFind/ILS/Driver/Folio.php @@ -1400,6 +1400,8 @@ 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 ) { $response = $this->makeRequest( From 2e7f621e5334b5a55254d5a2cc27acef5d5a6898 Mon Sep 17 00:00:00 2001 From: Maccabee Levine Date: Thu, 29 Aug 2024 13:21:46 +0000 Subject: [PATCH 7/8] Refactor items calls into separate function --- module/VuFind/src/VuFind/ILS/Driver/Folio.php | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/module/VuFind/src/VuFind/ILS/Driver/Folio.php b/module/VuFind/src/VuFind/ILS/Driver/Folio.php index c4c68f22ddb..a6549f290a2 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/Folio.php +++ b/module/VuFind/src/VuFind/ILS/Driver/Folio.php @@ -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( @@ -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. @@ -1404,11 +1417,7 @@ public function getPickupLocations($patron, $holdInfo = null) // so limiting by itemEffectiveLocation does not apply && $holdInfo['item_id'] ?? false ) { - $response = $this->makeRequest( - 'GET', - '/item-storage/items/' . $holdInfo['item_id'] - ); - $item = json_decode($response->getBody()); + $item = $this->getItemById($holdInfo['item_id']); $itemLocationId = $item->effectiveLocationId; $limitedServicePoints = $this->getLocationData($itemLocationId)['servicePointIds']; } From 0f986361724ec0947621d28acfeb02e8c55ab01e Mon Sep 17 00:00:00 2001 From: Maccabee Levine Date: Thu, 29 Aug 2024 13:26:22 +0000 Subject: [PATCH 8/8] Fix return type --- module/VuFind/src/VuFind/ILS/Driver/Folio.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/VuFind/src/VuFind/ILS/Driver/Folio.php b/module/VuFind/src/VuFind/ILS/Driver/Folio.php index a6549f290a2..33a23b0cfcb 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/Folio.php +++ b/module/VuFind/src/VuFind/ILS/Driver/Folio.php @@ -375,7 +375,7 @@ protected function getInstanceById( * * @param string $itemId UUID * - * @return stdClass The item + * @return \stdClass The item */ protected function getItemById($itemId) {