From bf00c646b1608430f556e6154d3ef32b93347be4 Mon Sep 17 00:00:00 2001 From: Dorian Merz <merz@ub.uni-leipzig.de> Date: Mon, 13 Jan 2020 11:11:27 +0100 Subject: [PATCH] refs #16630 [fid] refactor GetIt logic * re-structures logics * partitions into distinct source id packages * returns full config set for each --- module/fid/src/View/Helper/Root/GetIt.php | 447 +++++++++++++++++++++- 1 file changed, 446 insertions(+), 1 deletion(-) diff --git a/module/fid/src/View/Helper/Root/GetIt.php b/module/fid/src/View/Helper/Root/GetIt.php index aee1bc4139d..7ecdc5dc614 100644 --- a/module/fid/src/View/Helper/Root/GetIt.php +++ b/module/fid/src/View/Helper/Root/GetIt.php @@ -55,6 +55,22 @@ class GetIt extends AbstractHelper */ protected $driver; + /** + * @var array list of available source ID definitions from config + */ + protected $sids = [ + 'source_idsV1', + 'source_idsV3', + 'source_idsV4', + 'source_idsV5', + 'source_idsV6', + 'source_idsV7', + 'source_idsV8', + 'source_idsV9', + 'source_idsV10', + 'source_idsV11', + ]; + /** * FID API Client * @@ -72,6 +88,11 @@ class GetIt extends AbstractHelper protected $isbn; protected $issn; + protected $accordeonColorDefault; + protected $accordeonColorAlternative; + protected $accordeonHeadlineDefault; + protected $accordeonHeadlineAlternative; + /** * GetIt constructor. * @@ -100,6 +121,11 @@ class GetIt extends AbstractHelper $this->isbn = $this->driver->tryMethod('getISBNs'); $this->issn = $this->driver->tryMethod('getISSNs'); + $this->accordeonColorDefault = 'azure'; + $this->accordeonColorAlternative = 'amber'; + $this->accordeonHeadlineDefault = $this->translate('getit_links'); + $this->accordeonHeadlineAlternative = $this->translate('getit_infos'); + return $this; } @@ -196,7 +222,7 @@ class GetIt extends AbstractHelper $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)) + && !in_array($this->_getNonSourceIds('source_idsV8_9'), $this->institution)) || preg_grep($this->_getNonSourceIds('source_idsV8_3'), $this->format) ) ) { @@ -445,4 +471,423 @@ class GetIt extends AbstractHelper } return false; } + + public function getConfig() + { + //set default values + $accordeonColor = $this->accordeonColorDefault; + $accordeonHeadline = $this->accordeonHeadlineDefault; + $boxHeadline = $this->translate('Get it'); + $notice = $this->translate('getit_text_default'); + $showLinks = true; + $showOrderButton = false; + $showPartCopyButton = false; + $bossData = false; + $isEBCEBooks = false; + $hideNotice = true; + $isAiSidRecord = false; + + // let specific functions override defaults where necessary + foreach ($this->sids as $sid_config) { + if (in_array($this->sid, $sid = $this->_getSourceIds($sid_config))) + { + $foo = 'get_config_'.$sid_config; + $this->$foo( + $accordeonColor, + $accordeonHeadline, + $boxHeadline, + $notice, + $showLinks, + $showOrderButton, + $showPartCopyButton, + $bossData, + $isEBCEBooks, + $hideNotice, + $isAiSidRecord + ); + if ($this->sid !== '0') + { + //special case for source ID 0 + // this is th only SID that is contained in multiple configs (V8 + V9) + break; + } + } + } + return compact( + 'accordeonColor', + 'accordeonHeadline', + 'boxHeadline', + 'notice', + 'showLinks', + 'showOrderButton', + 'showPartCopyButton', + 'bossData', + 'isEBCEBooks', + 'hideNotice', + 'isAiSidRecord' + ); + } + + public function get_config_source_idsV1( + &$accordeonColor, + &$accordeonHeadline, + &$boxHeadline, + &$notice, + &$showLinks, + &$showOrderButton, + &$showPartCopyButton, + &$bossData, + &$isEBCEBooks, + &$hideNotice, + &$isAiSidRecord + ) + { + $accordeonColor = $this->accordeonColorAlternative; + $accordeonHeadline = $this->accordeonHeadlineAlternative; + $notice = $this->translate('getit_text_1'); + } + + public function get_config_source_idsV3( + &$accordeonColor, + &$accordeonHeadline, + &$boxHeadline, + &$notice, + &$showLinks, + &$showOrderButton, + &$showPartCopyButton, + &$bossData, + &$isEBCEBooks, + &$hideNotice, + &$isAiSidRecord + ) + { + $accordeonColor = $this->accordeonColorAlternative; + $accordeonHeadline = $this->accordeonHeadlineAlternative; + $boxHeadline = $this->fidClient->isLoggedOn() ? $this->translate('Get it') : $this->translate('getit_logged_not'); + $notice = ''; + $isAiSidRecord = true; + } + + public function get_config_source_idsV4( + &$accordeonColor, + &$accordeonHeadline, + &$boxHeadline, + &$notice, + &$showLinks, + &$showOrderButton, + &$showPartCopyButton, + &$bossData, + &$isEBCEBooks, + &$hideNotice, + &$isAiSidRecord + ) + { + $boxHeadline = $this->fidClient->isLoggedOn() ? $this->translate('Get it') : $this->translate('getit_logged_not'); + $notice = $this->fidClient->isLoggedOn() ? $this->translate('getit_text_12') : $this->translate('getit_text_2'); + } + + public function get_config_source_idsV5( + &$accordeonColor, + &$accordeonHeadline, + &$boxHeadline, + &$notice, + &$showLinks, + &$showOrderButton, + &$showPartCopyButton, + &$bossData, + &$isEBCEBooks, + &$hideNotice, + &$isAiSidRecord + ) + { + $accordeonColor = $this->accordeonColorAlternative; + $accordeonHeadline = $this->accordeonHeadlineAlternative; + $notice = !$this->fidClient->isLoggedOn() ? $this->translate('getit_text_3_1') : $this->translate('getit_text_13'); + $boxHeadline = $this->fidClient->isLoggedOn() ? $this->translate('Get it') : $this->translate('getit_logged_not'); + $showLinks = $this->fidClient->isLoggedOn(); + } + + public function get_config_source_idsV6( + &$accordeonColor, + &$accordeonHeadline, + &$boxHeadline, + &$notice, + &$showLinks, + &$showOrderButton, + &$showPartCopyButton, + &$bossData, + &$isEBCEBooks, + &$hideNotice, + &$isAiSidRecord + ) + { + $notice = $this->translate('getit_text_4'); + } + + public function get_config_source_idsV7( + &$accordeonColor, + &$accordeonHeadline, + &$boxHeadline, + &$notice, + &$showLinks, + &$showOrderButton, + &$showPartCopyButton, + &$bossData, + &$isEBCEBooks, + &$hideNotice, + &$isAiSidRecord + ) + { + $accordeonColor = $this->accordeonColorAlternative; + $accordeonHeadline = $this->accordeonHeadlineAlternative; + $notice = $this->translate('getit_text_5'); + } + + public function get_config_source_idsV8( + &$accordeonColor, + &$accordeonHeadline, + &$boxHeadline, + &$notice, + &$showLinks, + &$showOrderButton, + &$showPartCopyButton, + &$bossData, + &$isEBCEBooks, + &$hideNotice, + &$isAiSidRecord + ) + { + //accordeon + if (in_array('Free', $this->facetAvail)) { + $accordeonHeadline = $this->accordeonHeadlineAlternative; + $accordeonColor = $this->accordeonColorAlternative; + } 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)) + ) { + $accordeonHeadline = $this->accordeonHeadlineAlternative; + $accordeonColor = $this->accordeonColorAlternative; + } + //END accordeon + //box headline + $isLogin = false; + if (in_array($this->sid, $this->_getSourceIds('source_idsV9')) + && preg_grep($this->_getNonSourceIds('source_idsV8_8'), $this->format) + ) { + $isLogin = true; + } + elseif (in_array('Local', $this->facetAvail) + && ((preg_grep($this->_getNonSourceIds('source_idsV8_1'), $this->format) + && !in_array($this->_getNonSourceIds('source_idsV8_9'), $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 ($isLogin && !$this->fidClient->isLoggedOn()) { + $headLine = $this->translate('getit_logged_not'); + } + //END boxheadline + //notice + if (in_array($this->sid, $this->_getSourceIds('source_idsV9'))) { + if (preg_grep($this->_getNonSourceIds('source_idsV8_8'), $this->collection)) { + if (!$this->fidClient->isLoggedOn()) { + $notice = $this->translate('getit_text_3_1'); + } else { + $notice = $this->translate('getit_text_13'); + } + } + elseif ($this->isCollection) { + $notice = $this->translate('getit_text_11',['%%hierarchy_tree%%' => $this->translate('hierarchy_tree')]); + } + elseif (preg_grep($this->_getNonSourceIds('source_idsV8_7'), $this->megacollection) + ) { + $notice = $this->translate('getit_text_1'); + } + elseif (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()) { + $notice = $this->translate('getit_text_10'); + } elseif (preg_grep($this->_getNonSourceIds('source_idsV8_3'), $this->format)) { + $notice = $this->translate('getit_text_14'); + } else { + $notice = ''; + } + } + elseif (in_array('Local', $this->facetAvail) + && preg_grep($this->_getNonSourceIds('source_idsV8_2'), $this->format) + ) { + $notice = $this->translate('getit_text_8'); + } + elseif (in_array('Free', $this->facetAvail)) { + $notice = $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)) + ) { + $notice = $this->translate('getit_text_9'); + } elseif (in_array('Online', $this->facetAvail) + && preg_grep($this->_getNonSourceIds('source_idsV8_1'), $this->format) + ) { + if (!$this->fidClient->isLoggedOn()) { + $notice = $this->translate('getit_text_10'); + } else { + $notice = $this->translate('getit_text_15'); + } + } + } elseif ($this->isCollection) { + $notice = $this->translate('getit_text_11',['%%hierarchy_tree%%' => $this->translate('hierarchy_tree')]); + } elseif (in_array('Local', $this->facetAvail) + && preg_grep($this->_getNonSourceIds('source_idsV8_2'), $this->format) + ) { + $notice = $this->translate('getit_text_8'); + } elseif (in_array('Local', $this->facetAvail)) { + if (!$this->fidClient->isLoggedOn()) { + $notice = $this->translate('getit_text_10'); + } elseif (preg_grep($this->_getNonSourceIds('source_idsV8_3'), $this->format)) { + $notice = $this->translate('getit_text_14'); + } else { + $notice = ''; + } + } elseif (in_array('Free', $this->facetAvail)) { + $notice = $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)) + ) { + $notice = $this->translate('getit_text_9'); + } elseif (in_array('Online', $this->facetAvail) + && preg_grep($this->_getNonSourceIds('source_idsV8_1'), $this->format) + ) { + if (!$this->fidClient->isLoggedOn()) { + $notice = $this->translate('getit_text_10'); + } else { + $notice = $this->translate('getit_text_15'); + } + } + //END notice + //bossData + if (!in_array('Free', $this->facetAvail) + //&& (!empty($this->isbn) || !empty($this->issn)) + && !preg_grep($this->_getNonSourceIds('source_idsV8_8'), $this->collection) + ) { + if (preg_grep($this->_getNonSourceIds('source_idsV8_1'), $this->format) + ) { + $bossData = true; + if (!$this->isCollection) { + $showPartCopyButton = true; + } + } elseif (in_array('Local', $this->facetAvail) + && preg_grep($this->_getNonSourceIds('source_idsV8_3'), $this->format) + ) { + $bossData = true; + } + } + //END bossData + //hideNotice + if (in_array('Online', $this->facetAvail)) + { + if (preg_grep($this->_getNonSourceIds('source_idsV8_1'), $this->format) + || preg_grep($this->_getNonSourceIds('source_idsV8_5'), $this->format) + || preg_grep($this->_getNonSourceIds('source_idsV8_6'), $this->format) + ) { + $hideNotice = false; + } + } elseif (in_array('Local', $this->facetAvail)) + { + if (preg_grep($this->_getNonSourceIds('source_idsV8_1'), $this->format) + || preg_grep($this->_getNonSourceIds('source_idsV8_2'), $this->format) + || preg_grep($this->_getNonSourceIds('source_idsV8_3'), $this->format) + ) { + $hideNotice = false; + } + } + //END hideNotice + } + + public function get_config_source_idsV9( + &$accordeonColor, + &$accordeonHeadline, + &$boxHeadline, + &$notice, + &$showLinks, + &$showOrderButton, + &$showPartCopyButton, + &$bossData, + &$isEBCEBooks, + &$hideNotice, + &$isAiSidRecord + ) + { + //showLinks + if ( + preg_grep($this->_getNonSourceIds('source_idsV8_8'), $this->collection) + ) { + if (!$this->fidClient->isLoggedOn()) { + $showLinks = false; + } + } + //END showLinks + //orderButton + if (preg_grep($this->_getNonSourceIds('source_idsV8_1'), $this->format) + && !in_array($this->_getNonSourceIds('source_idsV8_9'), $this->institution) + && !$this->isCollection + && !preg_grep($this->_getNonSourceIds('source_idsV8_8'), $this->collection) + ) { + $showOrderButton = true; + } + //END orderButton + //EBCEbooks + if (in_array('Online', $this->facetAvail) + && preg_grep($this->_getNonSourceIds('source_idsV8_8'), $this->collection) + ) { + $isEBCEBooks = true; + } + //END EBCEbooks + } + + public function get_config_source_idsV10( + &$accordeonColor, + &$accordeonHeadline, + &$boxHeadline, + &$notice, + &$showLinks, + &$showOrderButton, + &$showPartCopyButton, + &$bossData, + &$isEBCEBooks, + &$hideNotice, + &$isAiSidRecord + ) + { + $accordeonColor = $this->accordeonColorAlternative; + $accordeonHeadline = $this->accordeonHeadlineAlternative; + $notice = $this->translate('getit_text_6'); + } + + public function get_config_source_idsV11( + &$accordeonColor, + &$accordeonHeadline, + &$boxHeadline, + &$notice, + &$showLinks, + &$showOrderButton, + &$showPartCopyButton, + &$bossData, + &$isEBCEBooks, + &$hideNotice, + &$isAiSidRecord + ) + { + $notice = $this->translate('getit_text_7'); + } } -- GitLab