diff --git a/application/modules/admin/controllers/HarvestController.php b/application/modules/admin/controllers/HarvestController.php index c9b742e4e8f346ffbc7f959a8e9c20d53d3d0367..83438153be8319d15dd3dcce7854853b0ea190e9 100644 --- a/application/modules/admin/controllers/HarvestController.php +++ b/application/modules/admin/controllers/HarvestController.php @@ -54,13 +54,14 @@ class Admin_HarvestController extends Zend_Controller_Action { $this->view->titre = $this->view->_(sprintf('Moissonnage %s', $this->_service->getName())); } - + protected function getServices() { return ['arte-vod' => new Class_WebService_BibNumerique_ArteVOD(), 'vodeclic' => new Class_WebService_BibNumerique_Vodeclic(), 'toutapprendre' => new Class_WebService_BibNumerique_ToutApprendre(), 'numilog' => new Class_WebService_BibNumerique_Numilog(), + 'cyberlibris' => new Class_WebService_BibNumerique_Cyberlibris(), 'numerique-premium' => new Class_WebService_BibNumerique_NumeriquePremium()]; } @@ -108,16 +109,16 @@ class Admin_HarvestController extends Zend_Controller_Action { $logger = new Zend_Log(); $logger->addWriter(new Zend_Log_Writer_Stream('php://output')); - + ob_start(); $logger->info('Début du moissonnage'); - + $service->setLogger($logger); $service->harvest(); (new Storm_Cache())->clean(); $logger->info('Fin du moissonnage'); - + $this->view->log = ob_get_clean(); } } diff --git a/application/modules/admin/controllers/UsergroupController.php b/application/modules/admin/controllers/UsergroupController.php index d7a112681daeedf254db5f5c3ec32843c323a73a..cf59ba96b19e26f7860f3009be88ed7608419789 100644 --- a/application/modules/admin/controllers/UsergroupController.php +++ b/application/modules/admin/controllers/UsergroupController.php @@ -163,6 +163,7 @@ class Admin_UsergroupController extends ZendAfi_Controller_Action { $this->displayGroupFiltreVisibleOnlyOnDynamicGroup(); $rights = Class_UserGroup::getActivatedRightDefinitionList(); + asort($rights); $form diff --git a/application/modules/admin/views/scripts/batch/index.phtml b/application/modules/admin/views/scripts/batch/index.phtml index 3193b38b3bd0040a1841dd157a600aa77563540e..82895d83116c1e489bfb722f391cb8b0ff2efe40 100644 --- a/application/modules/admin/views/scripts/batch/index.phtml +++ b/application/modules/admin/views/scripts/batch/index.phtml @@ -13,6 +13,9 @@ echo $this->tagModelTable( [ ['action' => 'delete', 'content' => $this->boutonIco('type=del')], function($batch) { + if ('MOISSONNAGE_CYBERLIBRIS' == $batch->getType()) + return ''; + $action = (in_array($batch->getType(), ['AUTOCOMPLETE_RECORD_TITLE', 'AUTOCOMPLETE_RECORD_AUTHOR'])) ? 'run-ajax' : 'run'; diff --git a/cosmogramme/php/_init.php b/cosmogramme/php/_init.php index 3124a73eab364b47f9aaacede2143f7eed726ec5..b87ef6fc23eb29a4bd966e305ec7df3ea934442f 100644 --- a/cosmogramme/php/_init.php +++ b/cosmogramme/php/_init.php @@ -2,7 +2,7 @@ // Constantes error_reporting(E_ERROR | E_PARSE); define("VERSION_COSMOGRAMME","6.52"); -define("PATCH_LEVEL","206"); +define("PATCH_LEVEL","209"); define("APPLI","cosmogramme"); define("COSMOPATH", "/var/www/html/vhosts/opac2/www/htdocs"); diff --git a/cosmogramme/php/integration/pseudo_notices.php b/cosmogramme/php/integration/pseudo_notices.php index 8154d7e8ebd0f00e42f6267756535de314c73128..e580f04ca45d195d9ddaf95c0503475648e018d6 100644 --- a/cosmogramme/php/integration/pseudo_notices.php +++ b/cosmogramme/php/integration/pseudo_notices.php @@ -46,7 +46,11 @@ if ($phase > 0 and $phase < 0.2) { continue; $log->ecrire('<span class="vert">'.$batch->getLibelle().':'); $phase_data["pointeur_reprise"]=$batch->getId(); - $batch->run(); + if ('MOISSONNAGE_CYBERLIBRIS' != $batch->getType() || $mode_cron) { + $batch->run(); + } else { + $log->ecrire('Ce batch n\'est traité qu\'en mode cron'); + } $log->ecrire(' OK</span><br/>'); $log->ecrire('<span class="vert">Temps de traitement : ' . $chrono->end() .'</span>'); } diff --git a/cosmogramme/sql/patch/patch_209.php b/cosmogramme/sql/patch/patch_209.php new file mode 100644 index 0000000000000000000000000000000000000000..89e8168e659ecc6ded5ee158cdd207489d63efb7 --- /dev/null +++ b/cosmogramme/sql/patch/patch_209.php @@ -0,0 +1,4 @@ +<?php +Class_CosmoVar::addLabelInList('types_docs', 111, 'Cyberlibris'); +?> + diff --git a/library/Class/AdminVar.php b/library/Class/AdminVar.php index 8128c602679eef3c924e73243f58da0240585c07..e01a388ef3f01b6fd7070055587322d090a5e419 100644 --- a/library/Class/AdminVar.php +++ b/library/Class/AdminVar.php @@ -169,6 +169,14 @@ class Class_AdminVar extends Storm_Model_Abstract { } + /** + * @return bool + */ + public static function isCyberlibrisEnabled() { + return ('' != self::get('CYBERLIBRIS_URL') ); + } + + /** * @return bool */ @@ -309,6 +317,7 @@ class Class_AdminVar extends Storm_Model_Abstract { 'NUMILOG_URL' => 'Paramétrage <a href="http://forge.afi-sa.fr/projects/opac3/wiki/Ressources_externes_enrichissements#Numilog">Numilog</a>', 'NUMILOG_OAI_URL' => 'Paramétrage <a href="http://forge.afi-sa.fr/projects/opac3/wiki/Ressources_externes_enrichissements#Numilog">Numilog</a>', 'NUMILOG_OAI_IDBIB' => 'Paramétrage <a href="http://forge.afi-sa.fr/projects/opac3/wiki/Ressources_externes_enrichissements#Numilog">Numilog</a>', + 'CYBERLIBRIS_URL' => 'Adresse du serveur OAI Cyberlibris', 'OAI_SERVER' => 'Activation du serveur OAI. 0 = inactif, 1 = actif', 'PACK_MOBILE' => 'Activation des fonctions avancées du téléphone. 0 = inactif, 1 = actif', 'ARTE_VOD_LOGIN' => 'Login ARTE VOD', diff --git a/library/Class/Album.php b/library/Class/Album.php index 43d55ed567292e012ee033e38db6639cd95da4d4..2f384c8999612c312206240636254b46886bd8ce 100644 --- a/library/Class/Album.php +++ b/library/Class/Album.php @@ -55,8 +55,11 @@ class AlbumLoader extends Storm_Model_Loader { public function getItemsOf($categoryId) { - return Class_Album::findAllBy(['cat_id' => $categoryId, - 'order' => 'titre']); + return Class_Album::findAllBy([ + 'cat_id' => $categoryId, + 'order' => 'titre', + 'limit' => 1000 + ]); } } @@ -399,11 +402,17 @@ class Class_Album extends Storm_Model_Abstract { return $this->setTypeDocId(Class_TypeDoc::ARTEVOD); } + public function beNumilog() { return $this->setTypeDocId(Class_TypeDoc::NUMILOG); } + public function beCyberlibris() { + return $this->setTypeDocId(Class_TypeDoc::CYBERLIBRIS); + } + + public function beNumeriquePremium() { return $this->setTypeDocId(Class_TypeDoc::NUMERIQUEPREMIUM); } @@ -413,6 +422,10 @@ class Class_Album extends Storm_Model_Abstract { } + public function isCyberlibris() { + return $this->getTypeDocId() == Class_TypeDoc::CYBERLIBRIS; + } + public function beFormationVodeclic() { return $this->setTypeDocId(Class_TypeDoc::VODECLIC); diff --git a/library/Class/Batch.php b/library/Class/Batch.php index df2f91db0fc94fa3ea6a47c25d5dc524f42ab608..bcde0edf615531c3015ee4a3a3d64a165dbf76d2 100644 --- a/library/Class/Batch.php +++ b/library/Class/Batch.php @@ -38,6 +38,7 @@ class Class_BatchLoader extends Storm_Model_Loader{ 'MOISSONNAGE_ARTEVOD' => new Class_Batch_ArteVOD(), 'MOISSONNAGE_NUMERIQUEPREMIUM' => new Class_Batch_NumeriquePremium(), 'MOISSONNAGE_NUMILOG' => new Class_Batch_Numilog(), + 'MOISSONNAGE_CYBERLIBRIS' => new Class_Batch_Cyberlibris(), 'MOISSONNAGE_TOUTAPPRENDRE' => new Class_Batch_ToutApprendre() ]; } diff --git a/library/Class/Batch/Cyberlibris.php b/library/Class/Batch/Cyberlibris.php new file mode 100644 index 0000000000000000000000000000000000000000..bc0b206d23e431f48f60b52a62770c63921a0bb8 --- /dev/null +++ b/library/Class/Batch/Cyberlibris.php @@ -0,0 +1,28 @@ +<?php +/** + * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 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). + * + * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_Batch_Cyberlibris extends Class_Batch_RessourceNumerique{ + protected function _getService() { + return new Class_WebService_BibNumerique_Cyberlibris(); + } +} +?> \ No newline at end of file diff --git a/library/Class/CosmoVar.php b/library/Class/CosmoVar.php index 9378c7ef39312bfa68ab97376418d797a95c6608..1ec58be04e2046c72a74d89952102b12413860ef 100644 --- a/library/Class/CosmoVar.php +++ b/library/Class/CosmoVar.php @@ -41,6 +41,34 @@ class Class_CosmoVarLoader extends Storm_Model_Loader { } return ''; } + + public function updateLabelInList($value ,$label ,$list) { + $new_list=[]; + foreach (explode(chr(13).chr(10), $list) as $line) { + $parts = explode(':', $line); + if ($value == $parts[0]) + $parts[1]=$label; + $new_list[]=implode(':', $parts); + } + return implode('\r\n',$new_list); + } + + + public function addLabelInList($name, $value, $label) { + if (!$model = Class_CosmoVar::find($name)) + return false; + + $liste = $model->getListe(); + + if (strpos($liste, "\r\n$value:") !== false) + $liste=$this->updateLabelInList($value,$label,$liste); + else + $liste .= "\r\n$value:$label"; + + $model->setListe($liste)->save(); + + return $this; + } } diff --git a/library/Class/TypeDoc.php b/library/Class/TypeDoc.php index 1a75d6726e29b53729ad610f8b7ab3aeb712e6fc..f72bed597f0c5284e15eb645b80a08d90541d133 100644 --- a/library/Class/TypeDoc.php +++ b/library/Class/TypeDoc.php @@ -27,6 +27,11 @@ class TypeDocLoader extends Storm_Model_Loader { } + public function getCurrentMaxId() { + return max(array_keys($this->_all_instances)); + } + + public function newInstance($attributes = null) { $instance = new Class_TypeDoc(); @@ -183,6 +188,7 @@ class Class_TypeDoc extends Storm_Model_Abstract { const TOUTAPPRENDRE = 108; const AUDIO_RECORD = 109; const NUMERIQUEPREMIUM = 110; + const CYBERLIBRIS = 111; public static function getDefaultTypeDocs() { @@ -204,7 +210,8 @@ class Class_TypeDoc extends Storm_Model_Abstract { self::CVS => 'Vidéos à la demande', self::TOUTAPPRENDRE => 'Cours en ligne', self::AUDIO_RECORD => 'Enregistrement audio', - self::NUMERIQUEPREMIUM => 'Numérique Premium']; + self::NUMERIQUEPREMIUM => 'Numérique Premium', + self::CYBERLIBRIS => 'Cyberlibris']; } diff --git a/library/Class/UserGroup.php b/library/Class/UserGroup.php index 6e9e71dfdb2fb84c9938c963babfe84801fad515..d399fc2063f161bd5bea558e599ecf82f6cabc49 100644 --- a/library/Class/UserGroup.php +++ b/library/Class/UserGroup.php @@ -42,6 +42,7 @@ class Class_UserGroup extends Storm_Model_Abstract { const RIGHT_ACCES_MUSICME = 7; const RIGHT_ACCES_NUMERIQUEPREMIUM = 20; const RIGHT_ACCES_LEKIOSK = 21; + const RIGHT_ACCES_CYBERLIBRIS = 22; // droits moderateurs const RIGHT_USER_DOMAINES_SUPPRESSION_LIMIT = 8; @@ -68,6 +69,7 @@ class Class_UserGroup extends Storm_Model_Abstract { self::RIGHT_DIRIGER_FORMATION => 'Formations: diriger une formation' , self::RIGHT_ACCES_ARTEVOD => 'Bibliothèque numérique: accéder à ARTE VOD', self::RIGHT_ACCES_NUMILOG => 'Bibliothèque numérique: accéder à Numilog', + self::RIGHT_ACCES_CYBERLIBRIS => 'Bibliothèque numérique: accéder à Cyberlibris', self::RIGHT_ACCES_CVS => 'Bibliothèque numérique: accéder à CVS', self::RIGHT_ACCES_VODECLIC => 'Bibliothèque numérique: accéder à Vodéclic', self::RIGHT_ACCES_TOUTAPPRENDRE => 'Bibliothèque numérique: accéder à Tout Apprendre', diff --git a/library/Class/WebService/BibNumerique/Abstract.php b/library/Class/WebService/BibNumerique/Abstract.php index c719d78f399f114b28f6773567b56ca095637d87..66d6e9c40bf7926542a13d3c064e872501651ce0 100644 --- a/library/Class/WebService/BibNumerique/Abstract.php +++ b/library/Class/WebService/BibNumerique/Abstract.php @@ -61,7 +61,7 @@ abstract class Class_WebService_BibNumerique_Abstract extends Class_WebService_A $this->getLogger()->info(sprintf('Traitement de la page %s / %s', $current_page, $total_page)); - $ress_numerique=$reader->getRessourcesNumeriques(); + $ress_numerique = $reader->getRessourcesNumeriques(); $this->_harvested_ids = array_merge($this->_harvested_ids, $this->_importRessources($ress_numerique)); $current_page++; diff --git a/library/Class/WebService/BibNumerique/Cyberlibris.php b/library/Class/WebService/BibNumerique/Cyberlibris.php new file mode 100644 index 0000000000000000000000000000000000000000..c825d695b7c8e846fa99aba271f896c5e28c6610 --- /dev/null +++ b/library/Class/WebService/BibNumerique/Cyberlibris.php @@ -0,0 +1,66 @@ +<?php +/** + * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 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). + * + * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_WebService_BibNumerique_Cyberlibris extends Class_WebService_BibNumerique_Abstract { + + const BASE_URL = 'http://oai-bibliovox.cyberlibris.fr/oai.aspx'; + const CATEGORY_LABEL = 'Cyberlibris'; + + + protected function _deleteNonHarvested() { + if (0 < count($this->getHarvestedIds())) + Class_Album::getLoader() + ->deleteBy(['where' => 'url_origine="'.self::BASE_URL.'" and id_origine not in (\'' . implode("', '", $this->getHarvestedIds()) . '\')']); + } + + + protected function _importRessources($ressources) { + $harvestedIds = []; + $this->_albums = []; + foreach ($ressources as $ressource) { + $harvestedIds[] = $ressource->getId(); + if ($ressource->isAlreadyHarvested()) + continue; + + $this->_albums[] = $ressource->import(); + } + return $harvestedIds; + } + + + protected function loadPage($page_number = 1) { + $reader = (new Class_WebService_BibNumerique_Cyberlibris_LivresNumeriquesReader()); + $reader->parse(); + return $reader; + } + + + public function isEnabled() { + return Class_AdminVar::isCyberlibrisEnabled(); + } + + + public function getName() { + return 'Cyberlibris'; + } +} +?> \ No newline at end of file diff --git a/library/Class/WebService/BibNumerique/Cyberlibris/LivreNumerique.php b/library/Class/WebService/BibNumerique/Cyberlibris/LivreNumerique.php new file mode 100644 index 0000000000000000000000000000000000000000..52480584249f6c13044309fe5c0305441e194950 --- /dev/null +++ b/library/Class/WebService/BibNumerique/Cyberlibris/LivreNumerique.php @@ -0,0 +1,53 @@ +<?php +/** + * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 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). + * + * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_WebService_BibNumerique_Cyberlibris_LivreNumerique extends Class_WebService_BibNumerique_RessourceNumerique { + protected $_record; + protected $_titre; + + + public function getBaseUrl(){ + return Class_WebService_BibNumerique_Cyberlibris::BASE_URL; + } + + + public function fillAlbum($album) { + $album->beCyberlibris() + ->setDescription($this->getDescription()) + ->setEditeur($this->getEditeur()); + foreach($this->getAuthors() as $author) + $album->addAuthor($author); + return $album; + } + + + public function getRessourceCategorieLibelle() { + return Class_WebService_BibNumerique_Cyberlibris::CATEGORY_LABEL; + } + + public function setOaiId($data) { + $result = split('=', $data); + $this->_id = ($result) ? $result[1] : ''; + $this->setExternalURI($data); + } +} +?> \ No newline at end of file diff --git a/library/Class/WebService/BibNumerique/Cyberlibris/LivresNumeriquesReader.php b/library/Class/WebService/BibNumerique/Cyberlibris/LivresNumeriquesReader.php new file mode 100644 index 0000000000000000000000000000000000000000..91db13fc46bcfcbddef956ef7a6d461721c9907e --- /dev/null +++ b/library/Class/WebService/BibNumerique/Cyberlibris/LivresNumeriquesReader.php @@ -0,0 +1,87 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 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). + * + * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_WebService_BibNumerique_Cyberlibris_LivresNumeriquesReader extends Class_WebService_DublinCoreParser { + protected $_total_count; + protected $_page_number; + protected $_page_size; + protected $_ressourcesNumeriques; + protected $livres; + protected $_logger; + + + public function getLogger() { + if (null == $this->_logger) + return new Zend_Log(new Zend_Log_Writer_Null()); + return $this->_logger; + } + + + public function parse() { + $this->_total_count = $this->_page_number = 0; + $this->_page_size = 1; + $this->livres = []; + $url = Class_AdminVar::get('CYBERLIBRIS_URL'); + $oaiws = new Class_WebService_OAI(); + + $listsize = ($this->_resumptionToken) ? $this->_resumptionToken->getListSize() : '100'; + $this->getLogger()->info($listsize .' ressources dans la base'); + $this->livres = $oaiws + ->setOAIHandler($url) + ->setNumericResourceClass('Class_WebService_BibNumerique_Cyberlibris_LivreNumerique') + ->getRecordsResourcesNumerique(); + + while ($oaiws->hasNextRecords()) + $this->livres = array_merge($this->livres, $oaiws->getNextNumericResources()); + + $this->_total_count = sizeof($this->livres); + $this->_page_number = 1; + $this->_page_size = $this->_total_count; + return $this; + } + + + public function getTotalCount() { + return $this->_total_count; + } + + + public function getPageNumber() { + return $this->_page_number; + } + + + public function getPageCount() { + return ceil($this->_total_count / $this->_page_size); + } + + + public function setRecords($records) { + $this->livres=$records; + } + + + public function getRessourcesNumeriques() { + return $this->livres; + } + +} diff --git a/library/Class/WebService/BibNumerique/Numilog.php b/library/Class/WebService/BibNumerique/Numilog.php index 7b04715e1d7040dab743c8feee9dcb8f06e2ca20..d1b5199604a6bd220532e92641ac9c3728d607c5 100644 --- a/library/Class/WebService/BibNumerique/Numilog.php +++ b/library/Class/WebService/BibNumerique/Numilog.php @@ -64,9 +64,6 @@ class Class_WebService_BibNumerique_Numilog extends Class_WebService_BibNumeriqu $id_bib = Class_AdminVar::get('NUMILOG_OAI_IDBIB'); $content = $this->open_oai_url($url); - $builder = new Class_Xml_Builder(); - - $reader = $this->getRessourcesNumeriquesReader()->parse($content); if (1 == $page_number) $this->getLogger()->info($reader->getTotalCount() .' ressources dans la base'); diff --git a/library/Class/WebService/BibNumerique/LivreNumerique.php b/library/Class/WebService/BibNumerique/Numilog/LivreNumerique.php similarity index 87% rename from library/Class/WebService/BibNumerique/LivreNumerique.php rename to library/Class/WebService/BibNumerique/Numilog/LivreNumerique.php index 02132ffbcbc0838cc0153640e0a3eaa03a118e25..50415ff877e16dc5740b088847c58c6558511041 100644 --- a/library/Class/WebService/BibNumerique/LivreNumerique.php +++ b/library/Class/WebService/BibNumerique/Numilog/LivreNumerique.php @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -class Class_WebService_BibNumerique_LivreNumerique extends Class_WebService_BibNumerique_RessourceNumerique { +class Class_WebService_BibNumerique_Numilog_LivreNumerique extends Class_WebService_BibNumerique_RessourceNumerique { protected $_record; protected $_titre; @@ -35,6 +35,7 @@ class Class_WebService_BibNumerique_LivreNumerique extends Class_WebService_BibN ->setEditeur($this->getEditeur()); foreach($this->getAuthors() as $author) $album->addAuthor($author); + $this->addPoster('http://couverture.numilog.com/' . $this->_id.'_GRANDE.jpg'); return $album; } diff --git a/library/Class/WebService/BibNumerique/RessourceNumerique.php b/library/Class/WebService/BibNumerique/RessourceNumerique.php index dc7801e81cc00e38c22fc916838563f850ea9a39..e211706d78a4f01311e9d7b6814f39397e5f57d6 100644 --- a/library/Class/WebService/BibNumerique/RessourceNumerique.php +++ b/library/Class/WebService/BibNumerique/RessourceNumerique.php @@ -321,7 +321,6 @@ return; $explode_id=explode(':',$id); $this->_id=$explode_id[count($explode_id)-1]; - $this->addPoster('http://couverture.numilog.com/'.$this->_id.'_GRANDE.jpg'); } diff --git a/library/Class/WebService/DublinCoreParser.php b/library/Class/WebService/DublinCoreParser.php index 1da3c7f9e49a3e53d96d34c8108935dfab6a4d70..bd3683afbcc72ef59fd23945c7365687b7af66b7 100644 --- a/library/Class/WebService/DublinCoreParser.php +++ b/library/Class/WebService/DublinCoreParser.php @@ -32,10 +32,11 @@ class Class_WebService_DublinCoreParser { protected $ressource_numerique; protected $_records_ressources; protected $visitor; + public function __construct() { - $this->_records = array(); + $this->_records = []; $this->_records_ressources = []; - $this->class_ressource_numerique=new Class_WebService_BibNumerique_RessourceNumerique(); + $this->class_ressource_numerique = new Class_WebService_BibNumerique_RessourceNumerique(); $this->visitor = $this; } diff --git a/library/Class/WebService/OAI.php b/library/Class/WebService/OAI.php index bc799d19c6f5b2ea86d1e37e2a2b3b9970ba2f83..b0ec108703e529ee02580d4d08d7d7dc9140c1bf 100644 --- a/library/Class/WebService/OAI.php +++ b/library/Class/WebService/OAI.php @@ -39,7 +39,8 @@ class Class_WebService_OAI extends Class_WebService_Abstract { protected static $_default_web_client; protected $web_client; - + protected $numeric_resource_class = 'Class_WebService_BibNumerique_Numilog_LivreNumerique'; + protected $_listRecordsResumptionToken; const ListSets = 'ListSets'; const ListRecords = 'ListRecords'; @@ -68,6 +69,17 @@ class Class_WebService_OAI extends Class_WebService_Abstract { } + public function setNumericResourceClass($classname) { + $this->numeric_resource_class = $classname; + return $this; + } + + + public function getNumericResourceClass() { + return $this->numeric_resource_class; + } + + public function getContent($url) { return $this->getWebClient()->open_url($url); } @@ -111,8 +123,17 @@ class Class_WebService_OAI extends Class_WebService_Abstract { } - public function getRecordsFromSet($set) { + public function getRecordsResourcesNumerique() { $xml_data = $this->oaiAsks(self::ListRecords, + array('metadataPrefix' => 'oai_dc' + )); + return $this->parseListRecordsRessourcesNumeriqueXML($xml_data); + + } + + + public function getRecordsFromSet($set) { + $xml_data = $this->oaiAsks(self::ListRecords, array('metadataPrefix' => 'oai_dc', 'set' => $set)); return $this->parseListRecordsXML($xml_data); @@ -120,7 +141,6 @@ class Class_WebService_OAI extends Class_WebService_Abstract { public function parseListRecordsXML($xml_data) { - $parser = new Class_WebService_DublinCoreParser(); $parser->parse($xml_data); $this->setListRecordsResumptionToken($parser->getResumptionToken()); @@ -132,15 +152,18 @@ class Class_WebService_OAI extends Class_WebService_Abstract { $parser = new Class_WebService_DublinCoreParser(); $parser->acceptVisitor($this); $parser->parseRessourcesNumeriques($xml_data); + $this->setListRecordsResumptionToken($parser->getResumptionToken()); return $parser->getRecordsRessourceNumeriques(); } + public function getNewRessourceNumerique() { - return new Class_WebService_BibNumerique_LivreNumerique(); + return new $this->numeric_resource_class; } public function hasNextRecords() { + if (!$this->getListRecordsResumptionToken()) return false; return ($this->getListRecordsResumptionToken()->getToken() != null); } @@ -154,6 +177,14 @@ class Class_WebService_OAI extends Class_WebService_Abstract { return $this->parseListRecordsXML($xml_data); } + public function getNextNumericResources() { + if (!$this->hasNextRecords()) + return array(); + $xml_data = $this->oaiAsks( + self::ListRecords, + array('resumptionToken' => $this->getListRecordsResumptionToken()->getToken())); + return $this->parseListRecordsRessourcesNumeriqueXML($xml_data); + } public function setListRecordsResumptionToken($token) { $this->_listRecordsResumptionToken = $token; diff --git a/library/Class/WebService/OAI/Numilog.php b/library/Class/WebService/OAI/Numilog.php deleted file mode 100644 index 3dcd753e0a13a71588d09504e6b8d13a14280589..0000000000000000000000000000000000000000 --- a/library/Class/WebService/OAI/Numilog.php +++ /dev/null @@ -1,149 +0,0 @@ -<?php -/** - * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. - * - * AFI-OPAC 2.0 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). - * - * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -////////////////////////////////////////////////////////////////////////////////////////// -// OPAC3 - Interrogation dépôts Open Archives Initiative -// -// Voir l'exploreur: http://re.cs.uct.ac.za/ -// Lister toutes les ensembles de Gallica: http://oai.bnf.fr/oai2/OAIHandler?verb=ListSets -// Lister toutes les notices de l'ensemble gallica:5:54 : http://oai.bnf.fr/oai2/OAIHandler?verb=ListRecords&metadataPrefix=oai_dc&set=gallica:5:54 -// Outil Repository Explorer, très utile: http://re.cs.uct.ac.za/ -////////////////////////////////////////////////////////////////////////////////////////// - -/* Permet d'aller chercher les données depuis un entrepôt OAI - * Utilisation: - * $oai_service = new Class_WebService_OAI() - * $oai_service->setOAIHandler('http://oai.bnf.fr/oai2/OAIHandler'); - * $oai_service->getSets() //retourne les sets sous forme de tableau associatifs - * $oai_service->getRecords('gallica'); //les 100 premiers records du set gallica - * while ($oai_service->hasNextRecords()) //prends les enregistrements suivants - * $oai->service->getNextRecords(); // tant qu'il y en a - */ -class Class_WebService_OAI_Numilog extends Class_WebService_OAI { - protected static $_default_web_client; - protected $web_client; - - const ListSets = 'ListSets'; - const ListRecords = 'ListRecords'; - - public static function baseURL() { - return 'http://' . $_SERVER['SERVER_NAME'] . BASE_URL . '/opac/oai/request'; - } - - - - public function setOAIHandler($oai_handler) { - $this->oai_handler = $oai_handler; - return $this; - } - - - - - public function listRecords() { - return $this->oaiAsks(self::ListSets, array()); - } - - - public function getSetsFromHandler($oai_handler) { - $this->setOAIHandler($oai_handler); - return $this->getSets(); - } - - - public function getRecords() { - /* Pour l'instant ne gère pas le resumptionToken, ça suffit pour la démo*/ - $xml_data = $this->listSets(); - $setspecs = array(); - $setnames = array(); - if (0==preg_match_all('/<setSpec>([^<]*)<\/setSpec>/i', $xml_data, $setspecs)) - return array(); - preg_match_all('/<setName>([^<]*)<\/setName>/i', $xml_data, $setnames); - - return array_combine($setspecs[1], $setnames[1]); - } - - - public function getRecordsFromHandlerAndSet($oai_handler, $set) { - $this->setOAIHandler($oai_handler); - return $this->getRecordsFromSet($set); - } - - - public function getRecordsFromSet($set) { - $xml_data = $this->oaiAsks(self::ListRecords, - array('metadataPrefix' => 'oai_dc', - 'set' => $set)); - return $this->parseListRecordsXML($xml_data); - } - - - protected function parseListRecordsXML($xml_data) { - $parser = new Class_WebService_DublinCoreParser(); - $parser->acceptVisitor($this); - $parser->parse($xml_data); - $this->setListRecordsResumptionToken($parser->getResumptionToken()); - return $parser->getRecords(); - } - - public function getNewRessourceNumerique() { - return new Class_WebService_BibNumerique_LivreNumerique(); - } - - public function hasNextRecords() { - return ($this->getListRecordsResumptionToken()->getToken() != null); - } - - - public function getNextRecords() { - if (!$this->hasNextRecords()) - return array(); - $xml_data = $this->oaiAsks( - self::ListRecords, - array('resumptionToken' => $this->getListRecordsResumptionToken()->getToken())); - return $this->parseListRecordsXML($xml_data); - } - - public function parseListRecordsRessourcesNumeriqueXML($xml_data) { - $parser = new Class_WebService_DublinCoreParser(); - $parser->acceptVisitor($this); - $parser->parseRessourcesNumeriques($xml_data); - return $parser->getRecordsRessourceNumeriques(); - } - - - public function setListRecordsResumptionToken($token) { - $this->_listRecordsResumptionToken = $token; - return $this; - } - - - public function getListRecordsResumptionToken() { - return $this->_listRecordsResumptionToken; - } - - - public function getTotalNumberOfRecords() { - if (!isset($this->_listRecordsResumptionToken)) return 0; - return $this->_listRecordsResumptionToken->getListSize(); - } -} - -?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Admin/MenuGaucheAdmin.php b/library/ZendAfi/View/Helper/Admin/MenuGaucheAdmin.php index 9da8a4481b0f3abfe55a8a05fe0327dfd73390d8..53b3e9a88184d9f2793931a0336dc408a16317a7 100644 --- a/library/ZendAfi/View/Helper/Admin/MenuGaucheAdmin.php +++ b/library/ZendAfi/View/Helper/Admin/MenuGaucheAdmin.php @@ -122,6 +122,12 @@ class ZendAfi_View_Helper_Admin_MenuGaucheAdmin extends ZendAfi_View_Helper_Base Class_AdminVar::isNumilogEnabled() && $this->filterAdmin($this->user)) + /* disabled until interactive harvesting is implemented + .$this->addMenu("oai_16.png", $this->translate()->_("Cyberlibris"), "/admin/harvest/cyberlibris-browse", + Class_AdminVar::isCyberlibrisEnabled() + && $this->filterAdmin($this->user)) + */ + .$this->addMenu("oai_16.png", $this->translate()->_("Tout Apprendre"), "/admin/harvest/toutapprendre-browse", Class_AdminVar::isToutApprendreEnabled() && $this->filterAdmin($this->user)) diff --git a/library/ZendAfi/View/Helper/RenderAlbum.php b/library/ZendAfi/View/Helper/RenderAlbum.php index b0538f7a8fa121094d66cc17d9723e55ae4b7b0b..277fc735400e80eff9ba4beeabf50874b810f6ee 100644 --- a/library/ZendAfi/View/Helper/RenderAlbum.php +++ b/library/ZendAfi/View/Helper/RenderAlbum.php @@ -34,7 +34,7 @@ class ZendAfi_View_Helper_RenderAlbum extends Zend_View_Helper_HtmlElement { return ''; } - if ($album->isNumilog()) + if ($album->isNumilog() || $album->isCyberlibris()) return $this->view->tagLivreNumerique($album); if ($album->isDiaporama() && $album->hasOnlyImages()) diff --git a/tests/application/modules/admin/controllers/UserGroupControllerTest.php b/tests/application/modules/admin/controllers/UserGroupControllerTest.php index 4b30d2613c9ca7ab03c9b3cfef23ef4f5322ed8d..e31a46a312a63f2b05c25f7ce8db6abae9361980 100644 --- a/tests/application/modules/admin/controllers/UserGroupControllerTest.php +++ b/tests/application/modules/admin/controllers/UserGroupControllerTest.php @@ -729,6 +729,22 @@ class Admin_UserGroupControllerRessourcesNumeriquesTest extends Admin_UserGroupC $this->dispatch('admin/usergroup/edit/id/6', true); $this->assertNotXPathContentContains('//label', $label, $this->_response->getBody()); } + + + /** @test */ + public function editCyberlibrisGroupShouldBeVisible() { + RessourcesNumeriquesFixtures::activateCyberlibris(); + $this->dispatch('admin/usergroup/edit/id/6', true); + $this->assertXPathContentContains('//label','Cyberlibris',$this->_response->getBody()); + } + + + /** @test */ + public function editToutApprendreGroupShouldBeVisible() { + RessourcesNumeriquesFixtures::activateCVS(); + $this->dispatch('admin/usergroup/edit/id/6', true); + $this->assertXPathContentContains('//label','Tout Apprendre',$this->_response->getBody()); + } } diff --git a/tests/fixtures/cyberlibris_oai.xml b/tests/fixtures/cyberlibris_oai.xml new file mode 100644 index 0000000000000000000000000000000000000000..2c43dbf47b26f55df652f4c38e004b8c213acde2 --- /dev/null +++ b/tests/fixtures/cyberlibris_oai.xml @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="UTF-8"?> +<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd"> +<responseDate>2014-07-01T15:40:47Z</responseDate> +<request verb="ListRecords" metadataPrefix="oai_dc" >http://oai-bibliovox.cyberlibris.fr/oai.aspx</request> +<ListRecords> +<record> +<header> +<identifier>oai:cyberlibris.fr:9782100497416</identifier> +<datestamp>2009-08-19</datestamp> +</header> +<metadata> +<oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"> +<dc:title>L'Art de diriger Tome 1 : Management - Stratégie Ed. 3</dc:title> +<dc:creator>Papin, Robert</dc:creator> +<dc:publisher>Dunod</dc:publisher> +<dc:contributor></dc:contributor> +<dc:date>2006</dc:date> +<dc:language>fre</dc:language> +<dc:identifier>http://www.bibliovox.com/bookdetails.aspx?docID=10177808</dc:identifier> +<dc:rights> copyrighted </dc:rights> +</oai_dc:dc> +</metadata> +</record> +<record> +<header> +<identifier>oai:cyberlibris.fr:9782711787234</identifier> +<datestamp>2009-08-19</datestamp> +</header> +<metadata> +<oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"> +<dc:title>Créer ou reprendre un commerce 2e édition</dc:title> +<dc:creator>Thiollet, Jean-Pierre</dc:creator> +<dc:publisher>Vuibert</dc:publisher> +<dc:contributor></dc:contributor> +<dc:date>2007</dc:date> +<dc:language>fre</dc:language> +<dc:identifier>http://www.bibliovox.com/bookdetails.aspx?docID=10177809</dc:identifier> +<dc:rights> copyrighted </dc:rights> +</oai_dc:dc> +</metadata> +</record> +<record> +<header> +<identifier>oai:cyberlibris.fr:9782711787043</identifier> +<datestamp>2009-08-19</datestamp> +</header> +<metadata> +<oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"> +<dc:title>Création d'entreprise : bien choisir son associé</dc:title> +<dc:creator>Cazard, Xavier</dc:creator> +<dc:publisher>Vuibert</dc:publisher> +<dc:contributor>Villey, Stéphane</dc:contributor> +<dc:date>2007</dc:date> +<dc:language>fre</dc:language> +<dc:identifier>http://www.bibliovox.com/bookdetails.aspx?docID=10177811</dc:identifier> +<dc:rights> copyrighted </dc:rights> +</oai_dc:dc> +</metadata> +</record> +<resumptionToken expirationDate="2014-07-03T14:16:14Z" completeListSize="14523" cursor="0">f0a442d7-b9fc-4b02-881a-318b573cef60</resumptionToken> +</ListRecords> +</OAI-PMH> diff --git a/tests/fixtures/cyberlibris_oai_fin.xml b/tests/fixtures/cyberlibris_oai_fin.xml new file mode 100644 index 0000000000000000000000000000000000000000..e7681e3d526cd5fdc9b579687176b79c1c4615d8 --- /dev/null +++ b/tests/fixtures/cyberlibris_oai_fin.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd"> +<responseDate>2014-07-01T15:40:47Z</responseDate> +<request verb="ListRecords" metadataPrefix="oai_dc" >http://oai-bibliovox.cyberlibris.fr/oai.aspx</request> +<ListRecords> +<record> +<header> +<identifier>oai:cyberlibris.fr:9782914453752</identifier> +<datestamp>2009-08-19</datestamp> +</header> +<metadata> +<oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"> +<dc:title>L'islam et la science</dc:title> +<dc:creator>Renan, Ernest</dc:creator> +<dc:publisher>L'Archange Minotaure</dc:publisher> +<dc:contributor></dc:contributor> +<dc:date>2007</dc:date> +<dc:language>fre</dc:language> +<dc:identifier>http://www.bibliovox.com/bookdetails.aspx?docID=10185250</dc:identifier> +<dc:rights> copyrighted </dc:rights> +</oai_dc:dc> +</metadata> +</record> +</ListRecords> +</OAI-PMH> diff --git a/tests/library/Class/RessourcesNumeriquesFixtures.php b/tests/library/Class/RessourcesNumeriquesFixtures.php index 6c97795abe70d5d186f01a2133382294701a4cb3..a184d5f7424d4221a6f231acfcf1980cba4e8193 100644 --- a/tests/library/Class/RessourcesNumeriquesFixtures.php +++ b/tests/library/Class/RessourcesNumeriquesFixtures.php @@ -25,6 +25,7 @@ class RessourcesNumeriquesFixtures { self::deactivateVodeclic(); self::deactivateArteVod(); self::deactivateNumilog(); + self::deactivateCyberlibris(); self::deactivateNumeriquePremium(); self::deactivateTypo3(); self::disableCVS(); @@ -38,6 +39,7 @@ class RessourcesNumeriquesFixtures { self::activateVodeclic(); self::activateArteVod(); self::activateNumilog(); + self::activateCyberlibris(); self::activateNumeriquePremium(); self::activateTypo3(); self::activateCVS(); @@ -93,6 +95,17 @@ class RessourcesNumeriquesFixtures { } + public static function activateCyberlibris() { + Class_AdminVar::newInstanceWithId('CYBERLIBRIS_URL', ['valeur' => 'http://oai-bibliovox.cyberlibris.fr/oai. +aspx']); + } + + + public static function deactivateCyberlibris() { + Class_AdminVar::newInstanceWithId('CYBERLIBRIS_URL', ['valeur' => '']); + } + + public static function activateArteVod() { Class_AdminVar::newInstanceWithId('ARTE_VOD',['valeur' => '1']); Class_AdminVar::newInstanceWithId('ARTE_VOD_LOGIN',['valeur' => 'user']); diff --git a/tests/library/Class/TypeDocTest.php b/tests/library/Class/TypeDocTest.php index 3f37112d3fbf54166a5a52ce415b24eb27115ead..3bb288d39ae550dabea58e095ebfa82a3aabe6ed 100644 --- a/tests/library/Class/TypeDocTest.php +++ b/tests/library/Class/TypeDocTest.php @@ -91,19 +91,13 @@ class TypeDocTest extends Storm_Test_ModelTestCase { /** @test */ public function saveNewInstancesVideoAndCDShouldUpdateTypesDocsVar() { - Class_TypeDoc::getLoader() - ->newInstance() - ->setLabel('videos') - ->save(); - - Class_TypeDoc::getLoader() - ->newInstance() - ->setLabel('CD') - ->save(); + $current_max = Class_TypeDoc::getCurrentMaxId(); + Class_TypeDoc::newInstance()->setLabel('videos')->save(); + Class_TypeDoc::newInstance()->setLabel('CD')->save(); - $this->assertContains("107:Vidéos à la demande\r\n108:Cours en ligne\r\n109:Enregistrement audio\r\n110:Numérique Premium\r\n111:videos\r\n112:CD", - $this->cosmo_types->getListe(), - 'Current value: '.$this->cosmo_types->getListe()); + $this->assertContains( + ($current_max + 1) . ":videos\r\n" . ($current_max + 2) . ":CD", + $this->cosmo_types->getListe()); } @@ -137,6 +131,30 @@ class TypeDocTest extends Storm_Test_ModelTestCase { public function loaderFind999ShouldReturnNull() { $this->assertEquals(null, Class_TypeDoc::getLoader()->find(999)); } + + /** @test */ + public function addLabelInListShouldWork() { + Class_CosmoVar::AddLabelInList('types_docs', 111, 'Cyberlibris'); + $this->assertContains('111:Cyberlibris', $this->cosmo_types->getListe()); + } + + + /** @test */ + public function couldnotAddLabelIfAlreadyExists() { + Class_CosmoVar::AddLabelInList('types_docs', 111, 'Cyberlibris'); + Class_CosmoVar::AddLabelInList('types_docs', 111, 'Cyberlibris'); + $this->assertEquals('0:non identifié\r\n1:livres\r\n2:périodiques\r\n111:Cyberlibris', $this->cosmo_types->getListe()); + } + + + /** @test */ + public function ifLabelExistsShouldUpdateLabel() { + Class_CosmoVar::AddLabelInList('types_docs', 111, 'Cyberlibris'); + Class_CosmoVar::AddLabelInList('types_docs', 111, 'Other'); + $this->assertContains('111:Other', $this->cosmo_types->getListe()); + } + + } ?> \ No newline at end of file diff --git a/tests/library/Class/WebService/CyberlibrisTest.php b/tests/library/Class/WebService/CyberlibrisTest.php new file mode 100644 index 0000000000000000000000000000000000000000..488040580da3f54dd848ebf3e1098b11a7678dae --- /dev/null +++ b/tests/library/Class/WebService/CyberlibrisTest.php @@ -0,0 +1,109 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 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). + * + * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class CyberlibrisHarvestSaveTest extends Storm_Test_ModelTestCase { + public function setUp() { + parent::setUp(); + + Class_AdminVar::newInstanceWithId('CYBERLIBRIS_URL', ['valeur' => 'http://oai-bibliovox.cyberlibris.fr/oai.aspx']); + + Class_Album::beVolatile(); + + $catalogue_xml = file_get_contents(realpath(dirname(__FILE__)). '/../../../fixtures/cyberlibris_oai.xml'); + $catalogue_xml_fin = file_get_contents(realpath(dirname(__FILE__)). '/../../../fixtures/cyberlibris_oai_fin.xml'); + + $this->_http_client = $this->mock(); + $this->_http_client + ->whenCalled('open_url') + ->with('http://oai-bibliovox.cyberlibris.fr/oai.aspx?verb=ListRecords&metadataPrefix=oai_dc') + ->answers($catalogue_xml) + ->whenCalled('open_url') + ->with('http://oai-bibliovox.cyberlibris.fr/oai.aspx?verb=ListRecords&resumptionToken=f0a442d7-b9fc-4b02-881a-318b573cef60') + ->answers($catalogue_xml_fin) + ->beStrict(); + + $this->onLoaderOfModel('Class_Album')->whenCalled('deleteBy')->answers(true); + + $this->_service = new Class_WebService_BibNumerique_Cyberlibris(); + Class_WebService_BibNumerique_Cyberlibris::setDefaultHttpClient($this->_http_client); + $this->_service->harvest(''); + } + + + /** @test */ + public function nameShouldBeCyberLibris() { + $this->assertEquals('Cyberlibris', $this->_service->getName()); + } + + + /** @test */ + public function shouldBeEnabled() { + $this->assertTrue($this->_service->isEnabled()); + } + + + /** @test */ + public function shouldHaveSaved4Albums() { + $this->assertEquals(4, count(Class_Album::findAll())); + } + + + /** @test */ + public function firstAlbumShouldNotHavePoster() { + $this->assertEquals('', Class_Album::find(1)->getPoster()); + } + + + /** @test */ + public function secondBookShouldBe() { + $this->assertContains('reprendre un commerce', Class_Album::find(2)->getTitre()); + } + + + /** @test */ + public function lastBookAuthorShouldBeRenanErnest() { + $this->assertEquals('Renan, Ernest', Class_Album::find(4)->getAuthorsNames()[0]); + } + + + /** @test */ + public function idShouldBeSet() { + $this->assertEquals('10185250', Class_Album::find(4)->getIdOrigine()); + } + + + /** @test */ + public function firstAlbumExternalURIShouldBeSet() { + $this->assertEquals('http://www.bibliovox.com/bookdetails.aspx?docID=10177808', Class_Album::find(1)->getExternalUri()); + } + + + /** @test */ + public function shouldAttemptToDeleteNonHarvested() { + $this->assertEquals( + "url_origine=\"http://oai-bibliovox.cyberlibris.fr/oai.aspx\" and id_origine not in ('10177808', '10177809', '10177811', '10185250')", + Class_Album::getLoader()->getAttributesForLastCallOn('deleteBy')[0]['where']); + } +} + + +?> \ No newline at end of file