From 583fb56183ff2be77ffeb83f8b9edd40f7649a6d Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Wed, 29 Aug 2012 15:08:07 -0400
Subject: [PATCH] Created ILS view helper to eliminate direct access to
 \VuFind\Connection\Manager from within templates.

---
 .../src/VuFind/Theme/Root/Helper/Ils.php      | 51 +++++++++++++++++++
 .../SolrDefault/tab-holdings.phtml            |  2 +-
 .../templates/myresearch/cataloglogin.phtml   |  2 +-
 .../templates/myresearch/login.phtml          |  2 +-
 .../SolrDefault/tab-holdings.phtml            |  2 +-
 .../templates/myresearch/cataloglogin.phtml   |  2 +-
 .../templates/myresearch/login.phtml          |  2 +-
 themes/root/theme.ini                         |  1 +
 8 files changed, 58 insertions(+), 6 deletions(-)
 create mode 100644 module/VuFind/src/VuFind/Theme/Root/Helper/Ils.php

diff --git a/module/VuFind/src/VuFind/Theme/Root/Helper/Ils.php b/module/VuFind/src/VuFind/Theme/Root/Helper/Ils.php
new file mode 100644
index 00000000000..fccfccf7283
--- /dev/null
+++ b/module/VuFind/src/VuFind/Theme/Root/Helper/Ils.php
@@ -0,0 +1,51 @@
+<?php
+/**
+ * ILS (integrated library system) view helper
+ *
+ * PHP version 5
+ *
+ * Copyright (C) Villanova University 2010.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * @category VuFind2
+ * @package  View_Helpers
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     http://vufind.org/wiki/building_a_recommendations_module Wiki
+ */
+namespace VuFind\Theme\Root\Helper;
+use Zend\View\Helper\AbstractHelper;
+
+/**
+ * ILS (integrated library system) view helper
+ *
+ * @category VuFind2
+ * @package  View_Helpers
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     http://vufind.org/wiki/building_a_recommendations_module Wiki
+ */
+class Ils extends AbstractHelper
+{
+    /**
+     * Get the ILS connection object.
+     *
+     * @return \VuFind\ILS\Connection
+     */
+    public function __invoke()
+    {
+        return \VuFind\Connection\Manager::connectToCatalog();
+    }
+}
\ No newline at end of file
diff --git a/themes/blueprint/templates/RecordDriver/SolrDefault/tab-holdings.phtml b/themes/blueprint/templates/RecordDriver/SolrDefault/tab-holdings.phtml
index 1e17906d429..a6daf896298 100644
--- a/themes/blueprint/templates/RecordDriver/SolrDefault/tab-holdings.phtml
+++ b/themes/blueprint/templates/RecordDriver/SolrDefault/tab-holdings.phtml
@@ -3,7 +3,7 @@
     $user = $this->layout()->account->isLoggedIn();
     $holdings = $this->driver->getRealTimeHoldings($this->layout()->account);
     $openUrl = $this->driver->openURLActive('holdings') ? $this->driver->getOpenURL() : false;
-    $offlineMode = \VuFind\Connection\Manager::connectToCatalog()->getOfflineMode();
+    $offlineMode = $this->ils()->getOfflineMode();
     // Account for replace_other_urls setting
     $urls = ($openUrl && $this->driver->replaceURLsWithOpenURL()) ? array() : $this->record($this->driver)->getLinkDetails();
 
diff --git a/themes/blueprint/templates/myresearch/cataloglogin.phtml b/themes/blueprint/templates/myresearch/cataloglogin.phtml
index 4f4bc0e94bc..da71a03c082 100644
--- a/themes/blueprint/templates/myresearch/cataloglogin.phtml
+++ b/themes/blueprint/templates/myresearch/cataloglogin.phtml
@@ -8,7 +8,7 @@
         . $this->transEsc('Login') . '</em>';
 
     // Convenience variable:
-    $offlineMode = \VuFind\Connection\Manager::connectToCatalog()->getOfflineMode();
+    $offlineMode = $this->ils()->getOfflineMode();
 ?>
 <? if ($offlineMode == "ils-offline"): ?>
   <div class="sysInfo">
