From e3d44437ac899592ef2769ce732f467f9f2ee5a7 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 16 Nov 2012 10:10:54 -0500
Subject: [PATCH] Suppress Solr-based next/prev titles when MARC-based data is
 available; fixed fatal error caused by missing title in 7xx linking fields.

---
 .../src/VuFind/RecordDriver/SolrMarc.php      | 40 +++++++++++++++----
 1 file changed, 33 insertions(+), 7 deletions(-)

diff --git a/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php b/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php
index ca4d96cf03e..b0414d434e7 100644
--- a/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php
+++ b/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php
@@ -280,6 +280,20 @@ class SolrMarc extends SolrDefault
         return $this->getFieldArray('500');
     }
 
+    /**
+     * Get an array of newer titles for the record.
+     *
+     * @return array
+     */
+    public function getNewerTitles()
+    {
+        // If the MARC links are being used, return blank array
+        $config = ConfigReader::getConfig();
+        $fieldsNames = isset($config->Record->marc_links)
+            ? array_map('trim', explode(',', $config->Record->marc_links)) : array();
+        return in_array('785', $fieldsNames) ? array() : parent::getNewerTitles();
+    }
+
     /**
      * Get the item's places of publication.
      *
@@ -309,6 +323,20 @@ class SolrMarc extends SolrDefault
         return $times;
     }
 
+    /**
+     * Get an array of previous titles for the record.
+     *
+     * @return array
+     */
+    public function getPreviousTitles()
+    {
+        // If the MARC links are being used, return blank array
+        $config = ConfigReader::getConfig();
+        $fieldsNames = isset($config->Record->marc_links)
+            ? array_map('trim', explode(',', $config->Record->marc_links)) : array();
+        return in_array('780', $fieldsNames) ? array() : parent::getPreviousTitles();
+    }
+
     /**
      * Get credits of people involved in production of the item.
      *
@@ -664,8 +692,6 @@ class SolrMarc extends SolrDefault
      */
     protected function getFieldData($field, $value)
     {
-        $labelPrfx   = 'note_';
-
         // There are two possible ways we may want to link to a record -- either
         // we will have a raw bibliographic record in subfield w, or else we will
         // have an OCLC number prefixed by (OCoLC).  If we have both, we want to
@@ -697,11 +723,11 @@ class SolrMarc extends SolrDefault
             return false;
         }
 
-        return array(
-            'title' => $labelPrfx.$value,
-            'value' => $field->getSubfield('t')->getData(),
-            'link'  => $link
-        );
+        $titleField = $field->getSubfield('t');
+        $title = $titleField ? $titleField->getData() : false;
+        return $title
+            ? array('title' => 'note_' . $value, 'value' => $title, 'link'  => $link)
+            : false;
     }
 
     /**
-- 
GitLab