diff --git a/library/Class/DigitalResource.php b/library/Class/DigitalResource.php index 6641cc19f68a8282d4de16e2b5e96f4bb91b7f68..974c24ea25cd4bb93239551082c89447ebb80398 100644 --- a/library/Class/DigitalResource.php +++ b/library/Class/DigitalResource.php @@ -175,7 +175,8 @@ class Class_DigitalResource extends Class_Entity { if (is_readable($this->getBaseDir() . '/' . $type . '/View/Helper/Album.php')) { $class_name = $type . '_View_Helper_Album'; - $helper = (new $class_name())->setView($view); + $helper = $this->build($class_name, $this->configFor($type)) + ->setView($view); return $helper->album($album); } diff --git a/library/Class/DigitalResource/AlbumViewHelper.php b/library/Class/DigitalResource/AlbumViewHelper.php new file mode 100644 index 0000000000000000000000000000000000000000..f1e5e7faa196f85313418e5d3f3c607bd71619ba --- /dev/null +++ b/library/Class/DigitalResource/AlbumViewHelper.php @@ -0,0 +1,47 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH 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 AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_DigitalResource_AlbumViewHelper extends ZendAfi_View_Helper_BaseHelper { + protected $_config; + + public function __construct($config) { + parent::__construct(); + $this->_config = $config; + } + + + public function album($album) { + if(!$album) + return ''; + + $url = $this->view->url(['module' => 'opac', + 'controller' => 'modules', + 'action' => $this->_config->getSsoAction(), + 'album_id' => $album->getId()], + null, + true); + + return $this->view->tagAnchor($url, + $this->_('Accéder à "%s" dans un nouvel onglet', $album->getTitre()), + ['target' => '_blank']); + } +} \ No newline at end of file diff --git a/library/Class/DigitalResource/Config.php b/library/Class/DigitalResource/Config.php index aee72a1e58886a09e23487ba44ab8c84f3284095..6e0eb99b83a4e4b6534c7c282f273497ddcac115 100644 --- a/library/Class/DigitalResource/Config.php +++ b/library/Class/DigitalResource/Config.php @@ -49,12 +49,6 @@ class Class_DigitalResource_Config extends Class_Entity { } - - public static function getInstanceFromController($controller) { - return Class_DigitalResource::getInstance()->configFor((new Class_DigitalResource_Name())->getNameFromController($controller)); - } - - public function __construct($digital_resource) { $this->setDigitalResource($digital_resource); $this->updateAttributes($this->getConfig()); diff --git a/library/Class/DigitalResource/Controller.php b/library/Class/DigitalResource/Controller.php index 55fda6522f2edea03ad308231948f38af0bf0902..311a8676ee81e04b0a6d88277cfca3be9c5084a6 100644 --- a/library/Class/DigitalResource/Controller.php +++ b/library/Class/DigitalResource/Controller.php @@ -24,7 +24,7 @@ class Class_DigitalResource_Controller extends ZendAfi_Controller_Action { public function preDispatch() { parent::preDispatch(); - $this->_config = Class_DigitalResource_Config::getInstanceFromController(get_called_class()); + $this->_config = Class_DigitalResource_Config::getInstanceFor(static::class); if ($this->_config->getSsoAction() == $this->_request->getActionName()) return $this->_forward('sso', diff --git a/library/Class/DigitalResource/Name.php b/library/Class/DigitalResource/Name.php index fdc589a83ffb1a70118f52135a89f7867eb32a23..203a70cfe47289e0bd2c1262751b468ab6bcca2a 100644 --- a/library/Class/DigitalResource/Name.php +++ b/library/Class/DigitalResource/Name.php @@ -22,19 +22,13 @@ class Class_DigitalResource_Name { - public function getPath($class) { - return dirname((new ReflectionClass($class))->getFileName()); + public function getPath($instance) { + return dirname((new ReflectionClass($instance))->getFileName()); } public function getName($class) { - $path = array_reverse(explode('/', static::getPath($class))); - return array_shift($path); - } - - - public function getNameFromController($class) { - $path = array_reverse(explode('/', dirname(static::getPath($class)))); + $path = explode('_', $class); return array_shift($path); } } \ No newline at end of file diff --git a/library/digital_resources/StoryPlayR/Config.php b/library/digital_resources/StoryPlayR/Config.php index abf2e371f3e0366b2fbb182983a7cc543cbd8aca..b9c424b21749c1a742db801f508ac4228f9fb3e5 100644 --- a/library/digital_resources/StoryPlayR/Config.php +++ b/library/digital_resources/StoryPlayR/Config.php @@ -30,7 +30,7 @@ class StoryPlayR_Config extends Class_DigitalResource_Config { 'OPDS_CATALOG_URL' => Class_AdminVar_Meta::newDefault($this->_('URL du catalogue OPDS de la plateforme StoryPlay*r')) ->bePrivate()], 'PermissionLabel' => $this->_('Bibliothèque numérique: accéder aux albums StoryPlay*r'), - 'NotAllowedMessage' => $this->_('Vous devez être abonné pour accéder à cette ressource.'), + 'NotAllowedMessage' => $this->_('Votre compte n\'est pas authorisé à accéder à cette ressource.'), 'SsoAction' => true, 'SsoValidateUrl' => true, @@ -50,11 +50,27 @@ class StoryPlayR_Config extends Class_DigitalResource_Config { public function getSsoUrl($user) { + if(!$user) + return ''; + return $this->getAdminVar('SSO_URL') . '?' - . http_build_query(['userid' => $user->getLogin(), - 'mediathequeid' => $this->getAdminVar('MEDIATHEQUE_ID'), - 'sessionid' => (new Class_CasTicket())->getTicketForUser($user)]); + . $this->_getSsoQuery($user); + } + + + public function getAlbumSsoUrl($user, $album) { + return parent::getAlbumSsoUrl($user, $album); + if(!$album) + return ''; + + if(!$base_url = $album->getExternalUri()) + return ''; + + if(!$user) + return ''; + + return $base_url . '&' . $this->_getSsoQuery($user); } @@ -74,6 +90,16 @@ class StoryPlayR_Config extends Class_DigitalResource_Config { public function getHarvestUrl($page = 1) { $query = ['portalProvider' => 'bokeh', 'mediathequeid' => $this->getAdminVar('MEDIATHEQUE_ID')]; + return $this->getAdminVar('OPDS_CATALOG_URL') . '?' . http_build_query(array_filter($query)); } + + + protected function _getSsoQuery($user) { + return $user + ? http_build_query(['userid' => $user->getLogin(), + 'mediathequeid' => $this->getAdminVar('MEDIATHEQUE_ID'), + 'sessionid' => (new Class_CasTicket())->getTicketForUser($user)]) + : ''; + } } \ No newline at end of file diff --git a/library/digital_resources/StoryPlayR/Service.php b/library/digital_resources/StoryPlayR/Service.php index 02256a2ac01696f5796f0f88b7eae3025f7c81e3..2f8b58c54d83bec6554b110211db04aa8fc280a0 100644 --- a/library/digital_resources/StoryPlayR/Service.php +++ b/library/digital_resources/StoryPlayR/Service.php @@ -20,7 +20,7 @@ */ -class StoryPlayr_Service extends Class_DigitalResource_Service { +class StoryPlayR_Service extends Class_DigitalResource_Service { public function getPageCount() { return 1; } diff --git a/library/digital_resources/StoryPlayR/View/Helper/Album.php b/library/digital_resources/StoryPlayR/View/Helper/Album.php new file mode 100644 index 0000000000000000000000000000000000000000..02c856a77fa5ee5cb12ec87600802b4639c1d02c --- /dev/null +++ b/library/digital_resources/StoryPlayR/View/Helper/Album.php @@ -0,0 +1,23 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH 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 AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class StoryPlayR_View_Helper_Album extends Class_DigitalResource_AlbumViewHelper {} \ No newline at end of file diff --git a/library/digital_resources/StoryPlayR/tests/StoryPlayRTest.php b/library/digital_resources/StoryPlayR/tests/StoryPlayRTest.php index a46ee76f218a0a687a75255972462a550d60f3ce..fe51eea85ebfa9b5879792261b859396bc9cd693 100644 --- a/library/digital_resources/StoryPlayR/tests/StoryPlayRTest.php +++ b/library/digital_resources/StoryPlayR/tests/StoryPlayRTest.php @@ -185,7 +185,7 @@ class StoryPlayRHarvestTest extends StoryPlayRActivatedTestCase { public function setUp() { parent::setUp(); - Class_AdminVar::set('StoryPlayR_OPDS_CATALOG_URL', 'https://preprod.storyplayr.com/api/opds-with-links?portalProvider=bokeh'); + Class_AdminVar::set('StoryPlayR_OPDS_CATALOG_URL', 'https://preprod.storyplayr.com/api/opds-with-links'); $opds = file_get_contents(__DIR__ . '/StoryPlayrCatalog.xml'); @@ -235,3 +235,55 @@ class StoryPlayRHarvestTest extends StoryPlayRActivatedTestCase { $this->assertEquals(13, count(explode(';', $this->_album->getMatiere()))); } } + + + +class StoryPlayRNoticeAjaxTest extends StoryPlayRActivatedTestCase { + public function setUp() { + parent::setUp(); + + $album = $this->fixture('Class_Album', + ['id' => 12, + 'titre' => 'Once upon a time', + 'type_doc_id' => 'StoryPlayR', + 'visible' => 1, + 'status' => Class_Album::STATUS_VALIDATED + ]); + + $album->index(); + + $this->dispatch('/noticeajax/resnumeriques/id_notice/' . $album->getNoticeId(), true); + } + + + /** @test */ + public function linkToModulesStoryPlayRAlbumShouldBePresent() { + $this->assertXPath('//a[contains(@href, "/modules/story-play-r/album_id/12")]'); + } +} + + + +class StoryPlayRAlbumSsoUrlTest extends StoryPlayRActivatedTestCase { + public function setUp() { + parent::setUp(); + + ZendAfi_Auth::getInstance()->logUser($this->_user); + + $album = $this->fixture('Class_Album', + ['id' => 12, + 'titre' => 'Once upon a time', + 'type_doc_id' => 'StoryPlayR' + ]); + + $album->setExternalUri('https://preprod.storyplayr.com/api/bokeh/login?target=/histoire/a-coat-of-many-colors/playr'); + + $this->dispatch('/modules/story-play-r/album_id/12', true); + } + + + /** @test */ + public function shouldRedirectToStoryPlayRSsoUrlWithJavascript() { + $this->assertXPathContentContains('//script', 'https://preprod.storyplayr.com/api/bokeh/login?target=/histoire/a-coat-of-many-colors/playr&userid=Tom&mediathequeid=123456&sessionid=ST-', $this->_response->getBody()); + } +}