diff --git a/themes/blueprint/templates/myresearch/login.phtml b/themes/blueprint/templates/myresearch/login.phtml
index 14e09542a33..90bf7b92d1b 100644
--- a/themes/blueprint/templates/myresearch/login.phtml
+++ b/themes/blueprint/templates/myresearch/login.phtml
@@ -15,7 +15,7 @@
     // Convenience variables:
     $account = $this->layout()->account;
     $hideLogin = !(is_object($account) && $account->loginEnabled());
-    $offlineMode = \VuFind\Connection\Manager::connectToCatalog()->getOfflineMode();
+    $offlineMode = $this->ils()->getOfflineMode();
 ?>
 
 <? if ($offlineMode == "ils-offline"): ?>
diff --git a/themes/jquerymobile/templates/RecordDriver/SolrDefault/tab-holdings.phtml b/themes/jquerymobile/templates/RecordDriver/SolrDefault/tab-holdings.phtml
index 2730774391a..a2283e1bdf5 100644
--- a/themes/jquerymobile/templates/RecordDriver/SolrDefault/tab-holdings.phtml
+++ b/themes/jquerymobile/templates/RecordDriver/SolrDefault/tab-holdings.phtml
@@ -2,7 +2,7 @@
     // Set up convenience variables:
     $user = $this->layout()->account->isLoggedIn();
     $holdings = $this->driver->getRealTimeHoldings($this->layout()->account);
-    $offlineMode = \VuFind\Connection\Manager::connectToCatalog()->getOfflineMode();
+    $offlineMode = $this->ils()->getOfflineMode();
 
     // Set page title.
     $this->headTitle($this->translate('Holdings') . ': ' . $this->driver->getBreadcrumb());
diff --git a/themes/jquerymobile/templates/myresearch/cataloglogin.phtml b/themes/jquerymobile/templates/myresearch/cataloglogin.phtml
index 0218a0996da..2cfcff0f55a 100644
--- a/themes/jquerymobile/templates/myresearch/cataloglogin.phtml
+++ b/themes/jquerymobile/templates/myresearch/cataloglogin.phtml
@@ -3,7 +3,7 @@
     $this->headTitle($this->translate('Login'));
 
     // Convenience variable:
-    $offlineMode = \VuFind\Connection\Manager::connectToCatalog()->getOfflineMode();
+    $offlineMode = $this->ils()->getOfflineMode();
 ?>
 <div data-role="page" id="MyResearch-login">
   <?=$this->mobileMenu()->header()?>
diff --git a/themes/jquerymobile/templates/myresearch/login.phtml b/themes/jquerymobile/templates/myresearch/login.phtml
index 8a7cd844427..09e14869dd3 100644
--- a/themes/jquerymobile/templates/myresearch/login.phtml
+++ b/themes/jquerymobile/templates/myresearch/login.phtml
@@ -5,7 +5,7 @@
     // Convenience variables:
     $account = $this->layout()->account;
     $hideLogin = !(is_object($account) && $account->loginEnabled());
-    $offlineMode = \VuFind\Connection\Manager::connectToCatalog()->getOfflineMode();
+    $offlineMode = $this->ils()->getOfflineMode();
 ?>
 <div data-role="page" id="MyResearch-login">
   <?=$this->mobileMenu()->header()?>
diff --git a/themes/root/theme.ini b/themes/root/theme.ini
index 97d6acb6184..0a40eaebf66 100644
--- a/themes/root/theme.ini
+++ b/themes/root/theme.ini
@@ -19,6 +19,7 @@ helpers_to_register[] = "HeadLink"
 helpers_to_register[] = "HeadScript"
 helpers_to_register[] = "HeadThemeResources"
 helpers_to_register[] = "Highlight"
+helpers_to_register[] = "Ils"
 helpers_to_register[] = "ImageLink"
 helpers_to_register[] = "InlineScript"
 helpers_to_register[] = "JqueryValidation"
-- 
GitLab