diff --git a/.gitattributes b/.gitattributes index b048ca9beeedb1c85ebc0dfab0ad3a68ffd254b7..7daae5a4fdd78ed2d1284a5d3c672d68f0b7b04d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -292,6 +292,7 @@ application/modules/admin/controllers/ModoController.php -text application/modules/admin/controllers/ModulesController.php -text application/modules/admin/controllers/ModulesnoticeController.php -text application/modules/admin/controllers/NewsletterController.php -text +application/modules/admin/controllers/OaiController.php -text application/modules/admin/controllers/OpdsController.php -text application/modules/admin/controllers/ProfilController.php -text application/modules/admin/controllers/RssController.php -text @@ -443,6 +444,7 @@ application/modules/admin/views/scripts/newsletter/index.phtml -text application/modules/admin/views/scripts/newsletter/preview.phtml -text application/modules/admin/views/scripts/newsletter/send.phtml -text application/modules/admin/views/scripts/newsletter/sendtest.phtml -text +application/modules/admin/views/scripts/oai/index.phtml -text application/modules/admin/views/scripts/opds/add.phtml -text application/modules/admin/views/scripts/opds/browse.phtml -text application/modules/admin/views/scripts/opds/edit.phtml -text @@ -485,7 +487,6 @@ application/modules/admin/views/scripts/stat/visunotice.phtml -text application/modules/admin/views/scripts/subModal.phtml -text application/modules/admin/views/scripts/systeme/cacheimages.phtml -text application/modules/admin/views/scripts/systeme/importavisopac2.phtml -text -application/modules/admin/views/scripts/systeme/ressourcesoai.phtml -text application/modules/admin/views/scripts/systeme/webservices.phtml -text application/modules/admin/views/scripts/upload/multiple.phtml -text application/modules/admin/views/scripts/usergroup/_form.phtml -text @@ -3441,6 +3442,7 @@ tests/application/modules/admin/controllers/LieuControllerTest.php -text tests/application/modules/admin/controllers/MenusControllerTest.php -text tests/application/modules/admin/controllers/ModulesControllerTest.php -text tests/application/modules/admin/controllers/NewsletterControllerTest.php -text +tests/application/modules/admin/controllers/OaiControllerTest.php -text tests/application/modules/admin/controllers/OpdsControllerTest.php -text tests/application/modules/admin/controllers/ProfilControllerIndexTest.php -text tests/application/modules/admin/controllers/ProfilControllerPageAccueilTest.php -text diff --git a/application/modules/admin/controllers/OaiController.php b/application/modules/admin/controllers/OaiController.php new file mode 100644 index 0000000000000000000000000000000000000000..e2e7881544e1aa21213bf9f550a3345cb6de9b8d --- /dev/null +++ b/application/modules/admin/controllers/OaiController.php @@ -0,0 +1,68 @@ +<?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 Admin_OaiController extends Zend_Controller_Action { + + function indexAction() { + $entrepot_id = $this->_getparam("entrepot_id"); + if ($entrepot_id) { + $entrepot = Class_EntrepotOAI::getLoader()->find($entrepot_id); + + $oai_service = new Class_WebService_OAI(); + $oai_service->setOAIHandler($entrepot->getHandler()); + + try { + $this->view->oai_sets = $oai_service->getSets(); + $this->view->oai_set = $this->view->oai_sets[0]; + } catch (Exception $e) { + $this->view->communication_error = $e->getMessage(); + } + } + + $this->view->entrepots = Class_EntrepotOAI::findAllAsArray(); + $this->view->entrepot_id = $entrepot_id; + $this->view->titre = 'Ressources OAI'; + } + + + function harvestAction() { + $this->_helper->viewRenderer->setNoRender(); + + $entrepot_id = $this->_getparam("entrepot_id"); + $resumption_token = $this->_getparam("resumption_token"); + $oai_set=$this->_getparam("oai_set"); + + $entrepot = Class_EntrepotOAI::getLoader()->find($entrepot_id); + $notice_oai = new Class_NoticeOAI(); + + if ($resumption_token) { + $token = new Class_WebService_ResumptionToken(); + $token->setToken($resumption_token); + $next_token = $notice_oai->resumeHarvest($entrepot, $token); + } else { + $next_token = $notice_oai->harvestSet($entrepot, $oai_set); + } + + if ($next_token) + echo $next_token->toJSON(); + } +} + +?> \ No newline at end of file diff --git a/application/modules/admin/controllers/SystemeController.php b/application/modules/admin/controllers/SystemeController.php index 6935949256646ea4deec7c3024ed69211cf8e0ae..d1041e47750ef41a982ec7774d92ffebd80e43c8 100644 --- a/application/modules/admin/controllers/SystemeController.php +++ b/application/modules/admin/controllers/SystemeController.php @@ -18,8 +18,7 @@ * 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 Admin_SystemeController extends Zend_Controller_Action -{ +class Admin_SystemeController extends Zend_Controller_Action { //------------------------------------------------------------------------------------------------------ // Test des web-services @@ -120,52 +119,6 @@ class Admin_SystemeController extends Zend_Controller_Action exit; } -//------------------------------------------------------------------------------------------------------ -// Synchronisation données BNF -//------------------------------------------------------------------------------------------------------ - function ressourcesoaiAction() { - $entrepot_id = $this->_getparam("entrepot_id"); - if ($entrepot_id) { - $entrepot = Class_EntrepotOAI::findById($entrepot_id); - - $oai_service = new Class_WebService_OAI(); - $oai_service->setOAIHandler($entrepot->getHandler()); - - try { - $this->view->oai_sets = $oai_service->getSets(); - $this->view->oai_set = $this->view->oai_sets[0]; - } catch (Exception $e) { - $this->view->communication_error = $e->getMessage(); - } - } - - $this->view->entrepots = Class_EntrepotOAI::findAllAsArray(); - $this->view->entrepot_id = $entrepot_id; - $this->view->titre = 'Ressources OAI'; - } - - - function oaiharvestAction() { - $this->_helper->viewRenderer->setNoRender(); - - $entrepot_id = $this->_getparam("entrepot_id"); - $resumption_token = $this->_getparam("resumption_token"); - $oai_set=$this->_getparam("oai_set"); - - $entrepot = Class_EntrepotOAI::findById($entrepot_id); - $notice_oai = new Class_NoticeOAI(); - - if ($resumption_token) { - $token = new Class_WebService_ResumptionToken(); - $token->setToken($resumption_token); - $next_token = $notice_oai->resumeHarvest($entrepot, $token); - } else { - $next_token = $notice_oai->harvestSet($entrepot, $oai_set); - } - - if ($next_token) - echo $next_token->toJSON(); - } //------------------------------------------------------------------------------------------------------ // Import des avis OPAC2 @@ -182,4 +135,6 @@ class Admin_SystemeController extends Zend_Controller_Action else $this->view->mode="intro"; } -} \ No newline at end of file +} + +?> \ No newline at end of file diff --git a/application/modules/admin/views/scripts/systeme/ressourcesoai.phtml b/application/modules/admin/views/scripts/oai/index.phtml similarity index 96% rename from application/modules/admin/views/scripts/systeme/ressourcesoai.phtml rename to application/modules/admin/views/scripts/oai/index.phtml index 7e355a3311d2b5b420422482572426504239a285..7e05840697fe0c19207557133b25cd0555c2c54e 100644 --- a/application/modules/admin/views/scripts/systeme/ressourcesoai.phtml +++ b/application/modules/admin/views/scripts/oai/index.phtml @@ -71,7 +71,7 @@ if ($this->entrepot_id) { <script type='text/javascript'> var oai_harvest = function(entrepot_id, oai_set, token) { - var harvest_url = '<?php echo BASE_URL.'/admin/systeme/oaiharvest' ?>'; + var harvest_url = '<?php echo BASE_URL.'/admin/oai/harvest' ?>'; var params = {'entrepot_id': entrepot_id, 'oai_set': oai_set, 'resumption_token': token}; diff --git a/library/Class/EntrepotOAI.php b/library/Class/EntrepotOAI.php index e17d14bd0e0dcbebe0412ad47066b48a11546ab8..87d5a2c46a4f9f163592505ac7399ddbb0687b36 100644 --- a/library/Class/EntrepotOAI.php +++ b/library/Class/EntrepotOAI.php @@ -18,59 +18,22 @@ * 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 : Notice OAI -////////////////////////////////////////////////////////////////////////////////////////// - -class TableEntrepotOAI extends Zend_Db_Table_Abstract { - protected $_name = 'oai_entrepots'; -} - class Class_EntrepotOAI extends Storm_Model_Abstract { - protected static $_table; - protected $_table_name = 'oai_entrepots'; protected $_has_many = array('notice' => array('model' => 'Class_NoticeOAI')); - // class side - public static function getLoader() { return self::getLoaderFor(__CLASS__); } - public static function newFromRow($row) { - if (!is_array($row)) - $row = $row->toArray(); - - $entrepot = new self; - return $entrepot - ->setId($row['id']) - ->setHandler($row['handler']) - ->setLibelle($row['libelle']); - } - - public static function setTableEntrepotOAI($tbl) { - self::$_table = $tbl; - } - - public static function getTableEntrepotOAI() { - if (!isset(self::$_table)) - self::$_table = new TableEntrepotOAI(); - return self::$_table; - } // Retourne tous les entrepots de la base public static function findAll() { - $rows = self::getTableEntrepotOAI()->fetchAll(); - $entrepots = array(); - - foreach($rows as $row) - $entrepots []= self::newFromRow($row); - - return $entrepots; + return self::getLoader()->findAllBy(array('order' => 'libelle')); } + public static function findAllAsArray() { $entrepots = self::findAll(); $ent_array = array(); @@ -79,42 +42,6 @@ class Class_EntrepotOAI extends Storm_Model_Abstract { return $ent_array; } - // Retourne l'entrepot avec l'id donné - public static function findById($id) { - $row = self::getTableEntrepotOAI()->fetchRow('id='.$id); - if (!$row) return null; - return self::newFromRow($row); - } - - - // instance side - - public function setHandler($handler) { - $this->_handler = $handler; - return $this; - } - - public function setId($id) { - $this->_id = $id; - return $this; - } - - public function setLibelle($libelle) { - $this->_libelle = $libelle; - return $this; - } - - public function getHandler() { - return $this->_handler; - } - - public function getId() { - return $this->_id; - } - - public function getLibelle() { - return $this->_libelle; - } public function isGallica() { return (strpos($this->_get('handler'), 'oai.bnf.fr') !== false); diff --git a/library/ZendAfi/View/Helper/Admin/MenuGaucheAdmin.php b/library/ZendAfi/View/Helper/Admin/MenuGaucheAdmin.php index 65dc8511f340f9892feb3c9198fd79207f8356be..96ed1fec2a703a5e3e4ecb4cb5f7ca3095f493b9 100644 --- a/library/ZendAfi/View/Helper/Admin/MenuGaucheAdmin.php +++ b/library/ZendAfi/View/Helper/Admin/MenuGaucheAdmin.php @@ -11,12 +11,12 @@ * * 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 + * 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 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ ////////////////////////////////////////////////////////////////////////////////////////// // OPAC3 - Menu admin @@ -39,17 +39,17 @@ class ZendAfi_View_Helper_Admin_MenuGaucheAdmin extends ZendAfi_View_Helper_Base $acl_super_admin = array('super_admin'); // Menu Modules - $menu_modules = $this->openBoite($this->translate()->_("Gestionnaire de contenu")); + $menu_modules = $this->openBoite($this->translate()->_("Gestionnaire de contenu")); $menu_modules .= $this->addMenu("cms.gif", $this->translate()->_("Articles"), "/admin/cms", $acl_all); $menu_modules .= $this->addMenu("catalogues.png", $this->translate()->_("Catalogues dynamiques"), "/admin/catalogue", $acl_admins); $menu_modules .= $this->addMenu("rss.gif", $this->translate()->_("Fils RSS"), "/admin/rss", $acl_admins); $menu_modules .= $this->addMenu("web.gif", $this->translate()->_("Sitothèque"), "/admin/sito", $acl_admins); $menu_modules .= $this->addMenu("moderation.gif", $this->translate()->_("Modération"), "/admin/modo/", $acl_all, $nb_moderations); - $menu_modules .= $this->addMenu("vcard.png", $this->translate()->_("Demandes d'inscription"), "/admin/modo/membreview", $acl_all, $demandes_inscription); + $menu_modules .= $this->addMenu("vcard.png", $this->translate()->_("Demandes d'inscription"), "/admin/modo/membreview", $acl_all, $demandes_inscription); $menu_modules .= $this->addMenu("mail.png", $this->translate()->_("Lettres d'information"), "/admin/newsletter", $acl_admins); if (Class_AdminVar::isFormationEnabled()) { $menu_modules .= $this->addMenu("formation.png", $this->translate()->_("Formations"), "/admin/formation", $acl_admins); - $menu_modules .= $this->addMenu("compass.png", $this->translate()->_("Lieux"), "/admin/lieu", $acl_admins); + $menu_modules .= $this->addMenu("compass.png", $this->translate()->_("Lieux"), "/admin/lieu", $acl_admins); } $menu_modules .= $this->closeBoite(); @@ -57,14 +57,14 @@ class ZendAfi_View_Helper_Admin_MenuGaucheAdmin extends ZendAfi_View_Helper_Base $menu_bibnum = ''; if (Class_AdminVar::isBibNumEnabled()) { $menu_bibnum .= $this->openBoite($this->translate()->_("Bibliothèque numérique")); - $menu_bibnum .= $this->addMenu("images.png", $this->translate()->_("Collections"), "/admin/album", $acl_admins); - $menu_bibnum .= $this->addMenu("epub.png", $this->translate()->_("Ressources OPDS"), "/admin/opds", $acl_admins); - $menu_bibnum .= $this->addMenu("website.gif", $this->translate()->_("Ressources OAI"), "/admin/systeme/ressourcesoai",$acl_admins); + $menu_bibnum .= $this->addMenu("images.png", $this->translate()->_("Collections"), "/admin/album", $acl_admins); + $menu_bibnum .= $this->addMenu("epub.png", $this->translate()->_("Ressources OPDS"), "/admin/opds", $acl_admins); + $menu_bibnum .= $this->addMenu("website.gif", $this->translate()->_("Ressources OAI"), "/admin/oai", $acl_admins); $menu_bibnum .= $this->closeBoite(); } - $menu_page = $this->openBoite($this->translate()->_("Mise en page")); + $menu_page = $this->openBoite($this->translate()->_("Mise en page")); $menu_page .= $this->addMenu("ecran.png", $this->translate()->_("Profils"), "/admin/profil", $acl_admins); $menu_page .= $this->addMenu("ledred.png", $this->translate()->_("Pictogrammes des genres"), "/admin/profil/genres", $acl_admins); @@ -83,7 +83,7 @@ class ZendAfi_View_Helper_Admin_MenuGaucheAdmin extends ZendAfi_View_Helper_Base $menu_stat.= $this->closeBoite(); - $menu_portail = $this->openBoite($this->translate()->_("Administration du portail")); + $menu_portail = $this->openBoite($this->translate()->_("Administration du portail")); $menu_portail .= $this->addMenu("map.gif", $this->translate()->_("Territoires"), "/admin/zone", $acl_admins_portail); $menu_portail .= $this->addMenu("service.png", $this->translate()->_("Bibliothèques"), "/admin/bib", $acl_admins); $menu_portail .= $this->addMenu("abonnes.gif", $this->translate()->_("Utilisateurs"), "/admin/users", $acl_admins); @@ -96,9 +96,9 @@ class ZendAfi_View_Helper_Admin_MenuGaucheAdmin extends ZendAfi_View_Helper_Base // Menu systeme (super admin) - $menu_systeme = $this->openBoite($this->translate()->_("Système")); + $menu_systeme = $this->openBoite($this->translate()->_("Système")); $menu_systeme .= $this->addMenu("database.png", $this->translate()->_("Accès à Cosmogramme"), getVar("URL_COSMOGRAMME"), $acl_admins_portail); - $menu_systeme .= $this->addMenu("systeme.png", $this->translate()->_("Variables"), "/admin/index/adminvar", $acl_super_admin); + $menu_systeme .= $this->addMenu("systeme.png", $this->translate()->_("Variables"), "/admin/index/adminvar", $acl_super_admin); $menu_systeme .= $this->addMenu("tester.gif", $this->translate()->_("Test des web-services"), "/admin/systeme/webservices", $acl_super_admin); $menu_systeme .= $this->addMenu("images.png", $this->translate()->_("Cache des images"), "/admin/systeme/cacheimages", $acl_super_admin); $menu_systeme .= $this->addMenu("chat.gif.png", $this->translate()->_("Import avis opac2"), "/admin/systeme/importavisopac2",$acl_super_admin); @@ -141,7 +141,7 @@ class ZendAfi_View_Helper_Admin_MenuGaucheAdmin extends ZendAfi_View_Helper_Base if(!preg_match('^http://^',$lien)) $lien = BASE_URL.$lien; - $ico = '<img src="'.URL_ADMIN_IMG.'picto/'.$img.'" alt="'.$titre.'" />'; + $ico = '<img src="'.URL_ADMIN_IMG.'picto/'.$img.'" alt="'.$titre.'" />'; $url= array('START'=>'<a href="'.$lien.'">','END'=>'</a>'); if (!empty($extra_infos)) diff --git a/tests/application/modules/admin/controllers/OaiControllerTest.php b/tests/application/modules/admin/controllers/OaiControllerTest.php new file mode 100644 index 0000000000000000000000000000000000000000..a5ce605b0ee10927d27bbf67a2655c62b4078977 --- /dev/null +++ b/tests/application/modules/admin/controllers/OaiControllerTest.php @@ -0,0 +1,72 @@ +<?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 + */ +require_once 'AdminAbstractControllerTestCase.php'; + + +abstract class Admin_OaiControllerTestCase extends Admin_AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + + $gallica = Class_EntrepotOAI::getLoader() + ->newInstanceWithId(4) + ->setLibelle('Gallica') + ->setHandler('http://oai.bnf.fr/oai2/OAIHandler'); + + $open_archive = Class_EntrepotOAI::getLoader() + ->newInstanceWithId(5) + ->setLibelle('Open Archives') + ->setHandler('http://hal.archives-ouvertes.fr/oai/oai.php'); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_EntrepotOAI') + ->whenCalled('findAllBy') + ->with(array('order' => 'libelle')) + ->answers(array($gallica, $open_archive)); + } +} + + + + +class Admin_OaiControllerIndexActionTestCase extends Admin_OaiControllerTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/admin/oai'); + } + + + /** @test */ + public function titleShouldBeRessourcesOAI() { + $this->assertXPathContentContains('//h1', 'Ressources OAI'); + } + + + /** @test */ + public function selectOptionShouldContainsGallica() { + $this->assertXPathContentContains('//select[@name="entrepot_id"]//option[@value="4"]', 'Gallica'); + } + + + /** @test */ + public function selectOptionShouldContainsOpenArchive() { + $this->assertXPathContentContains('//select[@name="entrepot_id"]//option[@value="5"]', 'Open Archives'); + } +} +?> \ No newline at end of file