diff --git a/module/finc/config/module.config.php b/module/finc/config/module.config.php index b2f39e304cdf7b8452a8434d147891356501df92..7673bcd88c9a4de514c7e6cf031600f08fd18083 100644 --- a/module/finc/config/module.config.php +++ b/module/finc/config/module.config.php @@ -164,6 +164,7 @@ $config = [ ], 'finc\RecordDriver\SolrMarcFinc' => [ 'VuFind\RecordDriver\IlsAwareDelegatorFactory', + 'finc\RecordDriver\SolrMarcUrlRulesDelegatorFactory', ], 'finc\RecordDriver\SolrMarcFincPDA' => [ 'VuFind\RecordDriver\IlsAwareDelegatorFactory', diff --git a/module/finc/src/finc/RecordDriver/SolrMarcFincTrait.php b/module/finc/src/finc/RecordDriver/SolrMarcFincTrait.php index ae6c2586b453676144e410bf3adcadbd7e54326f..c17bd5e99f6029bf368c46cdf01dccda9e2e53d8 100644 --- a/module/finc/src/finc/RecordDriver/SolrMarcFincTrait.php +++ b/module/finc/src/finc/RecordDriver/SolrMarcFincTrait.php @@ -67,6 +67,39 @@ trait SolrMarcFincTrait return $this->getFirstFieldValue('040', ['e']) == 'rda'; } + /** + * Helper function for getURLs() + * Decides which sub results from getURLs to choose. + * Standard version takes + * instance-specific URLs if present or choses LEFER over default otherwise + * + * @param array $resultsPerIsil + * @return mixed|null + */ + protected function extractUrls(array $resultsPerIsil) + { + $subresult = null; + // if we have a local entry for the current instance (i.e. ISIL) + // use that one + foreach ($this->isil as $isil) { + if (isset($resultsPerIsil[$isil])) { + $subresult = $resultsPerIsil[$isil]; + break; + } + } + // LFER ("Lizenzfreie elektronische Ressourcen", + // "license free electronic resources") may have a designated entry, + // if there is no instance specific url try the one for LFER + if (empty($subresult) && isset($resultsPerIsil['LFER'])) { + $subresult = $resultsPerIsil['LFER']; + } + // if we still have no URL, look for the unspecific entry + if (empty($subresult) && isset($resultsPerIsil['default'])) { + $subresult = $resultsPerIsil['default']; + } + return $subresult; + } + /** * Return an array of associative URL arrays with one or more of the following * keys: @@ -154,25 +187,8 @@ trait SolrMarcFincTrait } } } - $subresult = null; - // if we have a local entry for the current instance (i.e. ISIL) - // use that one - foreach ($this->isil as $isil) { - if (isset($resultsPerIsil[$isil])) { - $subresult = $resultsPerIsil[$isil]; - break; - } - } - // LFER ("Lizenzfreie elektronische Ressourcen", - // "license free electronic resources") may have a designated entry, - // if there is no instance specific url try the one for LFER - if (empty($subresult) && isset($resultsPerIsil['LFER'])) { - $subresult = $resultsPerIsil['LFER']; - } - // if we still have no URL, look for the unspecific entry - if (empty($subresult) && isset($resultsPerIsil['default'])) { - $subresult = $resultsPerIsil['default']; - } + + $subresult = $this->extractUrls($resultsPerIsil); if (!empty($subresult)) { foreach ($subresult as $current) { diff --git a/module/finc/src/finc/RecordDriver/SolrMarcUrlRulesDelegatorFactory.php b/module/finc/src/finc/RecordDriver/SolrMarcUrlRulesDelegatorFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..7160540c640834bc211dcb014672dc24b6bbc2d2 --- /dev/null +++ b/module/finc/src/finc/RecordDriver/SolrMarcUrlRulesDelegatorFactory.php @@ -0,0 +1,72 @@ +<?php +/** + * Delegator Factory for SolrMarc record drivers. Enables specialized rules + * for \finc\RecordDriver\SolrMarcFincTrait::getURLs + * + * PHP version 7 + * + * Copyright (C) Villanova University 2021. + * + * 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 RecordDrivers + * @author Dorian Merz <mer@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\RecordDriver; + +use Interop\Container\ContainerInterface; + +/** + * Delegator Factory for SolrMarc record drivers. Enables specialized rules + * for \finc\RecordDriver\SolrMarcFincTrait::getURLs + * + * @category VuFind + * @package RecordDrivers + * @author Dorian Merz <mer@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +class SolrMarcUrlRulesDelegatorFactory +{ + /** + * Creates a delegator of VuFind/Search to register several listeners. + * + * @param ContainerInterface $container + * @param string $name + * @param callable $callback + * @param array|null $options + * + * @return mixed + */ + public function __invoke( + ContainerInterface $container, + $name, + callable $callback, + array $options = null + ) { + $instance = call_user_func($callback); + + $urlRules = $container->get('VuFind\YamlReader')->get('SolrMarcUrlRules.yaml'); + if (!empty($urlRules)) { + if (isset($urlRules['rules']) && isset($urlRules['stopFlags'])) { + $instance->urlRules = $urlRules; + } + } + + return $instance; + } +}