From e371f79e4036ee1e59d32a3a144c24fb0c390171 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Mon, 22 Dec 2014 08:59:07 -0500
Subject: [PATCH] Added support for ILS drivers interacting with non-Solr
 backends.

---
 config/vufind/Demo.ini                        |  8 +++++++
 .../Controller/MyResearchController.php       | 10 +++++----
 module/VuFind/src/VuFind/ILS/Driver/Demo.php  | 21 +++++++++++++++++--
 .../templates/myresearch/fines.phtml          |  4 ++--
 .../templates/myresearch/fines.phtml          |  4 ++--
 .../templates/myresearch/fines.phtml          |  4 ++--
 6 files changed, 39 insertions(+), 12 deletions(-)

diff --git a/config/vufind/Demo.ini b/config/vufind/Demo.ini
index e3f4727c3a7..cf0ff761fc8 100644
--- a/config/vufind/Demo.ini
+++ b/config/vufind/Demo.ini
@@ -9,3 +9,11 @@ storageRetrievalRequests = true
 
 ; Whether to support ILL requests
 ILLRequests = true
+
+; Configuration for retrieving sample records
+[Records]
+; Search backend to pull records from
+source = Solr
+
+; Query to use for record retrieval
+query = "*:*"
\ No newline at end of file
diff --git a/module/VuFind/src/VuFind/Controller/MyResearchController.php b/module/VuFind/src/VuFind/Controller/MyResearchController.php
index 2eafcbea7a8..19dc3f8390d 100644
--- a/module/VuFind/src/VuFind/Controller/MyResearchController.php
+++ b/module/VuFind/src/VuFind/Controller/MyResearchController.php
@@ -824,8 +824,9 @@ class MyResearchController extends AbstractBase
     protected function getDriverForILSRecord($current)
     {
         $id = isset($current['id']) ? $current['id'] : null;
+        $source = isset($current['source']) ? $current['source'] : 'VuFind';
         $record = $this->getServiceLocator()->get('VuFind\RecordLoader')
-            ->load($id, 'VuFind', true);
+            ->load($id, $source, true);
         $record->setExtraDetail('ils_details', $current);
         return $record;
     }
@@ -1089,9 +1090,10 @@ class MyResearchController extends AbstractBase
                 if (!isset($row['id']) || empty($row['id'])) {
                     throw new \Exception();
                 }
