Commit c08deb45 authored by Laurent's avatar Laurent
Browse files

Merge branch 'dev#129492_connecteur_mobidys'

parents 6395ab7d b165d2c9
'129492' =>
['Label' => $this->_('Connecteur Mobidys'),
'Desc' => $this->_('%s propose un catalogue de livres numérique à destination des dys. Le connecteur fournis l\'accès SSO et l\'aspiration du catalogue.', '<a href="https://www.mobidys.com/bibliodyssee">Mobidys</a>'),
'Image' => '',
'Video' => '',
'Category' => $this->_('Bibliothèque numérique'),
'Right' => function($feature_description, $user) {return true;},
'Wiki' => 'https://wiki.bokeh-library-portal.org/index.php?title=Mobidys',
'Test' => '',
'Date' => '2021-07-08'],
\ No newline at end of file
- ticket #129492 : Bibliothèque numérique : développement du connecteur Mobidys
\ No newline at end of file
......@@ -51,6 +51,7 @@ class Class_WebService_OPDS_CatalogEntry extends Class_WebService_BibNumerique_R
public function addFile($url, $mimeType) {
$this->_files[] = Class_WebService_OPDS_EntryFile::newWith($url, $mimeType);
return $this;
}
......@@ -92,6 +93,7 @@ class Class_WebService_OPDS_CatalogEntry extends Class_WebService_BibNumerique_R
foreach ($this->_files as $file)
$file->newRessourceInAlbum($album);
return $this;
}
......
......@@ -16,7 +16,7 @@
*
* 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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_WebService_OPDS_CatalogReader {
......@@ -57,7 +57,7 @@ class Class_WebService_OPDS_CatalogReader {
public function getSearch() {
if (null != $this->_search)
if (null != $this->_search)
return $this->_search;
if (null != $this->_searchUrl)
......@@ -85,7 +85,7 @@ class Class_WebService_OPDS_CatalogReader {
public function startLink($attributes) {
if (!array_key_exists('TYPE', $attributes))
if (!array_key_exists('TYPE', $attributes))
return;
if (!$this->_xml_parser->inParents('entry')) {
......@@ -114,8 +114,8 @@ class Class_WebService_OPDS_CatalogReader {
|| false != strpos($attributes['REL'], 'acquisition'))) {
$this->_current_entry->beNotice();
if (in_array($attributes['TYPE'], array('application/epub+zip', 'application/pdf')))
$this->_current_entry->addFile($attributes['HREF'], $attributes['TYPE']);
return;
return $this->_current_entry->addFile($attributes['HREF'], $attributes['TYPE']);
return $this->_current_entry->setLink($attributes['HREF']);
}
if (array_key_exists('REL', $attributes) && $attributes['REL'] == 'start') {
......@@ -185,22 +185,22 @@ class Class_WebService_OPDS_CatalogReader {
protected function _concatMetadata($name, $value, $separator = ' - ') {
$this->_metadatas[$name] = (isset($this->_metadatas[$name]))
$this->_metadatas[$name] = (isset($this->_metadatas[$name]))
? $this->_metadatas[$name] . $separator . $value
: $value;
}
protected function _normalizeUrl($url) {
if (!$this->_selfUrl)
if (!$this->_selfUrl)
return $url;
if ('http' == substr($url, 0, 4))
if ('http' == substr($url, 0, 4))
return $url;
$urlInfos = parse_url($this->_selfUrl);
$normalized = $urlInfos['scheme'] . '://' . $urlInfos['host'];
if ('/' == substr($url, 0, 1))
if ('/' == substr($url, 0, 1))
return $normalized . $url;
return $normalized . dirname($urlInfos['path']) . $url;
}
......
<?php
/**
* Copyright (c) 2012-2021, 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 Mobidys_Batch extends Class_DigitalResource_Batch {}
<?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 Mobidys_Config extends Class_DigitalResource_Config {
protected function _getConfig() {
return ['Introduction' => $this->_('Mobidys'),
'HelpLink' => 'http://wiki.bokeh-library-portal.org/index.php/Mobidys',
'Url' => 'http://mobidys.com',
'Icon' => 'https://www.mobidys.com/wp-content/uploads/2020/09/logo-Mobidys-orange-simple.png',
'PermissionLabel' => $this->_('Bibliothèque numérique: accéder à la ressource Mobidys'),
'NotAllowedMessage' => $this->_('Votre compte n\'est pas autorisé à accéder à cette ressource.'),
'SsoAction' => true,
'Harvesting' => true,
'MenuLabel' => $this->_('Lien vers Mobidys'),
'ModuleMenu' => $this->withNameSpace('ModuleMenu'),
'Service' => $this->withNameSpace('Service'),
'Batch' => $this->withNameSpace('Batch'),
'DocTypeLabel' => $this->_('Mobidys'),
'AdminVars' => [
'Harvest_Url' => Class_AdminVar_Meta::newDefault($this->_('URL du flux OPDS pour le moissonage de Mobidys'), ['value' => '']),
'SSO_URL' => Class_AdminVar_Meta::newDefault($this->_('URL SSO de la plateforme Mobidys'),
['value' => ''])->bePrivate()]
];
}
public function isEnabled() {
return '' != $this->getAdminVar('SSO_URL')
&& $this->getOPDSUrl()
&& ((new ZendAfi_Validate_Url())->isValid($this->getOPDSUrl()));
}
public function getSsoUrl($user) {
if(!$user)
return '';
return $this->getAdminVar('SSO_URL')
. '?ticket='
. (new Class_CasTicket())->getTicketForUser($user);
}
public function getAlbumSsoUrl($user, $album) {
if(!$album)
return '';
return $album->getExternalUri()
. '?ticket='
. (new Class_CasTicket())->getTicketForUser($user);
}
public function getOPDSUrl() {
return $this->getAdminVar('Harvest_Url');
}
public function getHarvestUrl($page = 1) {
$query = ['lang' => 'fr'];
// not working in real life with parameters :
// 'format' => 'OPDS'
$url = $this->getAdminVar('Harvest_Url');
return $url . '?' . http_build_query(array_filter($query));
}
}
<?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 Mobidys_ModuleMenu extends Class_DigitalResource_ModuleMenu {}
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2021, 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 Mobidys_Service extends Class_DigitalResource_Service {
public function getPageCount() {
return 1;
}
public function getRessourcesNumeriques() {
return $this->_parser->getEntries();
}
public function loadPage($page_number = 1) {
$opds = $this->httpGet($this->_config->getHarvestUrl($page_number));
$this->_parser = (new Mobidys_Service_Parser)->parse($opds);
return $this;
}
}
<?php
/**
* Copyright (c) 2012-2021, 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 Mobidys_Service_Album extends Class_WebService_OPDS_CatalogEntry {
public function setId($id) {
$this->_id = $id;
return $this;
}
public function matchId($other_id) {
return $this->getId() === $other_id;
}
public function getBaseUrl() {
return Mobidys_Config::getInstance()->getAdminVar('SSO_URL');
}
protected function getTypeDoc() {
return Mobidys_Config::getInstance()->getDocType();
}
public function fillAlbum($album) {
parent::fillAlbum($album);
$album->setTypeDocId($this->getTypeDoc());
return $this;
}
public function setAuthor($author) {
return $this->addAuthor($author);
}
public function getRessourceCategorieLibelle() {
return Mobidys_Config::getInstance()->getDocTypeLabel();
}
public function setLink($link) {
return $this->setExternalUri($link);
}
}
<?php
/**
* Copyright (c) 2012-2021, 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 Mobidys_Service_Parser extends Class_WebService_OPDS_CatalogReader {
protected
$_albums = [];
public function startEntry($attributes) {
$this->_current_entry = new Mobidys_Service_Album();
return $this;
}
public function endEntry() {
$this->_albums[] = $this->_current_entry;
return $this;
}
public function getEntries() {
return $this->_albums;
}
public function endSource($data) {
return $this->_current_entry->setExternalUri($data);
}
public function endId($data) {
if (!$this->_xml_parser->inParents('entry'))
return $this;
$this->_current_entry->setId($data);
return $this;
}
public function endUpdated($data) {
if (!$this->_xml_parser->inParents('entry'))
return;
return $this->_current_entry->setYear(date('Y', strtotime($data)));
}
}
<?php
/**
* Copyright (c) 2012-2021, 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 Mobidys_View_Helper_Album extends Class_DigitalResource_AlbumViewHelper {}
<?php
/**
* Copyright (c) 2012-2021, 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 Mobidys_Plugin_IndexController extends Class_DigitalResource_Controller {}
<?php
/**
* Copyright (c) 2012-2021, 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
*/
abstract class MobidysActivatedTestCase extends AbstractControllerTestCase {
protected
$_storm_default_to_volatile = true,
$_user;
public function setUp() {
parent::setUp();
Class_AdminVar::set('Mobidys_SSO_URL', 'https://app.mobidys.org/mybib');
Class_AdminVar::set('Mobidys_Harvest_Url', 'http://backend.mobidys.com/opds');
$http_client = $this->mock()
->whenCalled('open_url')
->with('http://backend.mobidys.com/opds?lang=fr')
->answers(file_get_contents(__DIR__ . '/mobidys.opds'))
->beStrict();
Mobidys_Service::setDefaultHttpClient($http_client);
$group = $this->fixture('Class_UserGroup',
['id' => 1,
'libelle' => 'Digital resources']);
$this->_user = $this->fixture('Class_Users',
['id' => 1,
'login' => 'Tom',
'password' => 'pwd'])
->setUserGroups([$group]);
$this->fixture('Class_Permission',
['id' => 1,
'code' => 'Mobidys'])
->permitTo($group, new Class_Entity());
}
}
class MobidysHarvestTest extends MobidysActivatedTestCase {
protected $_album;
public function setUp() {
parent::setUp();
$ressource = Mobidys_Service::getInstance();
$ressource->harvest();
$this->_album = Class_Album::find(2);
$this->_album->index();
}
public function getAlbumAttribs() {
return [
['getTitre', 'A l\'intérieur de moi'],
['getIdOrigine', 'Interieur_de_moi'],
['getExternalUri', 'https://app.bibliodyssee.com/land/BM_29_Landerneau/product/1016'],
['getAnnee', '2021'],
['getDescription', 'Pour les tout-petits, un livre d\'éveil sensible et artistique, ouvert sur le monde qui les entoure.
Mots-clés : Emotion'],
['getTypeDocId' , 'Mobidys'],
['getCategoryLabel', 'Mobidys'],
['getPoster', 'https://d1ye1pkjd8d7nc.cloudfront.net/public_item/0001/05/4f2ee613e70ba86a9f75315766ae55db7dc669df.jpeg'],
['getMainAuthorName', 'Aurélia Gaud'],
];
}
/**
* @test
* @dataProvider getAlbumAttribs
*/
public function albumAttribsShouldMatch($key, $value) {
$this->assertEquals($value, call_user_func([$this->_album, $key]));
}
}
class MobidysSsoTest extends MobidysActivatedTestCase {
public function setUp() {
parent::setUp();
$user= $this->fixture('Class_Users',
['id' => 10,
'login' => 'Tom',
'password' => 'pwd']);
$this->fixture('Class_Album',
['id' => 1,
'titre' => 'mobidys album title',
'type_doc_id' => Mobidys_Config::getInstance()->getDocType(),
'id_origine' => 'zork666',
'external_uri' => 'http://app.mobidys/myalbum']);
}
/** @test */
public function userWithRoleInviteShouldNotHaveAccessToModulesMobidys() {
ZendAfi_Auth::getInstance()->logUser(Class_Users::find(10));
$this->dispatch('/opac/modules/mobidys', true);
$this->assertFlashMessengerContentContains('Votre compte n\'est pas autorisé à accéder à cette ressource.');
}
/** @test */
public function userValidShouldBeRedirectToMobidys() {
ZendAfi_Auth::getInstance()->logUser($this->_user);
$this->dispatch('/opac/modules/mobidys', true);
$this->assertXPathContentContains('//script','https://app.mobidys.org/mybib?ticket=');
}
/** @test */
public function userValidShouldBeRedirectToMobidysAlbum() {
ZendAfi_Auth::getInstance()->logUser($this->_user);
$this->dispatch('/opac/modules/mobidys/album_id/1', true);
$this->assertXPathContentContains('//script','http://app.mobidys/myalbum?ticket=');