diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index 2e08e6eaa1e2741a06876ff356de2f6b8fb998d8..d4dc2d5cf18d9301df021688ae640ba503733e3c 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -167,11 +167,25 @@ $config = array( $sm->get('VuFind\ILSDriverPluginManager') ); }, + 'VuFind\ILSHoldLogic' => function ($sm) { + return new \VuFind\ILS\Logic\Holds( + $sm->get('VuFind\AuthManager'), + $sm->get('VuFind\ILSConnection'), + $sm->get('VuFind\Config')->get('config') + ); + }, 'VuFind\ILSHoldSettings' => function ($sm) { return new \VuFind\ILS\HoldSettings( $sm->get('VuFind\Config')->get('config')->Catalog ); }, + 'VuFind\ILSTitleHoldLogic' => function ($sm) { + return new \VuFind\ILS\Logic\TitleHolds( + $sm->get('VuFind\AuthManager'), + $sm->get('VuFind\ILSConnection'), + $sm->get('VuFind\Config')->get('config') + ); + }, 'VuFind\Logger' => function ($sm) { $logger = new \VuFind\Log\Logger(); $logger->setServiceLocator($sm); @@ -489,11 +503,17 @@ $config = array( ); }, 'solrmarc' => function ($sm) { - return new \VuFind\RecordDriver\SolrMarc( + $driver = new \VuFind\RecordDriver\SolrMarc( $sm->getServiceLocator()->get('VuFind\Config')->get('config'), null, $sm->getServiceLocator()->get('VuFind\Config')->get('searches') ); + $driver->attachILS( + $sm->getServiceLocator()->get('VuFind\ILSConnection'), + $sm->getServiceLocator()->get('VuFind\ILSHoldLogic'), + $sm->getServiceLocator()->get('VuFind\ILSTitleHoldLogic') + ); + return $driver; }, 'solrreserves' => function ($sm) { return new \VuFind\RecordDriver\SolrReserves( diff --git a/module/VuFind/src/VuFind/Controller/AjaxController.php b/module/VuFind/src/VuFind/Controller/AjaxController.php index 6f64c5d850810e54ec359442ce6dfb9915fab93f..5d19f4e1248ed1f0594b0f9a63dbf2cebf3d760a 100644 --- a/module/VuFind/src/VuFind/Controller/AjaxController.php +++ b/module/VuFind/src/VuFind/Controller/AjaxController.php @@ -149,15 +149,14 @@ class AjaxController extends AbstractBase * * @param array $record Information on items linked to a single * bib record - * @param \VuFind\ILS\Connection $catalog ILS connection * * @return array Filtered version of $record */ - protected function filterSuppressedLocations($record, $catalog) + protected function filterSuppressedLocations($record) { static $hideHoldings = false; if ($hideHoldings === false) { - $logic = new \VuFind\ILS\Logic\Holds($this->getAuthManager(), $catalog); + $logic = $this->getServiceLocator()->get('VuFind\ILSHoldLogic'); $hideHoldings = $logic->getSuppressedLocations(); } @@ -222,7 +221,7 @@ class AjaxController extends AbstractBase $statuses = array(); foreach ($results as $recordNumber=>$record) { // Filter out suppressed locations: - $record = $this->filterSuppressedLocations($record, $catalog); + $record = $this->filterSuppressedLocations($record); // Skip empty records: if (count($record)) { diff --git a/module/VuFind/src/VuFind/ILS/Logic/Holds.php b/module/VuFind/src/VuFind/ILS/Logic/Holds.php index ed34576f50b8885cc5a9c706c75bb52d22ad5cf6..e728352a10c85a738b997142015621191ed65f32 100644 --- a/module/VuFind/src/VuFind/ILS/Logic/Holds.php +++ b/module/VuFind/src/VuFind/ILS/Logic/Holds.php @@ -27,8 +27,7 @@ * @link http://vufind.org/wiki/vufind2:developer_manual Wiki */ namespace VuFind\ILS\Logic; -use VuFind\Config\Reader as ConfigReader, VuFind\Crypt\HMAC, - VuFind\ILS\Connection as ILSConnection; +use VuFind\Crypt\HMAC, VuFind\ILS\Connection as ILSConnection; /** * Hold Logic Class @@ -75,11 +74,13 @@ class Holds * * @param \VuFind\Auth\Manager $account Auth manager object * @param ILSConnection $ils A catalog connection + * @param \Zend\Config\Config $config VuFind configuration */ - public function __construct(\VuFind\Auth\Manager $account, ILSConnection $ils) - { + public function __construct(\VuFind\Auth\Manager $account, ILSConnection $ils, + \Zend\Config\Config $config + ) { $this->account = $account; - $this->config = ConfigReader::getConfig(); + $this->config = $config; if (isset($this->config->Record->hide_holdings)) { foreach ($this->config->Record->hide_holdings as $current) { diff --git a/module/VuFind/src/VuFind/ILS/Logic/TitleHolds.php b/module/VuFind/src/VuFind/ILS/Logic/TitleHolds.php index 8d6e517fc839c0b50f827e4c273815d980df2caa..2431c8f06b067301897432be5b79ed9e57f6da4c 100644 --- a/module/VuFind/src/VuFind/ILS/Logic/TitleHolds.php +++ b/module/VuFind/src/VuFind/ILS/Logic/TitleHolds.php @@ -27,8 +27,7 @@ * @link http://vufind.org/wiki/vufind2:developer_manual Wiki */ namespace VuFind\ILS\Logic; -use VuFind\Config\Reader as ConfigReader, VuFind\Crypt\HMAC, - VuFind\ILS\Connection as ILSConnection; +use VuFind\Crypt\HMAC, VuFind\ILS\Connection as ILSConnection; /** * Title Hold Logic Class @@ -75,11 +74,13 @@ class TitleHolds * * @param \VuFind\Auth\Manager $account Auth manager object * @param ILSConnection $ils A catalog connection + * @param \Zend\Config\Config $config VuFind configuration */ - public function __construct(\VuFind\Auth\Manager $account, ILSConnection $ils) - { + public function __construct(\VuFind\Auth\Manager $account, ILSConnection $ils, + \Zend\Config\Config $config + ) { $this->account = $account; - $this->config = ConfigReader::getConfig(); + $this->config = $config; if (isset($this->config->Record->hide_holdings)) { foreach ($this->config->Record->hide_holdings as $current) { diff --git a/module/VuFind/src/VuFind/RecordDriver/SolrDefault.php b/module/VuFind/src/VuFind/RecordDriver/SolrDefault.php index 57b2cbe084112312155ecc9d6949fecba9b9a6ca..e7807ffbb8fd65cdb808dab617c4b8799423ddbd 100644 --- a/module/VuFind/src/VuFind/RecordDriver/SolrDefault.php +++ b/module/VuFind/src/VuFind/RecordDriver/SolrDefault.php @@ -875,11 +875,9 @@ class SolrDefault extends AbstractBase * Get an array of information about record holdings, obtained in real-time * from the ILS. * - * @param \VuFind\Auth\Manager $account Auth manager object - * * @return array */ - public function getRealTimeHoldings(\VuFind\Auth\Manager $account) + public function getRealTimeHoldings() { // Not supported by the Solr index -- implement in child classes. return array(); diff --git a/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php b/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php index b1101041bda2a79ba64c64765e79ebe8329f2641..22669543d8b3e0a63c88244802874c1a235cecae 100644 --- a/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php +++ b/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php @@ -26,10 +26,7 @@ * @link http://vufind.org/wiki/vufind2:record_drivers Wiki */ namespace VuFind\RecordDriver; -use VuFind\Exception\ILS as ILSException, - VuFind\ILS\Logic\Holds as HoldLogic, - VuFind\ILS\Logic\TitleHolds as TitleHoldLogic, - VuFind\XSLT\Processor as XSLTProcessor; +use VuFind\Exception\ILS as ILSException, VuFind\XSLT\Processor as XSLTProcessor; /** * Model for MARC records in Solr. @@ -49,6 +46,27 @@ class SolrMarc extends SolrDefault */ protected $marcRecord; + /** + * ILS connection + * + * @var \VuFind\ILS\Connection + */ + protected $ils = null; + + /** + * Hold logic + * + * @var \VuFind\ILS\Logic\Holds + */ + protected $holdLogic; + + /** + * Title hold logic + * + * @var \VuFind\ILS\Logic\TitleHolds + */ + protected $titleHoldLogic; + /** * Set raw data to initialize the object. * @@ -914,28 +932,42 @@ class SolrMarc extends SolrDefault } /** - * Get the ILS connection. + * Attach an ILS connection and related logic to the driver * - * @return \VuFind\ILS\Connection + * @param \VuFind\ILS\Connection $ils ILS connection + * @param \VuFind\ILS\Logic\Holds $holdLogic Hold logic handler + * @param \VuFind\ILS\Logic\TitleHolds $titleHoldLogic Title hold logic handler */ - protected function getILS() + public function attachILS(\VuFind\ILS\Connection $ils, + \VuFind\ILS\Logic\Holds $holdLogic, + \VuFind\ILS\Logic\TitleHolds $titleHoldLogic + ) { + $this->ils = $ils; + $this->holdLogic = $holdLogic; + $this->titleHoldLogic = $titleHoldLogic; + } + + /** + * Do we have an attached ILS connection? + * + * @return bool + */ + protected function hasILS() { - return $this->getServiceLocator()->getServiceLocator() - ->get('VuFind\ILSConnection'); + return null !== $this->ils; } /** * Get an array of information about record holdings, obtained in real-time * from the ILS. * - * @param \VuFind\Auth\Manager $account Auth manager object - * * @return array */ - public function getRealTimeHoldings(\VuFind\Auth\Manager $account) + public function getRealTimeHoldings() { - $holdLogic = new HoldLogic($account, $this->getILS()); - return $holdLogic->getHoldings($this->getUniqueID()); + return $this->hasILS() + ? $this->holdLogic->getHoldings($this->getUniqueID()) + : array(); } /** @@ -947,8 +979,11 @@ class SolrMarc extends SolrDefault public function getRealTimeHistory() { // Get Acquisitions Data + if (!$this->hasILS()) { + return array(); + } try { - return $this->getILS()->getPurchaseHistory($this->getUniqueID()); + return $this->ils->getPurchaseHistory($this->getUniqueID()); } catch (ILSException $e) { return array(); } @@ -957,19 +992,16 @@ class SolrMarc extends SolrDefault /** * Get a link for placing a title level hold. * - * @param \VuFind\Auth\Manager $account Auth manager object - * * @return mixed A url if a hold is possible, boolean false if not */ - public function getRealTimeTitleHold(\VuFind\Auth\Manager $account) + public function getRealTimeTitleHold() { - $biblioLevel = $this->getBibliographicLevel(); - if ("monograph" == strtolower($biblioLevel) - || stristr("part", $biblioLevel) - ) { - if ($this->getILS()->getTitleHoldsMode() != "disabled") { - $holdLogic = new TitleHoldLogic($account, $this->getILS()); - return $holdLogic->getHold($this->getUniqueID()); + if ($this->hasILS()) { + $biblioLevel = strtolower($this->getBibliographicLevel()); + if ("monograph" == $biblioLevel || strstr("part", $biblioLevel)) { + if ($this->ils->getTitleHoldsMode() != "disabled") { + return $this->titleHoldLogic->getHold($this->getUniqueID()); + } } } diff --git a/module/VuFind/src/VuFind/RecordDriver/WorldCat.php b/module/VuFind/src/VuFind/RecordDriver/WorldCat.php index c172fff649d3c3df7c72a4d103b4ea6fa977c624..0510ec6a2addd1a42441b558985e64632dcd4671 100644 --- a/module/VuFind/src/VuFind/RecordDriver/WorldCat.php +++ b/module/VuFind/src/VuFind/RecordDriver/WorldCat.php @@ -81,11 +81,9 @@ class WorldCat extends SolrMarc * Get an array of information about record holdings, obtained in real-time * from the ILS. * - * @param \VuFind\Auth\Manager $account Auth manager object - * * @return array */ - public function getRealTimeHoldings(\VuFind\Auth\Manager $account) + public function getRealTimeHoldings() { // Not supported here: return array(); diff --git a/themes/blueprint/templates/RecordTab/holdingsils.phtml b/themes/blueprint/templates/RecordTab/holdingsils.phtml index a4db7a3b2d094ab22eea0db0300670258d5f17fd..79e862bd3f57c3689618fc41dac1e331e84cd5d6 100644 --- a/themes/blueprint/templates/RecordTab/holdingsils.phtml +++ b/themes/blueprint/templates/RecordTab/holdingsils.phtml @@ -2,7 +2,7 @@ // Set up convenience variables: $account = $this->auth()->getManager(); $user = $account->isLoggedIn(); - $holdings = $this->driver->getRealTimeHoldings($account); + $holdings = $this->driver->getRealTimeHoldings(); $openUrl = $this->driver->openURLActive('holdings') ? $this->driver->getOpenURL() : false; $offlineMode = $this->ils()->getOfflineMode(); // Account for replace_other_urls setting @@ -33,7 +33,7 @@ <? endif; ?> <? endif; ?> <? endif; ?> -<? $holdingTitleHold = $this->driver->tryMethod('getRealTimeTitleHold', array($account)); if (!empty($holdingTitleHold)): ?> +<? $holdingTitleHold = $this->driver->tryMethod('getRealTimeTitleHold'); if (!empty($holdingTitleHold)): ?> <a class="holdPlace" href="<?=$this->recordLink()->getHoldUrl($holdingTitleHold)?>"><?=$this->transEsc('title_hold_place')?></a> <? endif; ?> <? if (!empty($urls) || $openUrl): ?> diff --git a/themes/jquerymobile/templates/RecordTab/holdingsils.phtml b/themes/jquerymobile/templates/RecordTab/holdingsils.phtml index e49ed4462aad7073e49fd20a119130c66d2a4bd4..66f3848768af9603bd6219b10b2fd145f26e7187 100644 --- a/themes/jquerymobile/templates/RecordTab/holdingsils.phtml +++ b/themes/jquerymobile/templates/RecordTab/holdingsils.phtml @@ -2,7 +2,7 @@ // Set up convenience variables: $account = $this->auth()->getManager(); $user = $account->isLoggedIn(); - $holdings = $this->driver->getRealTimeHoldings($account); + $holdings = $this->driver->getRealTimeHoldings(); $offlineMode = $this->ils()->getOfflineMode(); // Set page title. @@ -30,7 +30,7 @@ <? endif; ?> <? endif; ?> <? endif; ?> -<? $holdingTitleHold = $this->driver->tryMethod('getRealTimeTitleHold', array($account)); if (!empty($holdingTitleHold)): ?> +<? $holdingTitleHold = $this->driver->tryMethod('getRealTimeTitleHold'); if (!empty($holdingTitleHold)): ?> <a rel="external" class="holdPlace" href="<?=$this->recordLink()->getHoldUrl($holdingTitleHold, false)?>"><?=$this->transEsc('title_hold_place')?></a> <? endif; ?> <? foreach ($holdings as $location => $holding): ?> diff --git a/themes/root/templates/Email/record-sms.phtml b/themes/root/templates/Email/record-sms.phtml index 5bf63173fa150f959e6b4405bb234e3be002c20d..411c4ce214d00450b72f1e33a97d0602543b132d 100644 --- a/themes/root/templates/Email/record-sms.phtml +++ b/themes/root/templates/Email/record-sms.phtml @@ -7,7 +7,7 @@ // since text messages can be short, and we want the most important stuff // at the top! if ($this->driver->supportsAjaxStatus()) { - $holdings = $this->driver->getRealTimeHoldings($this->auth()->getManager()); + $holdings = $this->driver->getRealTimeHoldings(); // Figure out which call number/location to display. We'll try to find // a location with an available item that has a call number. Failing that,