From c65f2cb982006ef44128c0b05ea4e539ab47da1b Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Wed, 22 Oct 2014 14:23:40 -0400
Subject: [PATCH] More logical RecordTab implementation. - This makes it
 possible to use this tab with non-WorldCat records, as long as they have an
 OCLC number.

---
 .../src/VuFind/RecordTab/HoldingsWorldCat.php | 34 ++++++++++++++++---
 .../RecordTab/holdingsworldcat.phtml          |  2 +-
 .../RecordTab/holdingsworldcat.phtml          |  2 +-
 .../RecordTab/holdingsworldcat.phtml          |  2 +-
 .../RecordTab/holdingsworldcat.phtml          |  2 +-
 5 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/module/VuFind/src/VuFind/RecordTab/HoldingsWorldCat.php b/module/VuFind/src/VuFind/RecordTab/HoldingsWorldCat.php
index 144aaf96b7a..2b91d0ee049 100644
--- a/module/VuFind/src/VuFind/RecordTab/HoldingsWorldCat.php
+++ b/module/VuFind/src/VuFind/RecordTab/HoldingsWorldCat.php
@@ -67,14 +67,38 @@ class HoldingsWorldCat extends AbstractBase
     }
 
     /**
-     * Get holdings information from WorldCat.
+     * Get holdings information from WorldCat (false if none available).
      *
-     * @param string $id Record ID
+     * @return \SimpleXMLElement|bool
+     */
+    public function getHoldings()
+    {
+        $id = $this->getOCLCNum();
+        return empty($id) ? false : $this->wc->getHoldings($id);
+    }
+
+    /**
+     * Is this tab active?
+     *
+     * @return bool
+     */
+    public function isActive()
+    {
+        $id = $this->getOCLCNum();
+        return !empty($id);
+    }
+
+    /**
+     * Get the OCLC number from the active record driver.
      *
-     * @return \SimpleXMLElement
+     * @return string
      */
-    public function getHoldings($id)
+    protected function getOCLCNum()
     {
-        return $this->wc->getHoldings($id);
+        static $id = false;     // cache value in static variable
+        if (!$id) {
+            $id = $this->getRecordDriver()->tryMethod('getCleanOCLCNum');
+        }
+        return $id;
     }
 }
\ No newline at end of file
diff --git a/themes/blueprint/templates/RecordTab/holdingsworldcat.phtml b/themes/blueprint/templates/RecordTab/holdingsworldcat.phtml
index 2f4c12ca45d..8148ca6d4cc 100644
--- a/themes/blueprint/templates/RecordTab/holdingsworldcat.phtml
+++ b/themes/blueprint/templates/RecordTab/holdingsworldcat.phtml
@@ -1,4 +1,4 @@
-<? $holdings = $this->tab->getHoldings($this->driver->getUniqueId()); if ($holdings && count($holdings) > 0): ?>
+<? $holdings = $this->tab->getHoldings(); if ($holdings && count($holdings) > 0): ?>
 <h3><?=$this->transEsc('Holdings at Other Libraries')?></h3>
 <table cellpadding="2" cellspacing="0" border="0" class="citation" width="100%">
 <? foreach ($holdings as $holding): ?>
diff --git a/themes/bootstrap/templates/RecordTab/holdingsworldcat.phtml b/themes/bootstrap/templates/RecordTab/holdingsworldcat.phtml
index 6f1e69c64d5..57c0267ecdd 100644
--- a/themes/bootstrap/templates/RecordTab/holdingsworldcat.phtml
+++ b/themes/bootstrap/templates/RecordTab/holdingsworldcat.phtml
@@ -1,4 +1,4 @@
-<? $holdings = $this->tab->getHoldings($this->driver->getUniqueId()); if ($holdings && count($holdings) > 0): ?>
+<? $holdings = $this->tab->getHoldings(); if ($holdings && count($holdings) > 0): ?>
 <h3><?=$this->transEsc('Holdings at Other Libraries')?></h3>
 <table class="table table-striped">
 <? foreach ($holdings as $holding): ?>
diff --git a/themes/bootstrap3/templates/RecordTab/holdingsworldcat.phtml b/themes/bootstrap3/templates/RecordTab/holdingsworldcat.phtml
index 6f1e69c64d5..57c0267ecdd 100644
--- a/themes/bootstrap3/templates/RecordTab/holdingsworldcat.phtml
+++ b/themes/bootstrap3/templates/RecordTab/holdingsworldcat.phtml
@@ -1,4 +1,4 @@
-<? $holdings = $this->tab->getHoldings($this->driver->getUniqueId()); if ($holdings && count($holdings) > 0): ?>
+<? $holdings = $this->tab->getHoldings(); if ($holdings && count($holdings) > 0): ?>
 <h3><?=$this->transEsc('Holdings at Other Libraries')?></h3>
 <table class="table table-striped">
 <? foreach ($holdings as $holding): ?>
diff --git a/themes/jquerymobile/templates/RecordTab/holdingsworldcat.phtml b/themes/jquerymobile/templates/RecordTab/holdingsworldcat.phtml
index 2f4c12ca45d..8148ca6d4cc 100644
--- a/themes/jquerymobile/templates/RecordTab/holdingsworldcat.phtml
+++ b/themes/jquerymobile/templates/RecordTab/holdingsworldcat.phtml
@@ -1,4 +1,4 @@
-<? $holdings = $this->tab->getHoldings($this->driver->getUniqueId()); if ($holdings && count($holdings) > 0): ?>
+<? $holdings = $this->tab->getHoldings(); if ($holdings && count($holdings) > 0): ?>
 <h3><?=$this->transEsc('Holdings at Other Libraries')?></h3>
 <table cellpadding="2" cellspacing="0" border="0" class="citation" width="100%">
 <? foreach ($holdings as $holding): ?>
-- 
GitLab