From 0c348aa860f653e267c1acb6e1027b7b65638498 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Fri, 4 Mar 2016 13:03:23 -0500 Subject: [PATCH] New setting to skip certain block codes. --- config/vufind/VoyagerRestful.ini | 15 +++++++ .../src/VuFind/ILS/Driver/VoyagerRestful.php | 45 +++++++++++++------ 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/config/vufind/VoyagerRestful.ini b/config/vufind/VoyagerRestful.ini index 4610a738efc..527b90be11e 100644 --- a/config/vufind/VoyagerRestful.ini +++ b/config/vufind/VoyagerRestful.ini @@ -58,6 +58,21 @@ app = vxws patronHomeUbId = "1@XXXXX" dbKey = "1@XXXXX" +; This section contains patron-related settings. +[Patron] +; Before certain actions (such as placing holds or other requests) VuFind checks +; to see if the user's account is blocked. This helps reduce the number of API +; calls and may help prevent unwanted illegal requests from being placed in some +; circumstances. However, it may also be overly exclusive, as some of the block +; reasons are for relatively minor circumstances. Including a block code in this +; comma-separated list will prevent that situation from blocking a user from making +; requests (unless the status also blocks the patron explicitly through other API +; calls). See this page for a list of numeric codes: +; https://developers.exlibrisgroup.com/voyager/apis/RESTfulWebServices/PatronBlocks +; NOTE: You may wish to clear VuFind's cache after changing this setting, as +; block statuses are cached for a short period of time. +ignoredBlockCodes = "18,53,54,55" + ; This section is used to define library codes and named values which are used by the ; system to indicate the location at which a hold is to be collected. If you leave it ; commented out, a list will automatically be generated using the getPickUpLocations diff --git a/module/VuFind/src/VuFind/ILS/Driver/VoyagerRestful.php b/module/VuFind/src/VuFind/ILS/Driver/VoyagerRestful.php index b3d8ef1d532..39705ce5cbe 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/VoyagerRestful.php +++ b/module/VuFind/src/VuFind/ILS/Driver/VoyagerRestful.php @@ -1175,6 +1175,28 @@ class VoyagerRestful extends Voyager implements \VuFindHttp\HttpServiceAwareInte return $xmlComplete; } + /** + * Given the appropriate portion of the blocks API response, extract a list + * of block reasons that VuFind is not configured to ignore. + * + * @param \SimpleXMLElement $borrowBlocks borrowingBlock section of XML response + * + * @return array + */ + protected function extractBlockReasons($borrowBlocks) + { + $whitelistConfig = isset($this->config['Patron']['ignoredBlockCodes']) + ? $this->config['Patron']['ignoredBlockCodes'] : ''; + $whitelist = array_map('trim', explode(',', $whitelistConfig)); + $blockReason = []; + foreach ($borrowBlocks as $borrowBlock) { + if (!in_array((string)$borrowBlock->blockCode, $whitelist)) { + $blockReason[] = (string)$borrowBlock->blockReason; + } + } + return $blockReason; + } + /** * Check Account Blocks * @@ -1203,21 +1225,16 @@ class VoyagerRestful extends Voyager implements \VuFindHttp\HttpServiceAwareInte "view" => "full" ]; - $blockReason = []; - $blocks = $this->makeRequest($hierarchy, $params); - if ($blocks) { - $node = "reply-text"; - $reply = (string)$blocks->$node; - - // Valid Response - if ($reply == "ok" && isset($blocks->blocks)) { - foreach ($blocks->blocks->institution->borrowingBlock - as $borrowBlock - ) { - $blockReason[] = (string)$borrowBlock->blockReason; - } - } + if ($blocks + && (string)$blocks->{'reply-text'} == "ok" + && isset($blocks->blocks->institution->borrowingBlock) + ) { + $blockReason = $this->extractBlockReasons( + $blocks->blocks->institution->borrowingBlock + ); + } else { + $blockReason = []; } $this->putCachedData($cacheId, $blockReason); } -- GitLab