Skip to content
Snippets Groups Projects
Commit 87982c21 authored by Demian Katz's avatar Demian Katz
Browse files

Fixed bug: MARC linking fields mislabeled when repeating

- Resolves VUFIND-1034.
- Incorporates some code simplification/refactoring.
parent 3e239844
No related merge requests found
...@@ -772,56 +772,67 @@ class SolrMarc extends SolrDefault ...@@ -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 // Get data for field
$tmp = $this->getFieldData($field, $value); $tmp = $this->getFieldData($field);
if (is_array($tmp)) { if (is_array($tmp)) {
$retVal[] = $tmp; $retVal[] = $tmp;
} }
} }
} }
} }
if (empty($retVal)) { return empty($retVal) ? null : $retVal;
$retVal = null; }
/**
* 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 * Returns the array element for the 'getAllRecordLinks' method
* *
* @param File_MARC_Data_Field $field Field to examine * @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 * @return array|bool Array on success, boolean false if no
* valid link could be found in the data. * 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: // Make sure that there is a t field to be displayed:
if ($title = $field->getSubfield('t')) { if ($title = $field->getSubfield('t')) {
$title = $title->getData(); $title = $title->getData();
} else { } else {
return; return false;
} }
$linkTypeSetting = isset($this->mainConfig->Record->marc_links_link_types) $linkTypeSetting = isset($this->mainConfig->Record->marc_links_link_types)
...@@ -883,9 +894,11 @@ class SolrMarc extends SolrDefault ...@@ -883,9 +894,11 @@ class SolrMarc extends SolrDefault
} }
} }
// Make sure we have something to display: // Make sure we have something to display:
return isset($link) return !isset($link) ? false : array(
? array('title' => 'note_' . $value, 'value' => $title, 'link' => $link) 'title' => $this->getRecordLinkNote($field),
: false; 'value' => $title,
'link' => $link
);
} }
/** /**
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment