diff --git a/library/Class/CodifThesaurus.php b/library/Class/CodifThesaurus.php index cbd07eeaab1ded28cd28b32c5fe89b33c76510ca..577b426e147bd51113ea33a0260f11a02804b7e4 100644 --- a/library/Class/CodifThesaurus.php +++ b/library/Class/CodifThesaurus.php @@ -139,7 +139,7 @@ class Class_CodifThesaurusLoader extends Storm_Model_Loader { if (!$with_catalogue_dynamique) $where='code not like "catalogue" and'; $where .= ' LENGTH(id_thesaurus) in (1,4)'; return Class_CodifThesaurus::findAllBy(['where' => $where, - 'order' => 'id_thesaurus']); + 'order' => 'id_thesaurus']); } $pere = $this->getCodeSur4Chiffres($pere); diff --git a/library/Class/CriteresRecherche.php b/library/Class/CriteresRecherche.php index 0f37590dbf2b49542fe80f82ad576a2b0313c075..857e057f95519ca7021f5d0f3f5bc03e87020f57 100644 --- a/library/Class/CriteresRecherche.php +++ b/library/Class/CriteresRecherche.php @@ -309,6 +309,8 @@ class Class_CriteresRecherche { public function visitCatalogue($visitor, $catalogue) { + $visitor->visitCatalogue($catalogue); + $criteres = $this->getCriteres(); $this->setParams($catalogue->buildCriteresRecherche($criteres)); @@ -376,7 +378,7 @@ class Class_CriteresRecherche { } if (($panier = $this->getPanier()) && ($notices = $panier->getClesNotices())) { - $visitor->visitClesNotices($notices); + $visitor->visitPanier($panier); return $this; } diff --git a/library/Class/MoteurRecherche.php b/library/Class/MoteurRecherche.php index 33ef7eefb1db62a1f07f9134a08031e64d3494ff..2c19e8173858c4a080836153c3a1606930b904cd 100644 --- a/library/Class/MoteurRecherche.php +++ b/library/Class/MoteurRecherche.php @@ -219,8 +219,8 @@ class Class_MoteurRecherche { } - public function visitClesNotices($cles_notices) { - $keys = $this->prepareRecordsKeys($cles_notices); + public function visitClesNotices($panier) { + $keys = $this->prepareRecordsKeys($panier->getClesNotices()); $this->setCondition("notices.clef_alpha in(" . implode(', ', $keys) . ")"); } @@ -321,6 +321,11 @@ class Class_MoteurRecherche { } + public function visitCatalogue($catalogue) { + + } + + public function visitDomain($search_settings) { $search_engine = (new Class_MoteurRecherche()); $search_engine diff --git a/library/Trait/SearchCriteriaVisitor.php b/library/Trait/SearchCriteriaVisitor.php index d8e5ffef760a8a88303fdaccfe1e5edf339aa5bd..1ccf693ceceb1e5bd134e8d0ac2c4c34ec1cbf11 100644 --- a/library/Trait/SearchCriteriaVisitor.php +++ b/library/Trait/SearchCriteriaVisitor.php @@ -21,13 +21,10 @@ trait Trait_SearchCriteriaVisitor { - public function visitClesNotices($notices) {} - public function visitDomain($criteria) {} + public function visitCatalogue($catalogue) {} public function visitCoteDebutFin($start, $end) {} public function visitNouveaute($months_delay) {} public function visitAnneeDebutFin($start, $end) {} - public function visitFacetteDomainForOrConditions($catalog_id) {} - public function visitFilterOnDomain($criteria) {} public function visitSerie($serial, $order) {} public function visitCodeRebond($code) {} public function visitRubrique($rubrique, $fil) {} @@ -45,4 +42,10 @@ trait Trait_SearchCriteriaVisitor { public function hasErreur() { return false; } public function setErreur($error) {} public function visitSearchUrl($params) {} + public function visitPanier($panier) {} + + + public function visitFacetteDomainForOrConditions($catalog_id) {} + public function visitFilterOnDomain($criteria) {} + public function visitDomain($criteria) {} } \ No newline at end of file diff --git a/library/ZendAfi/Feed/SearchResultHeader.php b/library/ZendAfi/Feed/SearchResultHeader.php index 612c725ec96ce36d7cc01b1aef665f4641188afb..dea6d65d8e3a4d63a8c192b42ff0b9cd5ae0ce32 100644 --- a/library/ZendAfi/Feed/SearchResultHeader.php +++ b/library/ZendAfi/Feed/SearchResultHeader.php @@ -30,6 +30,73 @@ class ZendAfi_Feed_SearchResultHeader { $this->_header = $header; } + + public function visitFilterOnDomain($criterias) { } + public function visitDomain($criterias) {} + public function visitFacetteDomainForOrConditions($criterias) {} + public function visitNoExtension($no_extension) {} + public function hasErreur() {return false;} + public function visitCoteDebutFin($start, $end) {} + public function visitAnneeDebutFin($start, $end) {} + public function visitPage($page) {} + public function visitFiltre($filtre) {} + + + public function visitTextInput($name, $operateur, $type_recherche, $value) { + $op_labels = ['and' => '', + 'or' => $this->_('Ou '), + 'and not' => $this->_('Sauf ')]; + + $criteria_labels = [ + 'titres' => $this->_('Titre'), + 'auteurs' => ($l = Class_AdminVar::get('FACETTE_AUTEUR_LIBELLE')) ? $l : $this->_("Auteur"), + 'matieres' => ($l = Class_AdminVar::get('FACETTE_MATIERE_LIBELLE')) ? $l :$this->_("Sujet"), + 'dewey' => ($l = Class_AdminVar::get('FACETTE_DEWEY_LIBELLE')) ? $l :$this->_("Dewey / pcdm4"), + 'editeur' => $this->_("Editeur"), + 'collection' => $this->_("Collection") ]; + + $op_label = $operateur ? $op_labels[$operateur] : 'Et '; + + $libelle = $op_label. + strtolower($criteria_labels[$name]). + $this->_($type_recherche == 'commence' ? ' commence par': ':') .' ' . $value; + + $this->addCriteria($libelle); + } + + + + public function visitRubrique($rubrique, $fil) { + $this->addCriteria($this->_('Rubrique'), + Class_Codification::getInstance()->getLibelleFacette($rubrique)); + } + + + public function visitSection($section) { + $this->addCriteria('Section', + Class_Codification::getInstance()->getLibelleFacette("S".$section)); + } + + + public function visitAnnexe($annexe) { + $this->addCriteria('Annexe', + Class_Codification::getInstance()->getLibelleFacette("Y".$annexe)); + } + + + + public function visitSerie($serie, $tri) { + $title = Class_Notice::findFirstNoticeForClefChapeau($serie)->getTitreChapeau(); + $this->addCriteria($this->_('Série'), $title); + } + + + public function visitCodeRebond($code_rebond) { + $this->addCriteria($this->_('Recherche élargie à '), + Class_Codification::getInstance()->getLibelleFacette($code_rebond)); + } + + public function visitSearchResult($search_result) { $this->_description = $this->_plural($search_result->getRecordsCount(), "Aucun résultat trouvé", @@ -44,11 +111,6 @@ class ZendAfi_Feed_SearchResultHeader { } - public function visitNoExtension($no_extension) {} - - public function hasErreur() {return false;} - - public function setErreur($error) { $this->addCriteria($this->_('Erreur'), $error); } @@ -65,9 +127,28 @@ class ZendAfi_Feed_SearchResultHeader { } - public function visitFilterOnDomain($criterias) { } + public function visitTypeDoc($type_doc) { + $this->addCriteria($this->_('Type de document: %s', + Class_Codification::getInstance()->getLibelleFacette("T".$type_doc))); + } - public function visitDomain($criterias) {} + + public function visitNouveaute($nouveaute) { + if ($nouveaute == 0) + return; + $libelle = $this->_('Nouveautés de moins de: ') . $nouveaute . ' mois'; + $this->addCriteria($libelle); + } + + + public function visitCatalogue($catalogue) { + $this->_description .= ' ' . $this->_('pour le catalogue: ') . $catalogue->getLibelle(); + } + + + public function visitPanier($panier) { + $this->_description .= ' ' . $this->_('pour le panier: ') . $panier->getLibelle(); + } public function visitDigitalLib($digital_lib) { diff --git a/tests/application/modules/opac/controllers/RechercheControllerAtomTest.php b/tests/application/modules/opac/controllers/RechercheControllerAtomTest.php index 033b62daba5e5b848cf735e9b60ecc5d9b945182..fa9a0d9d5a3e6de7e72cdd735bc418fcab09bb59 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerAtomTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerAtomTest.php @@ -44,6 +44,11 @@ abstract class RechercheControllerAtomTestCase extends AbstractControllerTestCas ['id' => 123, 'libelle' => 'Science-Fiction']); + $this->fixture('Class_CodifAnnexe', + ['id' => 1, + 'code' => 1, + 'libelle' => 'Annecy']); + $this->dispatch($this->_searchUrl(), true); $this->_json = json_decode($this->_response->getBody()); $this->_xpath = new Storm_Test_XPathXML(); @@ -122,7 +127,8 @@ abstract class RechercheControllerAtomWithTwoNoticesTestCase extends RechercheCo 'resume' => 'Harry Potter il va tout dégommer', 'date_maj' => '2015-03-22 12:34:02', 'url_vignette' => 'http://ecx.images-amazon.com/images/I/51KVZWGHASL._SL160_.jpg', - 'url_image' => 'http://ecx.images-amazon.com/images/I/51KVZWGHASL.jpg']); + 'url_image' => 'http://ecx.images-amazon.com/images/I/51KVZWGHASL.jpg', + 'clef_chapeau' => 'HP']); $rdv = $this->fixture('Class_Notice', @@ -307,9 +313,21 @@ class RechercheControllerAtomWithErrorTest extends RechercheControllerAtomWithTw 'La sélection ne contient aucune notice'); } + + + /** @test */ + public function headerClassShouldHaveAllMethodsOfSearchCriteriaVisitorDeclared() { + $trait_methods = get_class_methods('Trait_SearchCriteriaVisitor'); + $header_methods = get_class_methods('ZendAfi_Feed_SearchResultHeader'); + foreach($trait_methods as $method) + $this->assertTrue(in_array($method, $header_methods), + $method .' not implemented in ZendAfi_Feed_SearchResultHeader'); + } } + + class RechercheControllerAtomOnDomainTest extends RechercheControllerAtomWithTwoNoticesTestCase { protected function _prepareLoader($loader) { @@ -324,8 +342,7 @@ class RechercheControllerAtomOnDomainTest extends RechercheControllerAtomWithTwo } - - /** @distest */ + /** @test */ public function feedSummaryShouldContainsCatalogue() { $this->_xpath->assertXPathContentContains($this->_response->getBody(), '//atom:feed/atom:subtitle', @@ -333,4 +350,126 @@ class RechercheControllerAtomOnDomainTest extends RechercheControllerAtomWithTwo } } + + + +class RechercheControllerAtomOnPanierTypeDocNouveauteTest extends RechercheControllerAtomWithTwoNoticesTestCase { + + protected function _prepareLoader($loader) { + $this->fixture('Class_PanierNotice', + ['id' => 23, + 'libelle' => 'mangas', + 'cles_notices' => ['RENDEZVOUSAKIRUNA--ANNANOVIONDARROUSSINJEANPIERRESOULISANASTASIOSLJUNGMARKCLAESBODNIAKIMHENRY---2012-104']]); + } + + + protected function _searchUrl() { + return 'recherche/simple/format/atom/id_panier/23/type_doc/1/nouveaute/3'; + } + + + /** @test */ + public function feedSummaryShouldContainsPanierMangas() { + $this->_xpath->assertXPathContentContains($this->_response->getBody(), + '//atom:feed/atom:subtitle', + "Il y a 2 résultats pour le panier: mangas"); + + } + + + /** @test */ + public function feedSummaryShouldContainsTypeDoc() { + $this->_xpath->assertXPathContentContains($this->_response->getBody(), + '//atom:feed/atom:subtitle', + "Type de document: livre"); + } + + + /** @test */ + public function feedSummaryShouldContainsNouveaute() { + $this->_xpath->assertXPathContentContains($this->_response->getBody(), + '//atom:feed/atom:subtitle', + "Nouveautés de moins de: 3 mois"); + } +} + + + +class RechercheControllerAtomWithSerieTest extends RechercheControllerAtomWithTwoNoticesTestCase { + protected function _searchUrl() { + return 'recherche/simple/expressionRecherche/Harry+Potter/tri/*/format/atom/serie/HP'; + } + + /** @test */ + public function feedSummaryShouldContainsSerie() { + $this->_xpath->assertXPathContentContains($this->_response->getBody(), + '//atom:feed/atom:subtitle', + 'Série: Harry Potter'); + } +} + + + +class RechercheControllerAtomWithRubricTest extends RechercheControllerAtomWithTwoNoticesTestCase { + protected function _prepareLoader($loader) { + $this->fixture('Class_Catalogue', + ['id' => 23, + 'libelle' => 'mangas']); + + $this->fixture('Class_CodifThesaurus', + ['id' => 23, + 'id_thesaurus' => 'CCCC23', + 'libelle' => 'mangas']); + } + + protected function _searchUrl() { + return 'recherche/simple/rubrique/HCCCC23/format/atom'; + } + + /** @test */ + public function feedSummaryShouldContainsRubriqueMangas() { + $this->_xpath->assertXPathContentContains($this->_response->getBody(), + '//atom:feed/atom:subtitle', + 'Rubrique: mangas'); + } +} + + + +class RechercheControllerAtomWithCodeRebondTest extends RechercheControllerAtomWithTwoNoticesTestCase { + protected function _searchUrl() { + return 'recherche/simple/expressionRecherche/Harry+Potter/tri/*/format/atom/code_rebond/G123'; + } + + /** @test */ + public function feedSummaryShouldContainsRechercheElargie() { + $this->_xpath->assertXPathContentContains($this->_response->getBody(), + '//atom:feed/atom:subtitle', + 'Recherche élargie à : Science-Fiction'); + } +} + + + +class RechercheControllerAtomWithAdvancedSearchTest extends RechercheControllerAtomWithTwoNoticesTestCase { + protected function _searchUrl() { + return 'recherche/simple/format/atom/rech_titres/potter/operateur_auteurs/or/rech_auteurs/rowling/section/1/annexe/1'; + } + + + /** @test */ + public function feedSummaryShouldContainsRechercheTitresOrAuteur() { + $this->_xpath->assertXPathContentContains($this->_response->getBody(), + '//atom:feed/atom:subtitle', + 'Et titre: potter. Ou auteur: rowling'); + } + + + /** @test */ + public function feedSummaryShouldContainsAnnexeAnnecy() { + $this->_xpath->assertXPathContentContains($this->_response->getBody(), + '//atom:feed/atom:subtitle', + 'Annexe: Annecy'); + } +} ?> \ No newline at end of file