From b8985196b692a43dc6005711b8f423e33d27851f Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@git-test.afi-sa.fr> Date: Sat, 5 Oct 2013 11:24:23 +0000 Subject: [PATCH] =?UTF-8?q?Introduction=20g=C3=A9n=C3=A9ration=20json=20du?= =?UTF-8?q?=20r=C3=A9sultat=20de=20recherche=20pour=20timelineJS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitattributes | 4 + library/Class/MoteurRecherche/Resultat.php | 35 +++++ library/Class/Notice.php | 1 + library/Trait/NoticeVisitor.php | 42 ++++++ .../Resultat/TimelineJsonVisitor.php | 70 +++++++++ .../Resultat/TimelineJsonVisitorTest.php | 134 ++++++++++++++++++ 6 files changed, 286 insertions(+) create mode 100644 library/Class/MoteurRecherche/Resultat.php create mode 100644 library/Trait/NoticeVisitor.php create mode 100644 library/ZendAfi/View/Helper/MoteurRecherche/Resultat/TimelineJsonVisitor.php create mode 100644 tests/library/ZendAfi/View/Helper/MoteurRecherche/Resultat/TimelineJsonVisitorTest.php diff --git a/.gitattributes b/.gitattributes index 2a84c0e0bc6..c931942220a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2314,6 +2314,7 @@ library/Class/ModeleFusion.php -text library/Class/Moderer.php -text library/Class/MoteurRecherche.php -text library/Class/MoteurRecherche/Facettes.php -text +library/Class/MoteurRecherche/Resultat.php -text library/Class/MultiUpload.php -text library/Class/MultiUpload/Handler.php -text library/Class/MultiUpload/HandlerFactory.php -text @@ -2616,6 +2617,7 @@ library/Thumbs/ThumbBase.inc.php -text library/Thumbs/ThumbLib.php -text library/Thumbs/thumb_plugins/gd_reflection.inc.php -text library/Trait/HasManyDomaines.php -text +library/Trait/NoticeVisitor.php -text library/Trait/Singleton.php -text library/Trait/StaticFileWriter.php -text library/Trait/TimeSource.php -text @@ -2858,6 +2860,7 @@ library/ZendAfi/View/Helper/Menu/Null.php -text library/ZendAfi/View/Helper/Menu/SousMenus.php -text library/ZendAfi/View/Helper/MenuHorizontal.php -text library/ZendAfi/View/Helper/ModuleAbstract.php -text +library/ZendAfi/View/Helper/MoteurRecherche/Resultat/TimelineJsonVisitor.php -text library/ZendAfi/View/Helper/NewsBibHelper.php -text library/ZendAfi/View/Helper/NoteImg.php -text library/ZendAfi/View/Helper/Notice/Abstract.php -text @@ -6188,6 +6191,7 @@ tests/library/ZendAfi/View/Helper/HistoriqueRechercheTest.php -text tests/library/ZendAfi/View/Helper/IconeSupportTest.php -text tests/library/ZendAfi/View/Helper/IframeContainerTest.php -text tests/library/ZendAfi/View/Helper/Java/MenuImageTest.php -text +tests/library/ZendAfi/View/Helper/MoteurRecherche/Resultat/TimelineJsonVisitorTest.php -text tests/library/ZendAfi/View/Helper/Notice/AvisTest.php -text tests/library/ZendAfi/View/Helper/Notice/ExemplairesTest.php -text tests/library/ZendAfi/View/Helper/Notice/FacettesTypeDocTest.php -text diff --git a/library/Class/MoteurRecherche/Resultat.php b/library/Class/MoteurRecherche/Resultat.php new file mode 100644 index 00000000000..754f76d551b --- /dev/null +++ b/library/Class/MoteurRecherche/Resultat.php @@ -0,0 +1,35 @@ +<?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_MoteurRecherche_Resultat { + protected $_notices; + + public function __construct($notices) { + $this->_notices = $notices; + } + + + public function acceptVisitor($visitor) { + foreach($this->_notices as $notice) + $visitor->visitNotice($notice); + } +} + +?> \ No newline at end of file diff --git a/library/Class/Notice.php b/library/Class/Notice.php index 91baa5a8789..cd10d048047 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -151,6 +151,7 @@ class Class_Notice extends Storm_Model_Abstract { 'titres' => '', 'auteurs' => '', 'editeur' => '', + 'date_maj' => '', 'collection' => '', 'matieres' => '', 'dewey' => '', diff --git a/library/Trait/NoticeVisitor.php b/library/Trait/NoticeVisitor.php new file mode 100644 index 00000000000..cd3e544c96d --- /dev/null +++ b/library/Trait/NoticeVisitor.php @@ -0,0 +1,42 @@ +<?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 + */ +trait Trait_NoticeVisitor { + public function visitClefAlpha($clef) {} + public function visitTitres($titres) {} + public function visitAuteurs($auteurs) {} + public function visitContributeurs($contributers) {} + public function visitMatiere($matiere) {} + public function visitFormats($formats) {} + public function visitResume($resume) {} + public function visitDateMaj($date_maj) {} + public function visitAnnee($annee) {} + public function visitEditeur($editeur) {} + public function visitLangues($langues) {} + public function visitTypeDoc($type_doc) {} + public function visitNatureDoc($nature_docs) {} + public function visitVignette($url_vignette) {} + public function visitIsbn($isbn) {} + public function visitEan($ean) {} + public function visitAlbum($album) {} + public function visitSource($source) {} +} + +?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/MoteurRecherche/Resultat/TimelineJsonVisitor.php b/library/ZendAfi/View/Helper/MoteurRecherche/Resultat/TimelineJsonVisitor.php new file mode 100644 index 00000000000..c4bea079d23 --- /dev/null +++ b/library/ZendAfi/View/Helper/MoteurRecherche/Resultat/TimelineJsonVisitor.php @@ -0,0 +1,70 @@ +<?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 ZendAfi_View_Helper_MoteurRecherche_Resultat_TimelineJsonVisitor extends Zend_View_Helper_HtmlElement { + use Trait_Translator, Trait_NoticeVisitor; + + protected $_json, $_dates, $_current_date; + + /** + * @param $resultat Class_MoteurRecherche_Resultat + */ + public function MoteurRecherche_Resultat_TimelineJsonVisitor($resultat) { + $this->_dates = []; + + $resultat->acceptVisitor($this); + + $this->_json = ['timeline' => [ + 'headline' => $this->_('Résultat de la recherche'), + 'date' => $this->_dates, + ] + ]; + return json_encode($this->_json); + } + + + public function visitNotice($notice) { + $this->_current_date = ['asset' => ['media' => $this->view->urlNotice($notice)]]; + $notice->acceptVisitor($this); + $this->_dates[] = $this->_current_date; + } + + + public function visitAnnee($annee) { + $this->_current_date['startDate'] = $annee.',01,01'; + $this->_current_date['endDate'] = $annee.',12,31'; + } + + + public function visitTitres($titres) { + $this->_current_date['headline'] = $titres[0]; + } + + + public function visitResume($resume) { + $this->_current_date['text'] = $resume; + } + + + public function visitVignette($url_vignette) { + $this->_current_date['asset']['thumbnail'] = $url_vignette; + } +} +?> \ No newline at end of file diff --git a/tests/library/ZendAfi/View/Helper/MoteurRecherche/Resultat/TimelineJsonVisitorTest.php b/tests/library/ZendAfi/View/Helper/MoteurRecherche/Resultat/TimelineJsonVisitorTest.php new file mode 100644 index 00000000000..15ac983d223 --- /dev/null +++ b/tests/library/ZendAfi/View/Helper/MoteurRecherche/Resultat/TimelineJsonVisitorTest.php @@ -0,0 +1,134 @@ +<?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 ZendAfi_View_Helper_MoteurRecherche_Resultat_TimelineJsonVisitorTest extends ViewHelperTestCase { + protected $_json; + + public function setUp() { + parent::setUp(); + + + $notices = + [Class_Notice::newInstanceWithId(2, + ['unimarc' => "00627nam0 22002291 450 00100080000001000180000802100070002610000410003310100130007410500390008720000690012621000360019521500290023122500230026067600060028368600100028970000290029983000270032883500060035593000140036193200220037500028922 a2-07-052818-9 aFR a20010130 d 0frea01 ba1 afreceng 1[2001-01-30-00.00.00.000000][][][]1 aHarry Potter et le prisonnier d'AzkabanfJoanne Kathleen Rowling aPariscGallimard jeunessed2000 a465 p.3465cill.d18 cm 2aFolio juniorv1006 10 aR ROW1 aRowlingbJoanne Kathleen 1A32A partir de 10 ans aJ aRomans4R aSorcier-Sorcière", + 'url_vignette' => 'hp.png', + 'url_image' => 'hp_big.png', + 'facettes' => 'D123 A400 Y2', + 'annee' => 2009, + 'clef_oeuvre' => 'HPELPA', + 'clef_alpha' => 'POTTER', + 'exemplaires' => []]), + + + Class_Notice::newInstanceWithId(45, + ['unimarc' => "01328ngm0 2200265 450 0010007000001000041000071010013000481020007000611150025000682000071000932100022001642150053001863000035002393000045002743300454003193450027007735100018008006060027008186060039008457000042008847020043009267020033009697020032010028010028010342247456 a20021213i20041975u y0frey0103 ba0 abamjfre aFR ac086baz|zba zz c1 aLa jeune fillebDVDdDen MusofSouleymane Cisse, réal., scénario cPathédcop. 2004 a1 DVD vidéo monoface zone 2 (1 h 26 min)ccoul. aDate de sortie du film : 1975. aFilm en bambara sous-titré en français aSékou est renvoyé de l'usine parce qu'il a osé demander une augmentation. Chômeur, il sort avec Ténin, une jeune fille muette ; il ignore qu'elle est la fille de son ancien patron. Ténin, qui sera violée par Sékou lors d'une sortie entre jeunes, se retrouve enceinte et subit la colère de ses parents. Elle se trouve alors confrontée brutalement à la morale de sa famille et à la lâcheté de Sékou, qui refuse de reconnaiîre l'enfant. b3388334509824d14.00 ?1 aDen Musozbam| 31070135aCinémayMali| 32243367aCinéma30076549yAfrique 131070144aCissébSouleymane43704690 132247457aCoulibalibDounamba Dani4590 132247458aDiabatebFanta4590 132247459aDiarrabOumou4590 0aFRbBNc20011120gAFNOR", + 'url_vignette' => 'jeune_fille.png', + 'url_image' => 'jeune_fille_big.png', + 'facettes' => 'D13 A10 Y1', + 'annee' => 2011, + 'clef_oeuvre' => 'JF', + 'clef_alpha' => 'JF', + 'exemplaires' => []]), + ]; + + $resultat = new Class_MoteurRecherche_Resultat($notices); + + $this->_helper = new ZendAfi_View_Helper_MoteurRecherche_Resultat_TimelineJsonVisitor(); + $this->_helper->setView(new ZendAfi_Controller_Action_Helper_View()); + $this->_json = json_decode($this->_helper->MoteurRecherche_Resultat_TimelineJsonVisitor($resultat)); + } + + + /** @test */ + public function timelineHeadlineShouldBeResultatRecherche() { + $this->assertEquals('Résultat de la recherche', $this->_json->timeline->headline); + } + + + /** @test */ + public function firstNoticeStartDateShouldBe2009_01_01() { + $this->assertEquals('2009,01,01', $this->_json->timeline->date[0]->startDate); + } + + + /** @test */ + public function firstNoticeEndDateShouldBe2009_12_31() { + $this->assertEquals('2009,12,31', $this->_json->timeline->date[0]->endDate); + } + + + /** @test */ + public function secondNoticeEndDateShouldBe2011_12_31() { + $this->assertEquals('2011,12,31', $this->_json->timeline->date[1]->endDate); + } + + + /** @test */ + public function firstNoticeHeadlineShouldBeHarryPotterPrisonnierAzkaban() { + $this->assertEquals('Harry Potter et le prisonnier d\'Azkaban', $this->_json->timeline->date[0]->headline); + } + + + /** @test */ + public function secondNoticeHeadlineShouldBeLaJeuneFille() { + $this->assertEquals('La jeune fille', $this->_json->timeline->date[1]->headline); + } + + + /** @test */ + public function firstNoticeTextShouldBeEmpty() { + $this->assertEquals('', $this->_json->timeline->date[0]->text); + } + + + /** @test */ + public function secondNoticeTextShouldBeSekouEstRenvoye() { + $this->assertContains('Sékou est renvoyé de l\'usine parce qu\'il a osé', + $this->_json->timeline->date[1]->text); + } + + + /** @test */ + public function firstNoticeThumbnailShouldBeHpDotPng() { + $this->assertEquals('hp.png', $this->_json->timeline->date[0]->asset->thumbnail); + } + + + /** @test */ + public function firstNoticeThumbnailShouldBeJeuneFilleDotPng() { + $this->assertEquals('jeune_fille.png', $this->_json->timeline->date[1]->asset->thumbnail); + } + + + /** @test */ + public function firstNoticeMediaShouldBeRechercheViewNoticeClefPotter() { + $this->assertContains('/recherche/viewnotice/clef/POTTER/id/2', $this->_json->timeline->date[0]->asset->media); + } + + + /** @test */ + public function secondNoticeMediaShouldBeRechercheViewNoticeClefJF() { + $this->assertContains('/recherche/viewnotice/clef/JF/id/45', $this->_json->timeline->date[1]->asset->media); + } + +} +?> \ No newline at end of file -- GitLab