From 3eb55c7cb9b1c238b3e3d8caa190aea06558ede9 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Wed, 5 Dec 2012 14:19:08 -0500 Subject: [PATCH] Implemented missing support for hideHoldingsTabWhenEmpty configuration setting. --- module/VuFind/config/module.config.php | 17 +++++++++- .../src/VuFind/RecordTab/HoldingsILS.php | 32 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index 2475b5eac28..4fb40cacff5 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -318,11 +318,26 @@ $config = array( ), 'recordtab_plugin_manager' => array( 'abstract_factories' => array('VuFind\RecordTab\PluginFactory'), + 'factories' => array( + 'holdingsils' => function ($sm) { + // If VuFind is configured to suppress the holdings tab when the + // ILS driver specifies no holdings, we need to pass in a connection + // object: + $config = \VuFind\Config\Reader::getConfig(); + if (isset($config->Site->hideHoldingsTabWhenEmpty) + && $config->Site->hideHoldingsTabWhenEmpty + ) { + $catalog = $sm->getServiceLocator()->get('VuFind\ILSConnection'); + } else { + $catalog = false; + } + return new \VuFind\RecordTab\HoldingsILS($catalog); + }, + ), 'invokables' => array( 'description' => 'VuFind\RecordTab\Description', 'excerpt' => 'VuFind\RecordTab\Excerpt', 'hierarchytree' => 'VuFind\RecordTab\HierarchyTree', - 'holdingsils' => 'VuFind\RecordTab\HoldingsILS', 'holdingsworldcat' => 'VuFind\RecordTab\HoldingsWorldCat', 'map' => 'VuFind\RecordTab\Map', 'reviews' => 'VuFind\RecordTab\Reviews', diff --git a/module/VuFind/src/VuFind/RecordTab/HoldingsILS.php b/module/VuFind/src/VuFind/RecordTab/HoldingsILS.php index 1b8dd3a3018..2c4d17f8c67 100644 --- a/module/VuFind/src/VuFind/RecordTab/HoldingsILS.php +++ b/module/VuFind/src/VuFind/RecordTab/HoldingsILS.php @@ -38,6 +38,25 @@ namespace VuFind\RecordTab; */ class HoldingsILS extends AbstractBase { + /** + * ILS connection (or false if not applicable) + * + * @param \VuFind\ILS\Connection|bool + */ + protected $catalog; + + /** + * Constructor + * + * @param \VuFind\ILS\Connection|bool $catalog ILS connection to use to check + * for holdings before displaying the tab; set to false if no check is needed + */ + public function __construct($catalog) + { + $this->catalog = ($catalog && $catalog instanceof \VuFind\ILS\Connection) + ? $catalog : false; + } + /** * Get the on-screen description for this tab. * @@ -47,4 +66,17 @@ class HoldingsILS extends AbstractBase { return 'Holdings'; } + + /** + * Is this tab active? + * + * @return bool + */ + public function isActive() + { + if ($this->catalog) { + return $this->catalog->hasHoldings($this->driver->getUniqueID()); + } + return true; + } } \ No newline at end of file -- GitLab