diff --git a/config/vufind/config.ini b/config/vufind/config.ini index 5a6cce97cf5be2255447447765826765c870c3fc..7be4d08207d15af1a3c776537836a6a4f58df1b9 100644 --- a/config/vufind/config.ini +++ b/config/vufind/config.ini @@ -127,7 +127,8 @@ holds_mode = "all" ; Set this to true if you want to allow your ILS driver to override your holds_mode ; setting on a record-by-record basis; this may be useful for local customizations, -; but in most cases you should leave this setting unchanged. +; but in most cases you should leave this setting unchanged. Overrides are ignored +; for mode settings of "driver" or "disabled." allow_holds_override = false ; Determines if holds can be cancelled or not. Options are true or false. diff --git a/module/VuFind/src/VuFind/ILS/Logic/TitleHolds.php b/module/VuFind/src/VuFind/ILS/Logic/TitleHolds.php index 0236451e9fed860336d5b5447e036c961e7f18ff..68b08c504ebd387c4626a1ada042608cebcb223a 100644 --- a/module/VuFind/src/VuFind/ILS/Logic/TitleHolds.php +++ b/module/VuFind/src/VuFind/ILS/Logic/TitleHolds.php @@ -88,12 +88,64 @@ class TitleHolds } return $this->driverHold($id, $patron); } else { + $mode = $this->checkOverrideMode($id, $mode); return $this->generateHold($id, $mode); } } return false; } + /** + * Get holdings for a particular record. + * + * @param string $id ID to retrieve + * + * @return array + */ + protected function getHoldings($id) + { + // Cache results in a static array since the same holdings may be requested + // multiple times during a run through the class: + static $holdings = array(); + + if (!isset($holdings[$id])) { + $holdings[$id] = $this->catalog->getHolding($id); + } + return $holdings[$id]; + } + + /** + * Support method for getHold to determine if we should override the configured + * holds mode. + * + * @param string $id Record ID to check + * @param string $mode Current mode + * + * @return string + */ + protected function checkOverrideMode($id, $mode) + { + if (isset($this->config->Catalog->allow_holds_override) + && $this->config->Catalog->allow_holds_override + ) { + $holdings = $this->getHoldings($id); + + // For title holds, the most important override feature to handle + // is to prevent displaying a link if all items are disabled. We + // may eventually want to address other scenarios as well. + $allDisabled = true; + foreach ($holdings as $holding) { + if (!isset($holding['holdOverride']) + || "disabled" != $holding['holdOverride'] + ) { + $allDisabled = false; + } + } + $mode = (true == $allDisabled) ? "disabled" : $mode; + } + return $mode; + } + /** * Protected method for driver defined title holds * @@ -143,12 +195,11 @@ class TitleHolds $checkHolds = $this->catalog->checkFunction("Holds"); if ($checkHolds != false) { - if ($type == "always") { $addlink = true; } elseif ($type == "availability") { - $holdings = $this->catalog->getHolding($id); + $holdings = $this->getHoldings($id); foreach ($holdings as $holding) { if ($holding['availability'] && !in_array($holding['location'], $this->hideHoldings) @@ -161,10 +212,10 @@ class TitleHolds if ($addlink) { if ($checkHolds['function'] == "getHoldLink") { - /* Return opac link */ + // Return opac link return $this->catalog->getHoldLink($id, $data); } else { - /* Return non-opac link */ + // Return non-opac link return $this->getHoldDetails($data, $checkHolds['HMACKeys']); } }