-                $record = $this->getServiceLocator()->get('VuFind\RecordLoader')
-                    ->load($row['id']);
-                $row['title'] = $record->getShortTitle();
+                $source = isset($row['source']) ? $row['source'] : 'VuFind';
+                $row['driver'] = $this->getServiceLocator()->get('VuFind\RecordLoader')
+                    ->load($row['id'], $source);
+                $row['title'] = $row['driver']->getShortTitle();
             } catch (\Exception $e) {
                 if (!isset($row['title'])) {
                     $row['title'] = null;
diff --git a/module/VuFind/src/VuFind/ILS/Driver/Demo.php b/module/VuFind/src/VuFind/ILS/Driver/Demo.php
index c9dddb70ae7..c730b20cd5f 100644
--- a/module/VuFind/src/VuFind/ILS/Driver/Demo.php
+++ b/module/VuFind/src/VuFind/ILS/Driver/Demo.php
@@ -195,13 +195,27 @@ class Demo extends AbstractBase
      */
     protected function getRandomBibId()
     {
-        $result = $this->searchService->random('Solr', new Query(''), 1);
+        $source = $this->getRecordSource();
+        $query = isset($this->config['Records']['query'])
+            ? $this->config['Records']['query'] : '*:*';
+        $result = $this->searchService->random($source, new Query($query), 1);
         if (count($result) === 0) {
-            throw new \Exception('Problem retrieving random record.');
+            throw new \Exception('Problem retrieving random record from $source.');
         }
         return current($result->getRecords())->getUniqueId();
     }
 
+    /**
+     * Get the name of the search backend providing records.
+     *
+     * @return string
+     */
+    protected function getRecordSource()
+    {
+        return isset($this->config['Records']['source'])
+            ? $this->config['Records']['source'] : 'Solr';
+    }
+
     /**
      * Generates a random, fake holding array
      *
@@ -297,6 +311,7 @@ class Demo extends AbstractBase
             } else {
                 if ($this->idsInMyResearch) {
                     $currentItem['id'] = $this->getRandomBibId();
+                    $currentItem['source'] = $this->getRecordSource();
                 } else {
                     $currentItem['title'] = 'Demo Title ' . $i;
                 }
@@ -635,6 +650,7 @@ class Demo extends AbstractBase
                 if (rand() % 3 != 1) {
                     if ($this->idsInMyResearch) {
                         $fineList[$i]['id'] = $this->getRandomBibId();
+                        $fineList[$i]['source'] = $this->getRecordSource();
                     } else {
                         $fineList[$i]['title'] = 'Demo Title ' . $i;
                     }
@@ -782,6 +798,7 @@ class Demo extends AbstractBase
                     );
                     if ($this->idsInMyResearch) {
                         $transList[$i]['id'] = $this->getRandomBibId();
+                        $transList[$i]['source'] = $this->getRecordSource();
                     } else {
                         $transList[$i]['title'] = 'Demo Title ' . $i;
                     }
diff --git a/themes/blueprint/templates/myresearch/fines.phtml b/themes/blueprint/templates/myresearch/fines.phtml
index 292ca8450e5..42d50c89c10 100644
--- a/themes/blueprint/templates/myresearch/fines.phtml
+++ b/themes/blueprint/templates/myresearch/fines.phtml
@@ -26,10 +26,10 @@
         <td>
           <? if (empty($record['title'])): ?>
             <?=$this->transEsc('not_applicable')?>
-          <? elseif (!isset($record['id'])): ?>
+          <? elseif (!is_object($record['driver'])): ?>
             <?=$this->escapeHtml(trim($record['title'], '/:'))?>
           <? else: ?>
-            <a href="<?=$this->url('record', array('id' => $record['id']))?>"><?=$this->escapeHtml(trim($record['title'], '/:'))?></a>
+            <a href="<?=$this->recordLink()->getUrl($record['driver'])?>"><?=$this->escapeHtml(trim($record['title'], '/:'))?></a>
           <? endif; ?>
         </td>
         <td><?=isset($record['checkout']) ? $this->escapeHtml($record['checkout']) : ''?></td>
diff --git a/themes/bootstrap3/templates/myresearch/fines.phtml b/themes/bootstrap3/templates/myresearch/fines.phtml
index abe05d2a4db..1499521e2a5 100644
--- a/themes/bootstrap3/templates/myresearch/fines.phtml
+++ b/themes/bootstrap3/templates/myresearch/fines.phtml
@@ -25,10 +25,10 @@
         <td>
           <? if (empty($record['title'])): ?>
             <?=$this->transEsc('not_applicable')?>
-          <? elseif (!isset($record['id'])): ?>
+          <? elseif (!is_object($record['driver'])): ?>
             <?=$this->escapeHtml(trim($record['title'], '/:'))?>
           <? else: ?>
-            <a href="<?=$this->url('record', array('id' => $record['id']))?>"><?=$this->escapeHtml(trim($record['title'], '/:'))?></a>
+            <a href="<?=$this->recordLink()->getUrl($record['driver'])?>"><?=$this->escapeHtml(trim($record['title'], '/:'))?></a>
           <? endif; ?>
         </td>
         <td><?=isset($record['checkout']) ? $this->escapeHtml($record['checkout']) : ''?></td>
diff --git a/themes/jquerymobile/templates/myresearch/fines.phtml b/themes/jquerymobile/templates/myresearch/fines.phtml
index 6fbb84c518a..fb4f7200a9f 100644
--- a/themes/jquerymobile/templates/myresearch/fines.phtml
+++ b/themes/jquerymobile/templates/myresearch/fines.phtml
@@ -12,8 +12,8 @@
       <ul class="results fines" data-role="listview">
         <? foreach ($this->fines as $record): ?>
           <li>
-            <? if ($showLink = (!empty($record['title']) && isset($record['id']))): ?>
-              <a rel="external" href="<?=$this->url('record', array('id' => $record['id']))?>">
+            <? if ($showLink = (!empty($record['title']) && is_object($record['driver']))): ?>
+              <a rel="external" href="<?=$this->recordLink()->getUrl($record['driver'])?>">
             <? endif; ?>
             <div class="result">
               <h3>
-- 
GitLab