From 1edea4d23de5858c6a108eaf21dc3352c9c7933e Mon Sep 17 00:00:00 2001 From: Dorian Merz <merz@ub.uni-leipzig.de> Date: Wed, 26 Jun 2019 13:42:00 +0200 Subject: [PATCH] refs #15205 [master-v5] getPublicationDetails in MARC Record Driver * avoids usage of imprint field for MARC records * reads MARC $264 with ind2 = 1 and $260 * obeys multi-fields and multi-subfields --- .../finc/RecordDriver/SolrMarcFincTrait.php | 55 +++++++++++++++++++ .../SolrDefault/data-publicationDetails.phtml | 32 ----------- 2 files changed, 55 insertions(+), 32 deletions(-) delete mode 100644 themes/finc/templates/RecordDriver/SolrDefault/data-publicationDetails.phtml diff --git a/module/finc/src/finc/RecordDriver/SolrMarcFincTrait.php b/module/finc/src/finc/RecordDriver/SolrMarcFincTrait.php index 8685085072f..de44b307092 100644 --- a/module/finc/src/finc/RecordDriver/SolrMarcFincTrait.php +++ b/module/finc/src/finc/RecordDriver/SolrMarcFincTrait.php @@ -2211,4 +2211,59 @@ trait SolrMarcFincTrait } return $retval; } + + /** + * + */ + public function getPublicationDetails() { + + $places = + $names = + $dates = []; + foreach (array('260','264') as $pos => $field_name) { + if ($fields = $this->getMarcRecord()->getFields($field_name)) { + foreach ($fields as $field) { + // for MARC $264 if indicator2 equals 1 we have publication details + // others are irrelevant + if ($pos === '264' && $field->getIndicator('2') !== '1') { + continue; + } + foreach (array( + 'places' => 'a', + 'names' => 'b', + 'dates' => 'c' + ) as $key => $sub_name) { + if ($lines = $field->getSubfields($sub_name)) { + ${$key}[] = implode( + ', ', + array_map( + function ($elem) { + return $elem->getData(); + }, + $lines + ) + ); + } else { + ${$key}[] = ''; + } + } + } + } + } + + $i = 0; + $retval = []; + while (isset($places[$i]) || isset($names[$i]) || isset($dates[$i])) { + // Build objects to represent each set of data; these will + // transform seamlessly into strings in the view layer. + $retval[] = new \VuFind\RecordDriver\Response\PublicationDetails( + $places[$i] ?? '', + $names[$i] ?? '', + $dates[$i] ?? '' + ); + $i++; + } + + return $retval; + } } diff --git a/themes/finc/templates/RecordDriver/SolrDefault/data-publicationDetails.phtml b/themes/finc/templates/RecordDriver/SolrDefault/data-publicationDetails.phtml deleted file mode 100644 index df299e1e5b9..00000000000 --- a/themes/finc/templates/RecordDriver/SolrDefault/data-publicationDetails.phtml +++ /dev/null @@ -1,32 +0,0 @@ -<!-- finc: RecordDriver - solrDefault - data-publicationDetails --> -<? if (!empty($data)): ?> - <div itemscope itemtype="http://schema.org/publisher"> - <? if (is_array($data) && !empty($data[0]) && $data[0] instanceof \VuFind\RecordDriver\Response\PublicationDetails): ?> - <? foreach ($data as $field): ?> - <span property="publisher" typeof="Organization"> - <? $pubPlace = $field->getPlace(); if (!empty($pubPlace)): ?> - <span property="location" typeof="Place"> - <span property="name"><?=$this->escapeHtml($pubPlace)?></span> - </span> - <? endif; ?> - <? $pubName = $field->getName(); if (!empty($pubName)): ?> - <span property="name"><?=$this->escapeHtml($pubName)?></span> - <? endif; ?> - </span> - <span property="datePublished"> - - <? $pubDate = $field->getDate(); if (!empty($pubDate)): ?> - <?=$this->escapeHtml($pubDate)?> - <? endif; ?> - </span> - <? endforeach; ?> - <? else: ?> - <? if (is_array($data)): ?> - <?= implode('<br/>', array_map(array($this, 'escapeHtml'), $data)) ?> - <? else: ?> - <?= $this->escapeHtml($data) ?> - <? endif; ?> - <? endif ?> - </div> -<? endif ?> -<!-- finc: RecordDriver - solrDefault - data-publicationDetails - END --> -- GitLab