From 3233bf9ddecd55abb942559629b32e78fa1c1f4a Mon Sep 17 00:00:00 2001 From: Dorian Merz <merz@ub.uni-leipzig.de> Date: Tue, 14 Jul 2020 13:43:35 +0200 Subject: [PATCH] refs #17943 [master] use MultiLine templating in RecordDataFormatter * reverts #13902 * adds MultiDataFieldsTrait to offer some multiline functions * adapts relevant templates --- .../View/Helper/Root/MultiDataFieldsTrait.php | 161 ++++++++++++++++++ .../DefaultRecord/data-additionals.phtml | 23 +-- .../data-otherRelationshipEntry.phtml | 21 +-- .../DefaultRecord/data-titleUniform.phtml | 33 ++-- .../RecordDriver/SolrLido/data-events.phtml | 20 +-- 5 files changed, 191 insertions(+), 67 deletions(-) create mode 100644 module/finc/src/finc/View/Helper/Root/MultiDataFieldsTrait.php diff --git a/module/finc/src/finc/View/Helper/Root/MultiDataFieldsTrait.php b/module/finc/src/finc/View/Helper/Root/MultiDataFieldsTrait.php new file mode 100644 index 00000000000..6c8b3ec0f5e --- /dev/null +++ b/module/finc/src/finc/View/Helper/Root/MultiDataFieldsTrait.php @@ -0,0 +1,161 @@ +<?php +/** + * multi data view helper callback functions + * + * PHP version 7 + * + * Copyright (C) Leipzig University Library, 2020. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category VuFind + * @package View_Helpers + * @author Dorian Merz <merz@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +namespace finc\View\Helper\Root; + +/** + * multi data view helper callback functions + * + * @category VuFind + * @package View_Helpers + * @author Dorian Merz <merz@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +trait MultiDataFieldsTrait +{ + /** + * return render details for additionals data set + * @return callback + */ + public function additionals($data, $options) + { + // Sort the data: + $final = []; + foreach ($data as $type => $values) { + $final[] = [ + 'label' => $values['identifier'], + 'values' => [$type => $values], + 'options' => [ + 'pos' => $options['pos'], + 'renderType' => 'RecordDriverTemplate', + 'template' => 'data-additionals.phtml', + ], + ]; + } + return $final; + } + + /** + * return render details for otherRelationshipEntry data set + * @return callback + */ + public function otherRelationShipEntry($data, $options) + { + // Sort the data: + $final = []; + foreach ($data as $type => $values) { + $final[] = [ + 'label' => $values[0]['subject'], + 'values' => [$type => $values], + 'options' => [ + 'pos' => $options['pos'], + 'renderType' => 'RecordDriverTemplate', + 'template' => 'data-otherRelationshipEntry.phtml', + ], + ]; + } + return $final; + } + + /** + * return render details for titleUniform data set + * @return callback + */ + public function titleUniform($data, $options, $driver) + { + // Sort the data: + $final = []; + foreach ($data as $type => $values) { + $final[] = [ + 'label' => $driver->tryMethod('isRDA') + ? 'rda_original_title' + : 'non_rda_original_title', + 'values' => [$type => $values], + 'options' => [ + 'pos' => $options['pos'], + 'renderType' => 'RecordDriverTemplate', + 'template' => 'data-titleUniform.phtml', + ], + ]; + } + return $final; + } + + /** + * return render details for events data set + * @return callback + */ + public function events($data, $options) + { + // Sort the data: + $final = []; + foreach ($data as $eventType => $values) { + switch ($eventType) { + case 'production': $title = 'expression creation'; break; + case 'publication': $title = 'Time of origin'; break; + default: $title = $eventType; + } + $final[] = [ + 'label' => $title, + 'values' => [$eventType => $values], + 'options' => [ + 'pos' => $options['pos'], + 'renderType' => 'RecordDriverTemplate', + 'template' => 'data-events.phtml', + ], + ]; + } + return $final; + } + + + /** + * return render details for titleUniform data set + * @return callback + */ + public function isbnIssns($data, $options, $driver) + { + // Sort the data: + $final = []; + foreach ($data as $type => $values) { + $final[] = [ + 'label' => $driver->tryMethod('isRDA') + ? 'rda_original_title' + : 'non_rda_original_title', + 'values' => [$type => $values], + 'options' => [ + 'pos' => $options['pos'], + 'renderType' => 'RecordDriverTemplate', + 'template' => 'data-titleUniform.phtml', + ], + ]; + } + return $final; + } + +} diff --git a/themes/finc/templates/RecordDriver/DefaultRecord/data-additionals.phtml b/themes/finc/templates/RecordDriver/DefaultRecord/data-additionals.phtml index fbb7def9e17..7ee1dc4a8e2 100644 --- a/themes/finc/templates/RecordDriver/DefaultRecord/data-additionals.phtml +++ b/themes/finc/templates/RecordDriver/DefaultRecord/data-additionals.phtml @@ -2,23 +2,16 @@ <?php if (!empty($data) && is_array($data)): ?> <?php foreach ($data as $additional) : ?> <?php if (isset($additional['identifier'])): ?> - <tr> - <th> - <?=$this->transEsc($additional['identifier'])?>: - </th> - <td> - <?php if(isset($additional['id']) && $url = $this->recordLink()->getRecordLink($additional['id'],'id')): ?> - <?php if (isset($additional['label']) && !empty($additional['label'])): ?> - <a href="<?=$url?>"><?=$this->escapeHtml($additional['label'])?></a><?=$this->escapeHtml($additional['suffix'])?> - <?php else: ?> - <a href="<?=$url?>"><?=$this->escapeHtml($additional['text'])?></a> - <?php endif; ?> - <?php unset($url) ?> + <?php if(isset($additional['id']) && $url = $this->recordLink()->getRecordLink($additional['id'],'id')): ?> + <?php if (isset($additional['label']) && !empty($additional['label'])): ?> + <a href="<?=$url?>"><?=$this->escapeHtml($additional['label'])?></a><?=$this->escapeHtml($additional['suffix'])?> <?php else: ?> - <?=$this->escapeHtml($additional['text'])?> + <a href="<?=$url?>"><?=$this->escapeHtml($additional['text'])?></a> <?php endif; ?> - </td> - </tr> + <?php unset($url) ?> + <?php else: ?> + <?=$this->escapeHtml($additional['text'])?> + <?php endif; ?> <?php endif; ?> <?php endforeach; ?> <?php endif; ?> diff --git a/themes/finc/templates/RecordDriver/DefaultRecord/data-otherRelationshipEntry.phtml b/themes/finc/templates/RecordDriver/DefaultRecord/data-otherRelationshipEntry.phtml index e57ce111e50..7ec5de28450 100644 --- a/themes/finc/templates/RecordDriver/DefaultRecord/data-otherRelationshipEntry.phtml +++ b/themes/finc/templates/RecordDriver/DefaultRecord/data-otherRelationshipEntry.phtml @@ -1,19 +1,14 @@ <!-- finc: RecordDriver - DefaultRecord - data-otherRelationshipEntry --> <?php if (!empty($data)): ?> <?php foreach ($data as $subject => $values): ?> - <tr> - <th><?=$this->transEsc($values[0]['subject'])?>: </th> - <td> - <?php foreach ($values as $v): ?> - <?php if (isset($v['id'])): ?> - <a href="<?=$this->recordLink()->getUrl($v['id'])?>"><?=$this->escapeHtml($v['text'])?></a> - <?php else: ?> - <?=$this->escapeHtml($v['text'])?> - <?php endif; ?> - <br/> - <?php endforeach; ?> - </td> - </tr> + <?php foreach ($values as $v): ?> + <?php if (isset($v['id'])): ?> + <a href="<?=$this->recordLink()->getUrl($v['id'])?>"><?=$this->escapeHtml($v['text'])?></a> + <?php else: ?> + <?=$this->escapeHtml($v['text'])?> + <?php endif; ?> + <br/> + <?php endforeach; ?> <?php endforeach; ?> <?php endif; ?> <!-- finc: RecordDriver - DefaultRecord - data-otherRelationshipEntry - END --> diff --git a/themes/finc/templates/RecordDriver/DefaultRecord/data-titleUniform.phtml b/themes/finc/templates/RecordDriver/DefaultRecord/data-titleUniform.phtml index 237b057941b..65f1c152091 100644 --- a/themes/finc/templates/RecordDriver/DefaultRecord/data-titleUniform.phtml +++ b/themes/finc/templates/RecordDriver/DefaultRecord/data-titleUniform.phtml @@ -1,25 +1,16 @@ <!-- finc: RecordDriver - DefaultRecord - data-titleUniform --> <?php if (!empty($data)): ?> - <tr> - <th> - <?=$this->driver->isRDA() - ? $this->transEsc('rda_original_title') - : $this->transEsc('non_rda_original_title')?>: - </th> - <td property="title"> - <?php if (is_array($data)): ?> - <?php if ($data['titleUniform']): ?> - <a href="<?= $this->record($this->driver)->getLink('titleUniform', $data['titleUniform']) ?>"> - <?php endif; ?> - <?= $this->escapeHtml($data['title']) ?> - <?php if ($data['titleUniform']): ?> - </a> - <?php endif; ?> - <?php if (isset($data['lang'])): ?> ⟨<?= $this->escapeHtml($data['lang']) ?>⟩<?php endif; ?> - <?php else: ?> - <a href="<?=$this->record($this->driver)->getLink('title', $data)?>"><?=$this->escapeHtml($data)?></a> - <?php endif; ?> - </td> - </tr> + <?php if (is_array($data)): ?> + <?php if ($data['titleUniform']): ?> + <a href="<?= $this->record($this->driver)->getLink('titleUniform', $data['titleUniform']) ?>"> + <?php endif; ?> + <?= $this->escapeHtml($data['title']) ?> + <?php if ($data['titleUniform']): ?> + </a> + <?php endif; ?> + <?php if (isset($data['lang'])): ?> ⟨<?= $this->escapeHtml($data['lang']) ?>⟩<?php endif; ?> + <?php else: ?> + <a href="<?=$this->record($this->driver)->getLink('title', $data)?>"><?=$this->escapeHtml($data)?></a> + <?php endif; ?> <?php endif; ?> <!-- finc: RecordDriver - DefaultRecord - data-titleUniform - END --> diff --git a/themes/finc/templates/RecordDriver/SolrLido/data-events.phtml b/themes/finc/templates/RecordDriver/SolrLido/data-events.phtml index 8030e6f371c..504ed249498 100644 --- a/themes/finc/templates/RecordDriver/SolrLido/data-events.phtml +++ b/themes/finc/templates/RecordDriver/SolrLido/data-events.phtml @@ -1,18 +1,5 @@ -<?php $publicationIsSet = false; ?> -<?php if (count($event = $this->driver->getEvents()) > 0): ?> - <?php foreach ($event as $eventType => $events): ?> - <tr class="recordEvents"> - <th> - <?php if ($eventType == 'production'): ?> - <?=$this->transEsc('expression creation')?>: - <?php elseif ($eventType == 'publication'): ?> - <?=$this->transEsc('Time of origin')?>: - <?php $publicationIsSet = true; ?> - <?php else: ?> - <?=$this->transEsc($eventType)?>: - <?php endif; ?> - </th> - <td> + <?php foreach ($data as $eventType => $events): ?> + <?php $publicationIsSet = $eventType === 'Publication'; ?> <div class="truncate-field"> <?php foreach ($events as $event): ?> <?php if ($event != $events[0]): ?><br/><?php endif; ?> @@ -36,7 +23,4 @@ <?php if (!empty($event['description'])): ?><?=$this->escapeHtml($event['description'])?><br/><?php endif; ?> <?php endforeach; ?> </div> - </td> - </tr> <?php endforeach; ?> -<?php endif; ?> -- GitLab