Skip to content
Snippets Groups Projects
Commit bd252507 authored by Ere Maijala's avatar Ere Maijala Committed by Robert Lange
Browse files

Fix Alma driver crash when an expected MARC subfield doesn't exist. (#1447)

parent a1ecb51b
No related merge requests found
......@@ -1616,25 +1616,24 @@ class Alma extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterface
// Physical
$physicalItems = $record->getFields('AVA');
foreach ($physicalItems as $field) {
$avail = $field->getSubfield('e')->getData();
$avail = $this->getMarcSubfield($field, 'e');
$item = $tmpl;
$item['availability'] = strtolower($avail) === 'available';
$item['location'] = (string)$field->getSubfield('c')
->getData();
$item['location'] = $this->getMarcSubfield($field, 'c');
$status[] = $item;
}
// Electronic
$electronicItems = $record->getFields('AVE');
foreach ($electronicItems as $field) {
$avail = $field->getSubfield('e')->getData();
$avail = $this->getMarcSubfield($field, 'e');
$item = $tmpl;
$item['availability'] = strtolower($avail) === 'available';
$item['location'] = $field->getSubfield('m')->getData();
$url = $field->getSubfield('u')->getData();
$item['location'] = $this->getMarcSubfield($field, 'm');
$url = $this->getMarcSubfield($field, 'u');
if (preg_match('/^https?:\/\//', $url)) {
$item['locationhref'] = $url;
}
$item['status'] = $field->getSubfield('s')->getData();
$item['status'] = $this->getMarcSubfield($field, 's');
$status[] = $item;
}
// Digital
......@@ -1652,11 +1651,11 @@ class Alma extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterface
$item = $tmpl;
unset($item['callnumber']);
$item['availability'] = true;
$item['location'] = $field->getSubfield('e')->getData();
$item['location'] = $this->getMarcSubfield($field, 'e');
if ($deliveryUrl) {
$item['locationhref'] = str_replace(
'%%id%%',
$field->getSubfield('b')->getData(),
$this->getMarcSubfield($field, 'b'),
$deliveryUrl
);
}
......@@ -1693,6 +1692,20 @@ class Alma extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterface
return null;
}
/**
* Get a MARC subfield from a MARC field
*
* @param \File_MARC_Subfield $field MARC Field
* @param string $subfield Subfield code
*
* @return string
*/
protected function getMarcSubfield($field, $subfield)
{
$subfield = $field->getSubfield($subfield);
return false === $subfield ? '' : $subfield->getData();
}
// @codingStandardsIgnoreStart
/**
......
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