From 931fd0bdcbe3023d0a253d3020c20619ce5a8227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Lahmann?= <lahmann@ub.uni-leipzig.de> Date: Mon, 27 Jul 2015 14:23:42 -0400 Subject: [PATCH] refactored signature of OpenUrl->__invoke view helper: __invoke($driver, $area) * refactored signature of OpenUrl->isActive() * updated tests to new signatures in OpenUrl view helper * updated templates to new signatures in OpenUrl view helper * corrected 'records' location to 'record' for consistency with config.ini. --- .../src/VuFind/View/Helper/Root/OpenUrl.php | 26 ++++++---- .../View/Helper/Root/OpenUrlTest.php | 48 +++++++++++-------- .../RecordDriver/Pazpar2/result-list.phtml | 4 +- .../SolrDefault/collection-info.phtml | 4 +- .../RecordDriver/SolrDefault/core.phtml | 4 +- .../RecordDriver/SolrDefault/list-entry.phtml | 4 +- .../SolrDefault/result-grid.phtml | 4 +- .../SolrDefault/result-list.phtml | 4 +- .../templates/RecordTab/holdingsils.phtml | 4 +- .../RecordDriver/Pazpar2/result-list.phtml | 4 +- .../SolrDefault/collection-info.phtml | 4 +- .../RecordDriver/SolrDefault/core.phtml | 4 +- .../RecordDriver/SolrDefault/list-entry.phtml | 4 +- .../SolrDefault/result-grid.phtml | 4 +- .../SolrDefault/result-list.phtml | 4 +- .../templates/RecordTab/holdingsils.phtml | 4 +- .../RecordDriver/SolrDefault/core.phtml | 4 +- .../SolrDefault/result-list.phtml | 4 +- 18 files changed, 75 insertions(+), 63 deletions(-) diff --git a/module/VuFind/src/VuFind/View/Helper/Root/OpenUrl.php b/module/VuFind/src/VuFind/View/Helper/Root/OpenUrl.php index 45916414c38..53da7557873 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/OpenUrl.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/OpenUrl.php @@ -66,6 +66,13 @@ class OpenUrl extends \Zend\View\Helper\AbstractHelper */ protected $recordDriver; + /** + * OpenURL context ('results', 'record' or 'holdings') + * + * @var string + */ + protected $area; + /** * Constructor * @@ -85,12 +92,15 @@ class OpenUrl extends \Zend\View\Helper\AbstractHelper * Render appropriate UI controls for an OpenURL link. * * @param \VuFind\RecordDriver $driver The current recorddriver + * @param string $area OpenURL context ('results', 'record' + * or 'holdings' * * @return object */ - public function __invoke($driver) + public function __invoke($driver, $area) { $this->recordDriver = $driver; + $this->area = $area; return $this; } @@ -142,17 +152,15 @@ class OpenUrl extends \Zend\View\Helper\AbstractHelper /** * Public method to check whether OpenURLs are active for current record * - * @param string $area 'results', 'record' or 'holdings' - * * @return bool */ - public function isActive($area) + public function isActive() { // check first if OpenURLs are enabled for this RecordDriver // check second if OpenURLs are enabled for this context // check last if any rules apply if (!$this->recordDriver->getOpenUrl() - || !$this->checkContext($area) + || !$this->checkContext() || !$this->checkIfRulesApply() ) { return false; @@ -164,11 +172,9 @@ class OpenUrl extends \Zend\View\Helper\AbstractHelper * Does the OpenURL configuration indicate that we should display OpenURLs in * the specified context? * - * @param string $area 'results', 'record' or 'holdings' - * * @return bool */ - protected function checkContext($area) + protected function checkContext() { // Doesn't matter the target area if no OpenURL resolver is specified: if (!isset($this->config->url)) { @@ -176,14 +182,14 @@ class OpenUrl extends \Zend\View\Helper\AbstractHelper } // If a setting exists, return that: - $key = 'show_in_' . $area; + $key = 'show_in_' . $this->area; if (isset($this->config->$key)) { return $this->config->$key; } // If we got this far, use the defaults -- true for results, false for // everywhere else. - return ($area == 'results'); + return ($this->area == 'results'); } /** diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/OpenUrlTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/OpenUrlTest.php index 1e49eef4444..d7c5681ddc3 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/OpenUrlTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/OpenUrlTest.php @@ -59,9 +59,11 @@ class OpenUrlTest extends \VuFindTest\Unit\ViewHelperTestCase 'url' => 'http://foo/bar' ]; $openUrl = $this->getOpenUrl(null, $config) - ->__invoke($this->getMockDriver()); - $this->assertTrue($openUrl->isActive('results')); - $this->assertFalse($openUrl->isActive('foo')); + ->__invoke($this->getMockDriver(), 'results'); + $this->assertTrue($openUrl->isActive()); + $openUrl = $this->getOpenUrl(null, $config) + ->__invoke($this->getMockDriver(), 'foo'); + $this->assertFalse($openUrl->isActive()); } /** @@ -77,9 +79,11 @@ class OpenUrlTest extends \VuFindTest\Unit\ViewHelperTestCase 'show_in_foo' => true, ]; $openUrl = $this->getOpenUrl(null, $config) - ->__invoke($this->getMockDriver()); - $this->assertFalse($openUrl->isActive('results')); - $this->assertTrue($openUrl->isActive('foo')); + ->__invoke($this->getMockDriver(), 'results'); + $this->assertFalse($openUrl->isActive()); + $openUrl = $this->getOpenUrl(null, $config) + ->__invoke($this->getMockDriver(), 'foo'); + $this->assertTrue($openUrl->isActive()); } /** @@ -90,9 +94,11 @@ class OpenUrlTest extends \VuFindTest\Unit\ViewHelperTestCase public function testCheckContextNoUrl() { $openUrl = $this->getOpenUrl() - ->__invoke($this->getMockDriver()); - $this->assertFalse($openUrl->isActive('results')); - $this->assertFalse($openUrl->isActive('foo')); + ->__invoke($this->getMockDriver(), 'results'); + $this->assertFalse($openUrl->isActive()); + $openUrl = $this->getOpenUrl() + ->__invoke($this->getMockDriver(), 'foo'); + $this->assertFalse($openUrl->isActive()); } /** @@ -105,8 +111,8 @@ class OpenUrlTest extends \VuFindTest\Unit\ViewHelperTestCase { $openUrl = $this ->getOpenUrl($this->getFixture("rule1.json"), $this->rulesConfig) - ->__invoke($this->getMockDriver()); - $this->assertTrue($openUrl->isActive('results')); + ->__invoke($this->getMockDriver(), 'results'); + $this->assertTrue($openUrl->isActive()); } /** @@ -119,8 +125,8 @@ class OpenUrlTest extends \VuFindTest\Unit\ViewHelperTestCase { $openUrl = $this ->getOpenUrl($this->getFixture("rule2.json"), $this->rulesConfig) - ->__invoke($this->getMockDriver()); - $this->assertFalse($openUrl->isActive('results')); + ->__invoke($this->getMockDriver(), 'results'); + $this->assertFalse($openUrl->isActive()); } /** @@ -133,8 +139,8 @@ class OpenUrlTest extends \VuFindTest\Unit\ViewHelperTestCase { $openUrl = $this ->getOpenUrl($this->getFixture("rule3.json"), $this->rulesConfig) - ->__invoke($this->getMockDriver()); - $this->assertFalse($openUrl->isActive('results')); + ->__invoke($this->getMockDriver(), 'results'); + $this->assertFalse($openUrl->isActive()); } /** @@ -151,8 +157,8 @@ class OpenUrlTest extends \VuFindTest\Unit\ViewHelperTestCase ); $openUrl = $this ->getOpenUrl($this->getFixture("rule5.json"), $this->rulesConfig) - ->__invoke($driver); - $this->assertFalse($openUrl->isActive('results')); + ->__invoke($driver, 'results'); + $this->assertFalse($openUrl->isActive()); } /** @@ -165,8 +171,8 @@ class OpenUrlTest extends \VuFindTest\Unit\ViewHelperTestCase { $openUrl = $this ->getOpenUrl($this->getFixture("rule4.json"), $this->rulesConfig) - ->__invoke($this->getMockDriver()); - $this->assertTrue($openUrl->isActive('results')); + ->__invoke($this->getMockDriver(), 'results'); + $this->assertTrue($openUrl->isActive()); } /** @@ -186,8 +192,8 @@ class OpenUrlTest extends \VuFindTest\Unit\ViewHelperTestCase ); $openUrl = $this ->getOpenUrl($this->getFixture("rule1.json"), $this->rulesConfig); - $this->assertTrue($openUrl->__invoke($defaultDriver)->isActive('results')); - $this->assertFalse($openUrl->__invoke($marcDriver)->isActive('results')); + $this->assertTrue($openUrl->__invoke($defaultDriver, 'results')->isActive()); + $this->assertFalse($openUrl->__invoke($marcDriver, 'results')->isActive()); } /** diff --git a/themes/blueprint/templates/RecordDriver/Pazpar2/result-list.phtml b/themes/blueprint/templates/RecordDriver/Pazpar2/result-list.phtml index 22b08523b77..4eb2ae0646b 100644 --- a/themes/blueprint/templates/RecordDriver/Pazpar2/result-list.phtml +++ b/themes/blueprint/templates/RecordDriver/Pazpar2/result-list.phtml @@ -60,8 +60,8 @@ but even if we don't plan to display the link, we still want to get the $openUrl value for use in generating a COinS (Z3988) tag -- see bottom of file. */ - $openUrl = $this->openUrl($this->driver); - $openUrlActive = $openUrl->isActive('results'); + $openUrl = $this->openUrl($this->driver, 'results'); + $openUrlActive = $openUrl->isActive(); // Account for replace_other_urls setting $urls = $openUrlActive ? $this->record($this->driver)->getLinkDetailsForOpenUrl() : $this->record($this->driver)->getLinkDetails() ; if ($openUrlActive || !empty($urls)): ?> diff --git a/themes/blueprint/templates/RecordDriver/SolrDefault/collection-info.phtml b/themes/blueprint/templates/RecordDriver/SolrDefault/collection-info.phtml index 04843bd0ab8..46de8dde937 100644 --- a/themes/blueprint/templates/RecordDriver/SolrDefault/collection-info.phtml +++ b/themes/blueprint/templates/RecordDriver/SolrDefault/collection-info.phtml @@ -130,8 +130,8 @@ <? endif; ?> <? - $openUrl = $this->openUrl($this->driver); - $openUrlActive = $openUrl->isActive('record'); + $openUrl = $this->openUrl($this->driver, 'record'); + $openUrlActive = $openUrl->isActive(); // Account for replace_other_urls setting $urls = $openUrlActive ? $this->record($this->driver)->getLinkDetailsForOpenUrl() : $this->record($this->driver)->getLinkDetails() ; ?> diff --git a/themes/blueprint/templates/RecordDriver/SolrDefault/core.phtml b/themes/blueprint/templates/RecordDriver/SolrDefault/core.phtml index e7977746ef9..2349e0a1961 100644 --- a/themes/blueprint/templates/RecordDriver/SolrDefault/core.phtml +++ b/themes/blueprint/templates/RecordDriver/SolrDefault/core.phtml @@ -171,8 +171,8 @@ <? endif; ?> <? - $openUrl = $this->openUrl($this->driver); - $openUrlActive = $openUrl->isActive('records'); + $openUrl = $this->openUrl($this->driver, 'record'); + $openUrlActive = $openUrl->isActive(); // Account for replace_other_urls setting $urls = $openUrlActive ? $this->record($this->driver)->getLinkDetailsForOpenUrl() : $this->record($this->driver)->getLinkDetails() ; ?> diff --git a/themes/blueprint/templates/RecordDriver/SolrDefault/list-entry.phtml b/themes/blueprint/templates/RecordDriver/SolrDefault/list-entry.phtml index 75f327f620a..4053efdf3e9 100644 --- a/themes/blueprint/templates/RecordDriver/SolrDefault/list-entry.phtml +++ b/themes/blueprint/templates/RecordDriver/SolrDefault/list-entry.phtml @@ -76,8 +76,8 @@ but even if we don't plan to display the link, we still want to get the $openUrl value for use in generating a COinS (Z3988) tag -- see bottom of file. */ - $openUrl = $this->openUrl($this->driver); - $openUrlActive = $openUrl->isActive('results'); + $openUrl = $this->openUrl($this->driver, 'results'); + $openUrlActive = $openUrl->isActive(); // Account for replace_other_urls setting $urls = $openUrlActive ? $this->record($this->driver)->getLinkDetailsForOpenUrl() : $this->record($this->driver)->getLinkDetails() ; if ($openUrlActive || !empty($urls)): ?> diff --git a/themes/blueprint/templates/RecordDriver/SolrDefault/result-grid.phtml b/themes/blueprint/templates/RecordDriver/SolrDefault/result-grid.phtml index 6d07b79a516..9bc2cf989e5 100644 --- a/themes/blueprint/templates/RecordDriver/SolrDefault/result-grid.phtml +++ b/themes/blueprint/templates/RecordDriver/SolrDefault/result-grid.phtml @@ -12,8 +12,8 @@ but even if we don't plan to display the link, we still want to get the $openUrl value for use in generating a COinS (Z3988) tag -- see bottom of file. */ - $openUrl = $this->openUrl($this->driver); - $openUrlActive = $openUrl->isActive('results'); + $openUrl = $this->openUrl($this->driver, 'results'); + $openUrlActive = $openUrl->isActive(); // Account for replace_other_urls setting $urls = $openUrlActive ? $this->record($this->driver)->getLinkDetailsForOpenUrl() : $this->record($this->driver)->getLinkDetails() ; ?> diff --git a/themes/blueprint/templates/RecordDriver/SolrDefault/result-list.phtml b/themes/blueprint/templates/RecordDriver/SolrDefault/result-list.phtml index ceaa5f7dbc3..d98ba4a07ef 100644 --- a/themes/blueprint/templates/RecordDriver/SolrDefault/result-list.phtml +++ b/themes/blueprint/templates/RecordDriver/SolrDefault/result-list.phtml @@ -109,8 +109,8 @@ but even if we don't plan to display the link, we still want to get the $openUrl value for use in generating a COinS (Z3988) tag -- see bottom of file. */ - $openUrl = $this->openUrl($this->driver); - $openUrlActive = $openUrl->isActive('results'); + $openUrl = $this->openUrl($this->driver, 'results'); + $openUrlActive = $openUrl->isActive(); // Account for replace_other_urls setting $urls = $openUrlActive ? $this->record($this->driver)->getLinkDetailsForOpenUrl() : $this->record($this->driver)->getLinkDetails() ; if ($openUrlActive || !empty($urls)): ?> diff --git a/themes/blueprint/templates/RecordTab/holdingsils.phtml b/themes/blueprint/templates/RecordTab/holdingsils.phtml index 566eb49983c..308cef8b6ae 100644 --- a/themes/blueprint/templates/RecordTab/holdingsils.phtml +++ b/themes/blueprint/templates/RecordTab/holdingsils.phtml @@ -3,8 +3,8 @@ $account = $this->auth()->getManager(); $user = $account->isLoggedIn(); $holdings = $this->driver->getRealTimeHoldings(); - $openUrl = $this->openUrl($this->driver); - $openUrlActive = $openUrl->isActive('holdings'); + $openUrl = $this->openUrl($this->driver, 'holdings'); + $openUrlActive = $openUrl->isActive(); // Account for replace_other_urls setting $urls = $openUrlActive ? $this->record($this->driver)->getLinkDetailsForOpenUrl() : $this->record($this->driver)->getLinkDetails() ; $offlineMode = $this->ils()->getOfflineMode(); diff --git a/themes/bootstrap3/templates/RecordDriver/Pazpar2/result-list.phtml b/themes/bootstrap3/templates/RecordDriver/Pazpar2/result-list.phtml index 7ed216c6708..a13a6df8669 100644 --- a/themes/bootstrap3/templates/RecordDriver/Pazpar2/result-list.phtml +++ b/themes/bootstrap3/templates/RecordDriver/Pazpar2/result-list.phtml @@ -75,8 +75,8 @@ but even if we don't plan to display the link, we still want to get the $openUrl value for use in generating a COinS (Z3988) tag -- see bottom of file. */ - $openUrl = $this->openUrl($this->driver); - $openUrlActive = $openUrl->isActive('results'); + $openUrl = $this->openUrl($this->driver, 'results'); + $openUrlActive = $openUrl->isActive(); // Account for replace_other_urls setting $urls = $openUrlActive ? $this->record($this->driver)->getLinkDetailsForOpenUrl() : $this->record($this->driver)->getLinkDetails() ; if ($openUrlActive || !empty($urls)): ?> diff --git a/themes/bootstrap3/templates/RecordDriver/SolrDefault/collection-info.phtml b/themes/bootstrap3/templates/RecordDriver/SolrDefault/collection-info.phtml index 7963132aa06..183f94290fe 100644 --- a/themes/bootstrap3/templates/RecordDriver/SolrDefault/collection-info.phtml +++ b/themes/bootstrap3/templates/RecordDriver/SolrDefault/collection-info.phtml @@ -153,8 +153,8 @@ <? endif; ?> <? - $openUrl = $this->openUrl($this->driver); - $openUrlActive = $openUrl->isActive('record'); + $openUrl = $this->openUrl($this->driver, 'record'); + $openUrlActive = $openUrl->isActive(); // Account for replace_other_urls setting $urls = $openUrlActive ? $this->record($this->driver)->getLinkDetailsForOpenUrl() : $this->record($this->driver)->getLinkDetails() ; ?> diff --git a/themes/bootstrap3/templates/RecordDriver/SolrDefault/core.phtml b/themes/bootstrap3/templates/RecordDriver/SolrDefault/core.phtml index 571ee7a3eec..accf40bcfaf 100644 --- a/themes/bootstrap3/templates/RecordDriver/SolrDefault/core.phtml +++ b/themes/bootstrap3/templates/RecordDriver/SolrDefault/core.phtml @@ -213,8 +213,8 @@ <? endif; ?> <? - $openUrl = $this->openUrl($this->driver); - $openUrlActive = $openUrl->isActive('records'); + $openUrl = $this->openUrl($this->driver, 'record'); + $openUrlActive = $openUrl->isActive(); // Account for replace_other_urls setting $urls = $openUrlActive ? $this->record($this->driver)->getLinkDetailsForOpenUrl() : $this->record($this->driver)->getLinkDetails() ; ?> diff --git a/themes/bootstrap3/templates/RecordDriver/SolrDefault/list-entry.phtml b/themes/bootstrap3/templates/RecordDriver/SolrDefault/list-entry.phtml index bc4327986f1..22061423d20 100644 --- a/themes/bootstrap3/templates/RecordDriver/SolrDefault/list-entry.phtml +++ b/themes/bootstrap3/templates/RecordDriver/SolrDefault/list-entry.phtml @@ -127,8 +127,8 @@ but even if we don't plan to display the link, we still want to get the $openUrl value for use in generating a COinS (Z3988) tag -- see bottom of file. */ - $openUrl = $this->openUrl($this->driver); - $openUrlActive = $openUrl->isActive('results'); + $openUrl = $this->openUrl($this->driver, 'results'); + $openUrlActive = $openUrl->isActive(); // Account for replace_other_urls setting $urls = $openUrlActive ? $this->record($this->driver)->getLinkDetailsForOpenUrl() : $this->record($this->driver)->getLinkDetails() ; diff --git a/themes/bootstrap3/templates/RecordDriver/SolrDefault/result-grid.phtml b/themes/bootstrap3/templates/RecordDriver/SolrDefault/result-grid.phtml index ee78dde499e..c516921fc19 100644 --- a/themes/bootstrap3/templates/RecordDriver/SolrDefault/result-grid.phtml +++ b/themes/bootstrap3/templates/RecordDriver/SolrDefault/result-grid.phtml @@ -3,8 +3,8 @@ but even if we don't plan to display the link, we still want to get the $openUrl value for use in generating a COinS (Z3988) tag -- see bottom of file. */ -$openUrl = $this->openUrl($this->driver); -$openUrlActive = $openUrl->isActive('results'); +$openUrl = $this->openUrl($this->driver, 'results'); +$openUrlActive = $openUrl->isActive(); // Account for replace_other_urls setting $urls = $openUrlActive ? $this->record($this->driver)->getLinkDetailsForOpenUrl() : $this->record($this->driver)->getLinkDetails() ; ?> diff --git a/themes/bootstrap3/templates/RecordDriver/SolrDefault/result-list.phtml b/themes/bootstrap3/templates/RecordDriver/SolrDefault/result-list.phtml index 7d5d1bc1d34..a5e48e71379 100644 --- a/themes/bootstrap3/templates/RecordDriver/SolrDefault/result-list.phtml +++ b/themes/bootstrap3/templates/RecordDriver/SolrDefault/result-list.phtml @@ -116,8 +116,8 @@ but even if we don't plan to display the link, we still want to get the $openUrl value for use in generating a COinS (Z3988) tag -- see bottom of file. */ - $openUrl = $this->openUrl($this->driver); - $openUrlActive = $openUrl->isActive('results'); + $openUrl = $this->openUrl($this->driver, 'results'); + $openUrlActive = $openUrl->isActive(); // Account for replace_other_urls setting $urls = $openUrlActive ? $this->record($this->driver)->getLinkDetailsForOpenUrl() : $this->record($this->driver)->getLinkDetails() ; diff --git a/themes/bootstrap3/templates/RecordTab/holdingsils.phtml b/themes/bootstrap3/templates/RecordTab/holdingsils.phtml index 2965a1b63ef..c81a4e2989c 100644 --- a/themes/bootstrap3/templates/RecordTab/holdingsils.phtml +++ b/themes/bootstrap3/templates/RecordTab/holdingsils.phtml @@ -3,8 +3,8 @@ $account = $this->auth()->getManager(); $user = $account->isLoggedIn(); $holdings = $this->driver->getRealTimeHoldings(); - $openUrl = $this->openUrl($this->driver); - $openUrlActive = $openUrl->isActive('holdings'); + $openUrl = $this->openUrl($this->driver, 'holdings'); + $openUrlActive = $openUrl->isActive(); // Account for replace_other_urls setting $urls = $openUrlActive ? $this->record($this->driver)->getLinkDetailsForOpenUrl() : $this->record($this->driver)->getLinkDetails() ; $offlineMode = $this->ils()->getOfflineMode(); diff --git a/themes/jquerymobile/templates/RecordDriver/SolrDefault/core.phtml b/themes/jquerymobile/templates/RecordDriver/SolrDefault/core.phtml index 5af60c6afa0..6ad6bba3a0c 100644 --- a/themes/jquerymobile/templates/RecordDriver/SolrDefault/core.phtml +++ b/themes/jquerymobile/templates/RecordDriver/SolrDefault/core.phtml @@ -133,8 +133,8 @@ <? endif; ?> <? - $openUrl = $this->openUrl($this->driver); - $openUrlActive = $openUrl->isActive('record'); + $openUrl = $this->openUrl($this->driver, 'record'); + $openUrlActive = $openUrl->isActive(); // Account for replace_other_urls setting $urls = $openUrlActive ? $this->record($this->driver)->getLinkDetailsForOpenUrl() diff --git a/themes/jquerymobile/templates/RecordDriver/SolrDefault/result-list.phtml b/themes/jquerymobile/templates/RecordDriver/SolrDefault/result-list.phtml index 09b4ccfb8a9..0d44917101a 100644 --- a/themes/jquerymobile/templates/RecordDriver/SolrDefault/result-list.phtml +++ b/themes/jquerymobile/templates/RecordDriver/SolrDefault/result-list.phtml @@ -24,8 +24,8 @@ <? endif; ?> <?=$this->record($this->driver)->getFormatList()?> <? - $openUrl = $this->openUrl($this->driver); - $openUrlActive = $openUrl->isActive('results'); + $openUrl = $this->openUrl($this->driver, 'results'); + $openUrlActive = $openUrl->isActive(); $urls = $openUrlActive ? $this->record($this->driver)->getLinkDetailsForOpenUrl() : $this->record($this->driver)->getLinkDetails(); -- GitLab