From 444569e39fbd64ec289cbc4f1e0af6208524e18e Mon Sep 17 00:00:00 2001 From: Brad Busenius <bbusenius@users.noreply.github.com> Date: Tue, 25 Aug 2020 07:23:32 -0500 Subject: [PATCH] FOLIO: use location discoveryDisplayName instead of name (#1692) --- module/VuFind/src/VuFind/ILS/Driver/Folio.php | 41 +++++++++++++++---- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/module/VuFind/src/VuFind/ILS/Driver/Folio.php b/module/VuFind/src/VuFind/ILS/Driver/Folio.php index 958e203ee05..cede35e4ece 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/Folio.php +++ b/module/VuFind/src/VuFind/ILS/Driver/Folio.php @@ -416,6 +416,36 @@ class Folio extends AbstractAPI implements ); } + /** + * Gets the location name from the /locations endpoint and sets + * the display name to discoveryDisplayName, name, or code + * based on whichever is available first in that order. + * + * @param string $locationId ID of a location from the + * /holdings-storage/holdings endpoint + * + * @return string + */ + protected function getLocationName($locationId) + { + $locationName = ''; + if (!empty($locationId)) { + $locationResponse = $this->makeRequest( + 'GET', + '/locations/' . $locationId + ); + $location = json_decode($locationResponse->getBody()); + if (!empty($location->discoveryDisplayName)) { + $locationName = $location->discoveryDisplayName; + } elseif (!empty($location->name)) { + $locationName = $location->name; + } elseif (!empty($location->code)) { + $locationName = $location->code; + } + } + return $locationName; + } + /** * This method queries the ILS for holding information. * @@ -442,15 +472,8 @@ class Folio extends AbstractAPI implements $holdingBody = json_decode($holdingResponse->getBody()); $items = []; foreach ($holdingBody->holdingsRecords as $holding) { - $locationName = ''; - if (!empty($holding->permanentLocationId)) { - $locationResponse = $this->makeRequest( - 'GET', - '/locations/' . $holding->permanentLocationId - ); - $location = json_decode($locationResponse->getBody()); - $locationName = $location->name; - } + $locationId = $holding->permanentLocationId; + $locationName = $this->getLocationName($locationId); $query = [ 'query' => '(holdingsRecordId=="' . $holding->id -- GitLab