diff --git a/application/modules/opac/controllers/RechercheoaiController.php b/application/modules/opac/controllers/RechercheoaiController.php index 5a731598befb1d86f8258e31280eb46af14e66ee..0cbca41d050f49a44acee05dde5f05ac8b808c37 100644 --- a/application/modules/opac/controllers/RechercheoaiController.php +++ b/application/modules/opac/controllers/RechercheoaiController.php @@ -22,46 +22,37 @@ // OPAC3 - Controleur pour les recherches OAI ////////////////////////////////////////////////////////////////////////////////////////// -class RechercheoaiController extends Zend_Controller_Action -{ - -//------------------------------------------------------------------------------------------------------ -// Initialisation du controler -//------------------------------------------------------------------------------------------------------ - function init() - { - - } - -//------------------------------------------------------------------------------------------------------ -// INDEX -//------------------------------------------------------------------------------------------------------ - function indexAction() - { +class RechercheoaiController extends Zend_Controller_Action { + function indexAction() { $cls_oai=new Class_NoticeOAI(); $this->view->statut=$_REQUEST["statut"]; $this->view->id_entrepot=$_REQUEST["id_entrepot"]; $this->view->entrepots =$cls_oai->getEntrepots(); } -//------------------------------------------------------------------------------------------------------ -// RESULTAT DE LA RECHERCHE -//------------------------------------------------------------------------------------------------------ - function resultatAction() - { + + function resultatAction() { $cls_oai=new Class_NoticeOAI(); $this->view->entrepots =$cls_oai->getEntrepots(); - $this->view->expressionRecherche = $_REQUEST["expressionRecherche"]; - $this->view->id_entrepot=$_REQUEST["id_entrepot"]; - $resultat=$cls_oai->recherche($_REQUEST); - if($resultat["statut"]=="erreur") $this->view->erreur=$resultat["erreur"]; - else - { - $this->view->recherche=$_REQUEST["expressionRecherche"]; - $this->view->notices=$cls_oai->getPageResultat($resultat["req_liste"], $this->_getParam('page')); - $this->view->nombre=$resultat["nombre"]; + + $this->view->expressionRecherche = $this->_getParam("expressionRecherche", ''); + $this->view->id_entrepot = $this->_getParam("id_entrepot", 0); + + $params_recherche = array('expressionRecherche' => $this->view->expressionRecherche); + if ($this->view->id_entrepot) + $params_recherche['id_entrepot'] = $this->view->id_entrepot; + + $resultat = $cls_oai->recherche($params_recherche); + + if (isset($resultat["statut"])) { + $this->view->erreur=$resultat["erreur"]; + } else { + $this->view->recherche = $this->_getParam("expressionRecherche", ''); + $this->view->notices = $cls_oai->getPageResultat($resultat["req_liste"], + $this->_getParam('page')); + $this->view->nombre = $resultat["nombre"]; $this->view->page = $this->_getParam('page'); - $this->view->url_retour=BASE_URL."/rechercheoai/resultat?expressionRecherche=".$_REQUEST["expressionRecherche"]."&id_entrepot=".$_REQUEST["id_entrepot"]; + $this->view->url_retour = $this->view->url($params_recherche); } } diff --git a/application/modules/opac/views/scripts/footer.phtml b/application/modules/opac/views/scripts/footer.phtml index 0e9fdbf5929bd46407572612dee6a2f4666e992b..f8e893b39982d4b349b1f9a11b03d02ef8fc6bbe 100644 --- a/application/modules/opac/views/scripts/footer.phtml +++ b/application/modules/opac/views/scripts/footer.phtml @@ -21,6 +21,6 @@ </table> </div> </div> - <?php echo getVar('GOOGLE_ANALYTICS'); ?> +<?php echo Class_AdminVar::get('GOOGLE_ANALYTICS'); ?> </body> </html> diff --git a/application/modules/opac/views/scripts/head.phtml b/application/modules/opac/views/scripts/head.phtml index 06804e72ab83963631166c53c327573a4ebe0e25..7b0b86574536e591c0a709d76b5f6a774472f3a6 100644 --- a/application/modules/opac/views/scripts/head.phtml +++ b/application/modules/opac/views/scripts/head.phtml @@ -51,7 +51,7 @@ if ($this->accessibilite_on) { //Feuilles de styles pour les déficiences visue ->addJQueryReady('initAccessibilityOptions();'); } -if (getVar('ID_READ_SPEAKER')) +if (Class_AdminVar::get('ID_READ_SPEAKER')) $head_scripts ->addJQueryReady(sprintf('$.getScript("http://wr.readspeaker.com/webreader/webreader.js.php?cid=%s")', getVar('ID_READ_SPEAKER'))); diff --git a/application/modules/opac/views/scripts/rechercheoai/index.phtml b/application/modules/opac/views/scripts/rechercheoai/index.phtml index ba90ddced29d03cef457ea31a31c6d0bfb154c29..4241d70915e31ac0cc8f5c6116c0c5749f9d8670 100644 --- a/application/modules/opac/views/scripts/rechercheoai/index.phtml +++ b/application/modules/opac/views/scripts/rechercheoai/index.phtml @@ -2,7 +2,7 @@ $this->openBoite("Recherche OAI"); ?> <center> -<form name="form" action="<?php echo BASE_URL ?>/opac/rechercheoai/resultat" method="post"> +<form name="form" action="<?php echo BASE_URL ?>/opac/rechercheoai/resultat" method="get"> <table width="100%"> <tr> <td> diff --git a/application/modules/opac/views/scripts/rechercheoai/resultat.phtml b/application/modules/opac/views/scripts/rechercheoai/resultat.phtml index b6dfe5559bb63ddf62bbc45b138cd214d5983904..f30c97c6ea87ab9588f919eb3207375043d7509b 100644 --- a/application/modules/opac/views/scripts/rechercheoai/resultat.phtml +++ b/application/modules/opac/views/scripts/rechercheoai/resultat.phtml @@ -14,20 +14,25 @@ else else $texte=$this->_("%s notices trouvées", $this->nombre); echo BR.'<div class="liste_vignette">'.$texte.'</div>'; - foreach($this->notices as $notice) - { + foreach($this->notices as $notice) { echo '<div class="liste_vignette"><table width="100%">'; - echo '<tr><td align="right" style="width:10%" valign="top">Titre : </td><td><a href="'.$this->url(array('action' => 'viewnotice', 'id' => $notice["id"])).'" target="_blank">'.$notice["titre"].'</a></td></tr>'; + echo '<tr><td align="right" style="width:10%" valign="top">Titre : </td><td><a href="'.$this->url(array('action' => 'viewnotice', 'id' => $notice->getId())).'" target="_blank">'.$notice->getTitre().'</a></td></tr>'; $line_format = '<tr><td align="right" valign="top">%s</td><td>%s</td></tr>'; - if($notice["auteur"]) printf($line_format, $this->_('Auteur :'), $notice["auteur"]); - if($notice["editeur"]) printf($line_format, $this->_('Editeur :'), $notice["editeur"]); - if($notice["date"]) printf($line_format, $this->_('Publié en :'), $notice["date"]); - //P.... de b.... de m..... faudrait arrêter d'écrire de la m..... quand même...... Laurent - printf($line_format, $this->_('Source :'), fetchOne("select libelle from oai_entrepots where id=".$notice["source"])); + if ($notice->hasAuteur()) + printf($line_format, $this->_('Auteur :'), $notice->getAuteur()); + + if ($notice->hasEditeur()) + printf($line_format, $this->_('Editeur :'), $notice->getEditeur()); + + if($notice->hasDate()) + printf($line_format, $this->_('Publié en :'), $notice->getDate()); + + printf($line_format, $this->_('Source :'), $notice->getLibelleEntrepot()); echo '</table></div>'; } - echo '<br/><div style="width:100%;text-align:center;">'.$this->pager($this->nombre,10,$this->page,$this->url_retour).'</div>'; + + echo '<br/><div style="width:100%;text-align:center;">'.$this->pager($this->nombre,10,$this->page,$this->url_retour).'</div>'; } ?> \ No newline at end of file diff --git a/library/Class/NoticeOAI.php b/library/Class/NoticeOAI.php index 1ff8aadf3973dba424ded58b88b6477f2f513a51..d4d7ff3944454fc30169d9b697c7bc935d23e1ef 100644 --- a/library/Class/NoticeOAI.php +++ b/library/Class/NoticeOAI.php @@ -40,7 +40,8 @@ class Class_NoticeOAI extends Storm_Model_Abstract { protected $_table_notices; protected $_oai_service; protected $_entrepot_oai; - protected $_default_attribute_values = array('data' => ''); + protected $_default_attribute_values = array('data' => '', + 'date' => ''); public static function getLoader() { @@ -98,6 +99,11 @@ class Class_NoticeOAI extends Storm_Model_Abstract { } + public function getEditeur() { + return $this->extractData('editeur'); + } + + public function extractData($name) { $datas = $this->getDataAsArray(); return isset($datas[$name]) ? $datas[$name] : ''; diff --git a/tests/application/modules/AbstractControllerTestCase.php b/tests/application/modules/AbstractControllerTestCase.php index d57de44eaf66166432f9181a2a3d686a4dd4a0ec..a9b5d00b73f0f49273076d070b01ac782822086a 100644 --- a/tests/application/modules/AbstractControllerTestCase.php +++ b/tests/application/modules/AbstractControllerTestCase.php @@ -161,7 +161,7 @@ abstract class AbstractControllerTestCase extends Zend_Test_PHPUnit_ControllerTe ->setMethod('POST') ->setPost($data); - return $this->dispatch($url); + return $this->dispatch($url, true); } /** diff --git a/tests/application/modules/admin/controllers/OaiControllerTest.php b/tests/application/modules/admin/controllers/OaiControllerTest.php index 3a664f1116a48b222241d6c697683b46a351fda4..e0cd49bea3db93d0aefb686d01e888439fcb6daf 100644 --- a/tests/application/modules/admin/controllers/OaiControllerTest.php +++ b/tests/application/modules/admin/controllers/OaiControllerTest.php @@ -192,16 +192,9 @@ class Admin_OaiControllerImportIsaacAsimovFoundationTest extends Admin_OaiContro abstract class Admin_OaiControllerSearchActionTestCase extends Admin_OaiControllerTestCase { public function setUp() { parent::setUp(); - $this->old_sql = Zend_Registry::get('sql'); - $this->mock_sql = Storm_Test_ObjectWrapper::on($this->old_sql); + $this->mock_sql = Storm_Test_ObjectWrapper::on(Zend_Registry::get('sql')); Zend_Registry::set('sql', $this->mock_sql); } - - - public function tearDown() { - Zend_Registry::set('sql', $this->old_sql); - parent::tearDown(); - } } diff --git a/tests/application/modules/opac/controllers/OAIControllerTest.php b/tests/application/modules/opac/controllers/OAIControllerTest.php index 06006fc3202ecef8eca94bf7895fdb2c37a93b92..5c3a18bb1e87c08184b1eb9a6871a1f581bfbaee 100644 --- a/tests/application/modules/opac/controllers/OAIControllerTest.php +++ b/tests/application/modules/opac/controllers/OAIControllerTest.php @@ -146,6 +146,68 @@ class OaiControllerUnknownVerbRequestTest extends OaiControllerRequestTestCase { '//oai:error[@code="badVerb"]', 'Illegal OAI verb'); } +} + + + + +class OAIControllerResultatActionTest extends AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + $this->mock_sql = Storm_Test_ObjectWrapper::on(Zend_Registry::get('sql')); + Zend_Registry::set('sql', $this->mock_sql); + + $this->mock_sql + ->whenCalled('fetchOne') + ->with('select count(*) from exemplaires') + ->answers(0) + + ->whenCalled('fetchAll') + ->with("select distinct(id_entrepot) from oai_notices", false) + ->answers(array(array('id_entrepot' => 1))) + + + ->whenCalled('fetchOne') + ->with("select libelle from oai_entrepots where id=1") + ->answers('Gallica') + + ->whenCalled('fetchOne') + ->with("Select count(*) from oai_notices where MATCH(recherche) AGAINST('+(POMME POMMES POM)' IN BOOLEAN MODE)") + ->answers(1) + + ->whenCalled('fetchAll') + ->with("select id from oai_notices where MATCH(recherche) AGAINST('+(POMME POMMES POM)' IN BOOLEAN MODE) order by alpha_titre LIMIT 0,10", + false) + ->answers(array(array('id' => 2))) + ->beStrict(); + $pommes = Class_NoticeOAI::getLoader() + ->newInstanceWithId(2) + ->setTitre('Mangez des pommes') + ->setEntrepot(Class_EntrepotOAI::getLoader() + ->newInstanceWithId(3) + ->setLibelle('Gallica')); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_NoticeOAI') + ->whenCalled('findAllBy') + ->with(array('id' => array(2))) + ->answers(array($pommes)) + ->beStrict(); + + $this->dispatch('/opac/rechercheoai/resultat/expressionRecherche/pomme', true); + } + + + public function tearDown() { + Zend_Registry::set('sql', $this->old_sql); + parent::tearDown(); + } + + + /** @test */ + public function tdShouldContainsMangezDesPommes() { + $this->assertXPathContentContains('//td', 'Mangez des pommes', $this->_response->getBody()); + } } + ?> \ No newline at end of file