diff --git a/module/fid/src/View/Helper/Root/Factory.php b/module/fid/src/View/Helper/Root/Factory.php index 1e9473f152c141a64e784495b0de29e0dd361c3d..89a4248bf602714bb621e068a5e185147f66e45c 100644 --- a/module/fid/src/View/Helper/Root/Factory.php +++ b/module/fid/src/View/Helper/Root/Factory.php @@ -27,6 +27,7 @@ */ namespace fid\View\Helper\Root; +use fid\Service\Client; use Interop\Container\ContainerInterface; /** @@ -55,4 +56,19 @@ class Factory $container->get('VuFind\Config')->get('fid') ); } + + /** + * Construct the Record helper. + * + * @param ContainerInterface $container Service manager. + * + * @return GetIt + */ + public static function getGetIt(ContainerInterface $container) + { + return new GetIt( + $container->get('VuFind\Config')->get('getit'), + $container->get(Client::class) + ); + } } diff --git a/module/fid/src/View/Helper/Root/GetIt.php b/module/fid/src/View/Helper/Root/GetIt.php new file mode 100644 index 0000000000000000000000000000000000000000..1811d51ee72c892ae3a89942c20bbcfbc688e437 --- /dev/null +++ b/module/fid/src/View/Helper/Root/GetIt.php @@ -0,0 +1,401 @@ +<?php +/** + * Get It box view helper + * + * PHP version 7 + * + * Copyright (C) Leipzig University Library 2019. + * + * 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 Gregor Gawol <gawol@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 fid\View\Helper\Root; + +use VuFind\I18n\Translator\TranslatorAwareTrait; +use VuFind\RecordDriver\AbstractBase; +use VuFind\View\Helper\Root\Config; +use Zend\View\Helper\AbstractHelper; + +/** + * Get It box view helper + * + * @category VuFind + * @package View_Helpers + * @author Gregor Gawol <gawol@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 GetIt extends AbstractHelper +{ + use TranslatorAwareTrait; + + /** + * @var \Zend\Config\Config + */ + protected $config; + + /** + * @var AbstractBase + */ + protected $driver; + + /** + * FID API Client + * + * @var \fid\Service\Client + */ + protected $fidClient; + protected $sid; + protected $format; + protected $facetAvail; + protected $multipart; + protected $institution; + protected $megacollection; + protected $collection; + protected $isbn; + protected $issn; + + /** + * GetIt constructor. + * + * @param Config $getItConfig Get It box Configuration + */ + public function __construct($getItConfig, $fidClient) + { + $this->config = $getItConfig; + $this->fidClient = $fidClient; + } + + /** + * @param $driver + */ + public function __invoke($driver) + { + $this->driver = $driver; + $this->sid = $this->driver->tryMethod('getSourceID'); + $this->format = $this->driver->tryMethod('getFormats'); + $this->facetAvail = $this->driver->tryMethod('getFacetAvail'); + $this->multipart = $this->driver->tryMethod('getMultiPart'); + $this->institution = $this->driver->tryMethod('getInstitutions'); + $this->megacollection = $this->driver->tryMethod('getMegaCollection'); + $this->collection = $this->driver->tryMethod('getCollection'); + $this->isbn = $this->driver->tryMethod('getISBNs'); + $this->issn = $this->driver->tryMethod('getISSNs'); + + return $this; + } + + /** + * @param $value + * + * @return array + */ + private function _getSourceIds($value) + { + $sids = $this->config->SourceIds; + return isset($sids->$value) ? explode(',', $sids->$value) : []; + } + + /** + * @param $value + * + * @return string + */ + private function _getNonSourceIds($value) + { + $sids = $this->config->NonSourceIds; + return isset($sids->$value) ? $sids->$value : ''; + } + + /** + * @param $defaultval + * @param $additionalval + * + * @return mixed + */ + private function _accordeon($defaultval, $additionalval) + { + if (in_array($this->sid, $this->_getSourceIds('source_idsV1'))) { + return $additionalval; + } elseif (in_array($this->sid, $this->_getSourceIds('source_idsV5'))) { + return $additionalval; + } elseif (in_array($this->sid, $this->_getSourceIds('source_idsV7'))) { + return $additionalval; + } elseif (in_array($this->sid, $this->_getSourceIds('source_idsV8'))) { + if (in_array('Free', $this->facetAvail)) { + return $additionalval; + } elseif (in_array('Online', $this->facetAvail) + && (preg_grep($this->_getNonSourceIds('source_idsV8_5'), $this->format) + || preg_grep($this->_getNonSourceIds('source_idsV8_6'), $this->format) + || preg_grep($this->_getNonSourceIds('source_idsV8_1'), $this->format)) + ) { + return $additionalval; + } + } elseif (in_array($this->sid, $this->_getSourceIds('source_idsV10'))) { + return $additionalval; + } + return $defaultval; + } + + /** + * @return string + */ + public function getAccordeonColor() + { + return $this->_accordeon('azure', 'amber'); + } + + /** + * @return mixed + */ + public function getAccordeonHeadline() + { + $links = $this->translate('getit_links'); + $infos = $this->translate('getit_infos'); + return $this->_accordeon($infos, $links); + } + + /** + * @return string + */ + public function getBoxHeadline() + { + if (in_array($this->sid, $this->_getSourceIds('source_idsV3'))) { + if (!$this->fidClient->isLoggedOn()) { + return $this->translate('getit_logged_not'); + } + } elseif (in_array($this->sid, $this->_getSourceIds('source_idsV4'))) { + if (!$this->fidClient->isLoggedOn()) { + return $this->translate('getit_logged_not'); + } + } elseif (in_array($this->sid, $this->_getSourceIds('source_idsV5'))) { + if (!$this->fidClient->isLoggedOn()) { + return $this->translate('getit_logged_not'); + } + } elseif (in_array($this->sid, $this->_getSourceIds('source_idsV8'))) { + $isLogin = false; + if (in_array('Local', $this->facetAvail) + && ((preg_grep($this->_getNonSourceIds('source_idsV8_1'), $this->format) + && !in_array($this->_getNonSourceIds('source_idsV8_1'), $this->institution)) + || preg_grep($this->_getNonSourceIds('source_idsV8_3'), $this->format) + ) + ) { + $isLogin = true; + } elseif (in_array('Online', $this->facetAvail) + && !in_array('Free', $this->facetAvail) + && (preg_grep($this->_getNonSourceIds('source_idsV8_1'), $this->format)) + ) { + $isLogin = true; + } + if (in_array($this->sid, $this->_getSourceIds('source_idsV9')) + && preg_grep($this->_getNonSourceIds('source_idsV8_8'), $this->format) + ) { + $isLogin = true; + } + if ($isLogin && !$this->fidClient->isLoggedOn()) { + return $this->translate('getit_logged_not'); + } + } + return $this->translate('Get it'); + } + + /** + * @return string + */ + public function getNotices() + { + if (in_array($this->sid, $this->_getSourceIds('source_idsV1'))) { + return $this->translate('getit_text_1'); + } elseif (in_array($this->sid, $this->_getSourceIds('source_idsV4'))) { + if (!$this->fidClient->isLoggedOn()) { + return $this->translate('getit_text_2'); + } else { + return $this->translate('getit_text_12'); + } + } elseif (in_array($this->sid, $this->_getSourceIds('source_idsV5'))) { + if (!$this->fidClient->isLoggedOn()) { + return $this->translate('getit_text_3_1'); + } else { + return $this->translate('getit_text_13'); + } + } elseif (in_array($this->sid, $this->_getSourceIds('source_idsV6'))) { + return $this->translate('getit_text_4'); + } elseif (in_array($this->sid, $this->_getSourceIds('source_idsV7'))) { + return $this->translate('getit_text_5'); + } elseif (in_array($this->sid, $this->_getSourceIds('source_idsV10'))) { + return $this->translate('getit_text_6'); + } elseif (in_array($this->sid, $this->_getSourceIds('source_idsV11'))) { + return $this->translate('getit_text_7'); + } elseif (in_array($this->sid, $this->_getSourceIds('source_idsV8'))) { + if (in_array($this->sid, $this->_getSourceIds('source_idsV9'))) { + if (preg_grep($this->_getNonSourceIds('source_idsV8_8'), $this->collection)) { + if (!$this->fidClient->isLoggedOn()) { + return $this->translate('getit_text_3_1'); + } else { + return $this->translate('getit_text_13'); + } + } + if (preg_grep($this->_getNonSourceIds('source_idsV8_4'), [$this->multipart])) { + return $this->translate('getit_text_11'); + } + if (preg_grep($this->_getNonSourceIds('source_idsV8_7'), $this->megacollection) + ) { + return $this->translate('getit_text_1'); + } + if (in_array('Local', $this->facetAvail) + && (preg_grep($this->_getNonSourceIds('source_idsV8_1'), $this->format) + || preg_grep($this->_getNonSourceIds('source_idsV8_3'), $this->format)) + ) { + if (!$this->fidClient->isLoggedOn()) { + return $this->translate('getit_text_10'); + } elseif (preg_grep($this->_getNonSourceIds('source_idsV8_3'), $this->format)) { + return $this->translate('getit_text_14'); + } else { + return ''; + } + } + if (in_array('Local', $this->facetAvail) + && preg_grep($this->_getNonSourceIds('source_idsV8_2'), $this->format) + ) { + return $this->translate('getit_text_8'); + } + if (in_array('Free', $this->facetAvail)) { + return $this->translate('getit_text_1'); + } + if (in_array('Online', $this->facetAvail) + && (preg_grep($this->_getNonSourceIds('source_idsV8_5'), $this->format) + || preg_grep($this->_getNonSourceIds('source_idsV8_6'), $this->format)) + ) { + return $this->translate('getit_text_9'); + } elseif (in_array('Online', $this->facetAvail) + && preg_grep($this->_getNonSourceIds('source_idsV8_1'), $this->format) + ) { + if (!$this->fidClient->isLoggedOn()) { + return $this->translate('getit_text_10'); + } else { + return $this->translate('getit_text_15'); + } + } + } elseif (preg_grep($this->_getNonSourceIds('source_idsV8_4'), [$this->multipart])) { + return $this->translate('getit_text_11'); + } elseif (in_array('Local', $this->facetAvail) + && preg_grep($this->_getNonSourceIds('source_idsV8_2'), $this->format) + ) { + return $this->translate('getit_text_8'); + } elseif (in_array('Local', $this->facetAvail)) { + if (!$this->fidClient->isLoggedOn()) { + return $this->translate('getit_text_10'); + } elseif (preg_grep($this->_getNonSourceIds('source_idsV8_3'), $this->format)) { + return $this->translate('getit_text_14'); + } + } elseif (in_array('Free', $this->facetAvail)) { + return $this->translate('getit_text_1'); + } elseif (in_array('Online', $this->facetAvail) + && (preg_grep($this->_getNonSourceIds('source_idsV8_5'), $this->format) + || preg_grep($this->_getNonSourceIds('source_idsV8_6'), $this->format)) + ) { + return $this->translate('getit_text_9'); + } elseif (in_array('Online', $this->facetAvail) + && preg_grep($this->_getNonSourceIds('source_idsV8_1'), $this->format) + ) { + if (!$this->fidClient->isLoggedOn()) { + return $this->translate('getit_text_10'); + } else { + return $this->translate('getit_text_15'); + } + } + } + return $this->translate('getit_text_default'); + } + + /** + * @return bool + */ + public function showLinks() + { + if (in_array($this->sid, $this->_getSourceIds('source_idsV5')) + || (in_array($this->sid, $this->_getSourceIds('source_idsV9')) + && preg_grep($this->_getNonSourceIds('source_idsV8_8'), $this->collection)) + ) { + if (!$this->fidClient->isLoggedOn()) { + return false; + } + } + return true; + } + + /** + * @return bool + */ + public function showOrderButton() + { + if (in_array($this->sid, $this->_getSourceIds('source_idsV9')) + && preg_grep($this->_getNonSourceIds('source_idsV8_1'), $this->format) + && !in_array($this->_getNonSourceIds('source_idsV8_9'), $this->institution) + && !preg_grep($this->_getNonSourceIds('source_idsV8_4'), [$this->multipart]) + && !preg_grep($this->_getNonSourceIds('source_idsV8_8'), $this->collection) + ) { + return true; + } + return false; + } + + /** + * @return bool + */ + public function showPartCopyButton() + { + if (!in_array('Free', $this->facetAvail) + && in_array($this->sid, $this->_getSourceIds('source_idsV9')) + && preg_grep($this->_getNonSourceIds('source_idsV8_1'), $this->format) + && !preg_grep($this->_getNonSourceIds('source_idsV8_4'), [$this->multipart]) + && !preg_grep($this->_getNonSourceIds('source_idsV8_8'), $this->collection) + ) { + return true; + } + return false; + } + + /** + * @return bool + */ + public function showBOSSData() + { + if (!in_array('Free', $this->facetAvail) + && in_array($this->sid, $this->_getSourceIds('source_idsV8')) + && (!empty($this->isbn) || !empty($this->issn)) + && !preg_grep($this->_getNonSourceIds('source_idsV8_8'), $this->collection) + ) { + if (in_array($this->sid, $this->_getSourceIds('source_idsV9')) + && preg_grep($this->_getNonSourceIds('source_idsV8_1'), $this->format) + ) { + return true; + } elseif (in_array('Local', $this->facetAvail) + && preg_grep($this->_getNonSourceIds('source_idsV8_3'), $this->format) + ) { + return true; + } elseif (in_array('Online', $this->facetAvail) + && preg_grep($this->_getNonSourceIds('source_idsV8_1'), $this->format) + ) { + return true; + } + } + return false; + } +} diff --git a/module/finc/src/finc/RecordDriver/SolrDefaultFincTrait.php b/module/finc/src/finc/RecordDriver/SolrDefaultFincTrait.php index 4c7a60fe0bd03061cf04511064904a2a115e337c..f45939e407020e81ebf8f4987c02ef7cd83b9001 100644 --- a/module/finc/src/finc/RecordDriver/SolrDefaultFincTrait.php +++ b/module/finc/src/finc/RecordDriver/SolrDefaultFincTrait.php @@ -449,6 +449,17 @@ trait SolrDefaultFincTrait return isset($this->fields['mega_collection']) ? $this->fields['mega_collection'] : []; } + /** + * Get an array of all collections in the record. + * + * @return array + * @access public + */ + public function getCollection() + { + return isset($this->fields['collection']) ? $this->fields['collection'] : []; + } + /** * Get the content of field multipart_set. * diff --git a/module/finc/src/finc/RecordDriver/SolrMarcFincTrait.php b/module/finc/src/finc/RecordDriver/SolrMarcFincTrait.php index bfbdb9ed07194976ff66f9e6ac38b9c7cc2bc735..0a92b49c68f4704afd28733e1a8eb3bfd7d579d7 100644 --- a/module/finc/src/finc/RecordDriver/SolrMarcFincTrait.php +++ b/module/finc/src/finc/RecordDriver/SolrMarcFincTrait.php @@ -2274,4 +2274,27 @@ trait SolrMarcFincTrait return $retval; } + + /** + * Get the delivery status of the record. + * + * @return string + * @access public + */ + public function getDeliveryStatus() + { + $retVal = []; + $statuses = $this->getMarcRecord()->getFields('366'); + + if(!is_null($statuses)) { + foreach ($statuses as $status) { + $value = $status->getSubfield('e'); + if($value) { + // is subfield u exists + $retVal[] = $value->getData(); + } + } + } + return implode(', ', array_unique($retVal)); + } } diff --git a/themes/fid/theme.config.php b/themes/fid/theme.config.php index 9287fac95d9c6235650fd6914cf64d0ccd816c23..c796f8532d90bd9c52cf90744dc362fa94063dba 100644 --- a/themes/fid/theme.config.php +++ b/themes/fid/theme.config.php @@ -16,6 +16,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * @author Sebastian Kehr <kehr@ub.uni-leipzig.de> + * @author Dorian Merz <merz@ub.uni-leipzig.de> + * @author Gregor Gawol <gawol@ub.uni-leipzig.de> * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 */ @@ -25,11 +27,15 @@ return [ 'factories' => array( 'fid\View\Helper\Root\UserGroups' => 'fid\View\Helper\Root\Factory::getUserGroups', + 'fid\View\Helper\Root\GetIt' => + 'fid\View\Helper\Root\Factory::getGetIt', 'fid\Helper\SearchTabs' => 'VuFind\View\Helper\Root\SearchTabsFactory', ), 'aliases' => array( 'usergroups' => 'UserGroups', 'UserGroups' => 'fid\View\Helper\Root\UserGroups', + 'getit' => 'fid\View\Helper\Root\GetIt', + 'GetIt' => 'fid\View\Helper\Root\GetIt', 'searchTabs' => 'fid\Helper\SearchTabs', ) ),