From 87982c21eb7f5f5b3cb89016d076c2c8a2a63f52 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Wed, 8 Oct 2014 11:12:32 -0400 Subject: [PATCH] Fixed bug: MARC linking fields mislabeled when repeating - Resolves VUFIND-1034. - Incorporates some code simplification/refactoring. --- .../src/VuFind/RecordDriver/SolrMarc.php | 73 +++++++++++-------- 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php b/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php index 4d8b18c7f43..c32d1e52710 100644 --- a/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php +++ b/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php @@ -772,56 +772,67 @@ class SolrMarc extends SolrDefault } } - // Normalize blank relationship indicator to 0: - $relationshipIndicator = $field->getIndicator('2'); - if ($relationshipIndicator == ' ') { - $relationshipIndicator = '0'; - } - - // Assign notes based on the relationship type - switch ($value) { - case '780': - if (in_array($relationshipIndicator, range('0', '7'))) { - $value .= '_' . $relationshipIndicator; - } - break; - case '785': - if (in_array($relationshipIndicator, range('0', '8'))) { - $value .= '_' . $relationshipIndicator; - } - break; - } - // Get data for field - $tmp = $this->getFieldData($field, $value); + $tmp = $this->getFieldData($field); if (is_array($tmp)) { $retVal[] = $tmp; } } } } - if (empty($retVal)) { - $retVal = null; + return empty($retVal) ? null : $retVal; + } + + /** + * Support method for getFieldData() -- factor the relationship indicator + * into the field number where relevant to generate a note to associate + * with a record link. + * + * @param File_MARC_Data_Field $field Field to examine + * + * @return string + */ + protected function getRecordLinkNote($field) + { + // Normalize blank relationship indicator to 0: + $relationshipIndicator = $field->getIndicator('2'); + if ($relationshipIndicator == ' ') { + $relationshipIndicator = '0'; + } + + // Assign notes based on the relationship type + $value = $field->getTag(); + switch ($value) { + case '780': + if (in_array($relationshipIndicator, range('0', '7'))) { + $value .= '_' . $relationshipIndicator; + } + break; + case '785': + if (in_array($relationshipIndicator, range('0', '8'))) { + $value .= '_' . $relationshipIndicator; + } + break; } - return $retVal; + + return 'note_' . $value; } /** * Returns the array element for the 'getAllRecordLinks' method * * @param File_MARC_Data_Field $field Field to examine - * @param string $value Field name for use in label * * @return array|bool Array on success, boolean false if no * valid link could be found in the data. */ - protected function getFieldData($field, $value) + protected function getFieldData($field) { // Make sure that there is a t field to be displayed: if ($title = $field->getSubfield('t')) { $title = $title->getData(); } else { - return; + return false; } $linkTypeSetting = isset($this->mainConfig->Record->marc_links_link_types) @@ -883,9 +894,11 @@ class SolrMarc extends SolrDefault } } // Make sure we have something to display: - return isset($link) - ? array('title' => 'note_' . $value, 'value' => $title, 'link' => $link) - : false; + return !isset($link) ? false : array( + 'title' => $this->getRecordLinkNote($field), + 'value' => $title, + 'link' => $link + ); } /** -- GitLab