diff --git a/FEATURES/188092 b/FEATURES/188092 new file mode 100644 index 0000000000000000000000000000000000000000..87def5b96db7bbf19490667686393d3634683558 --- /dev/null +++ b/FEATURES/188092 @@ -0,0 +1,10 @@ + '188092' => + ['Label' => $this->_('Tenir compte de la variable EXTENDED_SEARCH même pour des critères de type élément multiple'), + 'Desc' => $this->_('Sur le même principe que la recherche simple, si dans un élément multiple, plusieurs mots sont recherchés, avoir un opérateur ET entre chaque mot, sauf si on est en EXTENDED_SEARCH, la on aura des OU'), + 'Image' => '', + 'Video' => '', + 'Category' => $this->_('Recherche avancée'), + 'Right' => function($feature_description, $user) {return true;}, + 'Wiki' => '', + 'Test' => '', + 'Date' => '2023-11-02'], \ No newline at end of file diff --git a/VERSIONS_HOTLINE/191692 b/VERSIONS_HOTLINE/191692 new file mode 100644 index 0000000000000000000000000000000000000000..9d3798521e96bbd0906b222d5d7141a93cfbf6b0 --- /dev/null +++ b/VERSIONS_HOTLINE/191692 @@ -0,0 +1,5 @@ + - fonctionnalité #188092 : Recherche avancée : Tenir compte de la variable EXTENDED_SEARCH même pour des critères de type élément multiple. + + - correctif #173345 : Recherche : L'affinage doit être un critère de filtrage de type OU. + + - correctif #180690 : Recherche avancée : Les critères de type select basé sur des Thesaurus ne fonctionnait pas. \ No newline at end of file diff --git a/library/Class/CodifThesaurus/Loader.php b/library/Class/CodifThesaurus/Loader.php index 71be06bbf82dbf5006771a6e779a5d09be022288..5b653d9b745fd914df9f6008cbfbf54c2a5bb1c6 100644 --- a/library/Class/CodifThesaurus/Loader.php +++ b/library/Class/CodifThesaurus/Loader.php @@ -545,15 +545,6 @@ class Class_CodifThesaurus_Loader extends Storm_Model_Loader { } - public function getDynamicCodes() { - $params = []; - foreach(Class_CodifThesaurus::findAllDynamicFacets() as $facet) - $params [] = $facet->getCode(); - - return array_unique($params); - } - - public function root() { return Class_CodifThesaurus::newInstance(); } diff --git a/library/Class/CriteresRecherche.php b/library/Class/CriteresRecherche.php index 1b3f096e847a42751995ab7759fe6b9b8474ff02..842c954e571bd539dccd4439912ff8df683278fc 100644 --- a/library/Class/CriteresRecherche.php +++ b/library/Class/CriteresRecherche.php @@ -27,11 +27,10 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { protected string $_controller = 'recherche'; protected string $_action = 'simple'; - protected - $_tri_cache, - $_order_helper; + protected string $_tri_cache; + protected ?Class_CriteresRecherche_Order $_order_helper = null; - public static $criteres = + public static array $criteres = ['expressionRecherche' => 'Expression', 'rech_titres' => 'Titre', 'rech_auteurs' => 'Auteur', @@ -112,6 +111,7 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { 'pertinence', 'type_recherche', 'annexe', + 'section', 'geo_zone', 'geo_bib', 'fil', @@ -177,20 +177,22 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { } - public function getPertinence() : bool { + public function isRelevant(): bool + { return (1 == $this->getParam('pertinence', false)); } - public function filterLetterCode($data) : bool { - return preg_match('/[a-zA-Z][0-9]+/', trim($data)); - } - - public function getMultiFacets() : array { - return array_filter(array_merge(explode('-', $this->getParam('multifacets','')), - $this->selectionToArray(Class_CodifGenre::CODE_FACETTE, - $this->getGenre()))); + return array_unique(array_filter(array_merge(explode('-', $this->getParam('multifacets', '')), + $this->_selectionToArray(Class_CodifGenre::CODE_FACETTE, + $this->getGenre()), + $this->_selectionToArray(Class_CodifSection::CODE_FACETTE, + $this->getSection()), + $this->_selectionToArray(Class_CodifAnnexe::CODE_FACETTE, + $this->getAnnexe()), + $this->_selectionToArray(Class_CodifTypeDoc::CODE_FACETTE, + $this->getTypeDoc())))); } @@ -201,7 +203,7 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { public function getAxes() : Class_CriteresRecherche_AxesParam { - return (new Class_CriteresRecherche_AxesParam) + return (new Class_CriteresRecherche_AxesParam($this->isRelevant())) ->fromParamString($this->getParam('axes', '')); } @@ -223,92 +225,62 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { } - public function getGenre() { - return $this->getParam('genre', null); - } - - public function getFiltres() : array { $filtres = []; - if (!$this->isRecherchePanier() - && !$this->isSelection() - && !$this->isRechercheCatalogueEmpty() - && $this->_profil) { - $filtres = array_merge($filtres, - $this->_getProfilFilters($this->_profil)); - } + if ( ! $this->isRecherchePanier() + && ! $this->isSelection() + && ! $this->isRechercheCatalogueEmpty() + && $this->_profil) + $filtres = array_merge($filtres, $this->_getProfilFilters()); $filtres_array = array_filter(explode('-', $this->getParam('filtres', ''))); - foreach ($filtres_array as $filtre_str) { + foreach ($filtres_array as $filtre_str) if (($codes = array_filter(explode(';',$filtre_str), [$this, 'validCodeOrNull'])) && ($key = Class_Facet::find($codes[0])->getCodeRubrique())) $filtres[$key] = $codes; - } if ($bibs = $this->getBibs()) - $filtres[Class_Bib::CODE_FACETTE] = array_map(function($bib) - { - return Class_Bib::CODE_FACETTE . $bib; - }, + $filtres[Class_Bib::CODE_FACETTE] = array_map(fn($bib) => Class_Bib::CODE_FACETTE . $bib, $bibs); if (($geo_zone = $this->getGeoZone()) - && ($geo_zone = Class_Zone::find($geo_zone))) { - $all_bibs = $geo_zone->getBibs(); - $filtres[Class_Bib::CODE_FACETTE] = array_map(function($bib) - { - return Class_Bib::CODE_FACETTE . $bib->getId(); - }, - $all_bibs); - } + && ($geo_zone = Class_Zone::find($geo_zone))) + $filtres [Class_Bib::CODE_FACETTE] = array_map(fn($bib) => Class_Bib::CODE_FACETTE + . $bib->getId(), + $geo_zone->getBibs()); if (($geo_bib = $this->getGeoBib()) - && $bib = Class_Bib::find((int)$geo_bib)) { - $filtres[Class_Bib::CODE_FACETTE] = [Class_Bib::CODE_FACETTE . $bib->getId()]; - } + && $bib = Class_Bib::find((int)$geo_bib)) + $filtres [Class_Bib::CODE_FACETTE] = [Class_Bib::CODE_FACETTE . $bib->getId()]; return array_filter($filtres); } - public function selectionToArray($letter, $str, $closure = null) : array { + protected function _selectionToArray(string $letter, + string $str, + ?Closure $closure = null): array + { if ( ! $str) return []; - $items = array_filter(explode(';',str_replace(' ','',$str)), + $str = str_replace(' ', '', $str); + $separator = (false !== strpos($str, ',')) ? ',' : ';'; + $items = array_filter(explode($separator, $str), [$this, 'validCodeOrNull']); - foreach ($items as $key => $item) { - if (!$closure) { - $items[$key] = $letter . $item; - continue; - } - if (!$code = $closure($item)) - continue; + if ( ! $closure) + $closure = fn($item) => $item; - $items[$key] = $letter . $code; - } + foreach ($items as $key => $item) + if ($code = $closure($item)) + $items [$key] = $letter . $code; return $items; } - public function getTypeDoc() : array { - $digital_resource = Class_DigitalResource::getInstance(); - $validator = fn($type) => null !== Class_TypeDoc::find($type); - - return array_filter(explode(',', - $this->getParam('type_doc', '')), - $validator); - } - - - public function getMatiere() { - return $this->getParam('matiere', 0); - } - - public function getInFiles() : bool { return 1 === (int)$this->getParam('in_files'); } @@ -347,7 +319,7 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { public function getSelection() : ?Class_RecordSelection { return $this->isSelection() - ? new Class_RecordSelection() + ? new Class_RecordSelection : null; } @@ -357,30 +329,27 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { } - protected function _getProfilFilters($profil) : array { + protected function _getProfilFilters() : array { return [ Class_CodifTypeDoc::CODE_FACETTE - => $this->selectionToArray(Class_CodifTypeDoc::CODE_FACETTE, - $this->_profil->getSelTypeDoc()), + => $this->_selectionToArray(Class_CodifTypeDoc::CODE_FACETTE, + $this->_profil->getSelTypeDoc()), Class_CodifAnnexe::CODE_FACETTE - => $this->selectionToArray(Class_CodifAnnexe::CODE_FACETTE, - $this->_profil->getSelAnnexe()), + => $this->_selectionToArray(Class_CodifAnnexe::CODE_FACETTE, + $this->_profil->getSelAnnexe()), Class_CodifSection::CODE_FACETTE - => $this->selectionToArray(Class_CodifSection::CODE_FACETTE, - $this->_profil->getSelSection()), + => $this->_selectionToArray(Class_CodifSection::CODE_FACETTE, + $this->_profil->getSelSection()), Class_CodifThesaurus::CODE_FACETTE - => $this->selectionToArray(Class_CodifThesaurus::CODE_FACETTE, - $this->_profil->getDomainIds(), - function($id) - { - return ($thesaurus = Class_CodifThesaurus::findThesaurusForCatalogue($id)) - ? $thesaurus->getIdThesaurus() - : null; - }) + => $this->_selectionToArray(Class_CodifThesaurus::CODE_FACETTE, + (string) $this->_profil->getDomainIds(), + fn($id) => (($thesaurus = Class_CodifThesaurus::findThesaurusForCatalogue($id)) + ? $thesaurus->getIdThesaurus() + : null)) ]; } @@ -434,23 +403,23 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { return true; if ($catalogue = $this->getCatalogue()) { - $visitor->visitUrlCovers($this->getParam('only_img', 0)); - $visitor->visitReviews($this->getParam('with_reviews', 0)); - $this->visitCatalogue($visitor, $catalogue); + $this->_visitUrlCoversAndReviews($visitor) + ->visitCatalogue($visitor, $catalogue); + return true; } if (($panier = $this->getPanier()) && ($notices = $panier->getClesNotices())) { - $visitor->visitUrlCovers($this->getParam('only_img', 0)); - $visitor->visitReviews($this->getParam('with_reviews', 0)); + $this->_visitUrlCoversAndReviews($visitor); $visitor->visitPanier($panier); + return true; } if ($selection = $this->getSelection()) { - $visitor->visitUrlCovers($this->getParam('only_img', 0)); - $visitor->visitReviews($this->getParam('with_reviews', 0)); + $this->_visitUrlCoversAndReviews($visitor); $visitor->visitSelection($selection); + return true; } @@ -458,7 +427,15 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { } - public function visitByRechercheType($visitor) { + protected function _visitUrlCoversAndReviews($visitor) : self { + $visitor->visitUrlCovers($this->getParam('only_img', 0)); + $visitor->visitReviews($this->getParam('with_reviews', 0)); + + return $this; + } + + + protected function _visitByRechercheType($visitor) : self { if ( ! $this->_visitPanierCatalogue($visitor)) { $visitor->setErreur($this->_('La sélection ne contient aucune notice')); @@ -467,28 +444,32 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { if ($serie = $this->getSerie()) { $visitor->visitSerie($serie, $this->getTri()); + return $this; } if ($work = $this->getWork()) { $visitor->visitWork($work); + return $this; } if ($code_rebond = $this->getCodeRebond()) { $visitor->visitCodeRebond($code_rebond); + return $this; } if ($rubrique = $this->getRubrique()) { unset($this->_params['expressionRecherche']); $visitor->visitRubrique($rubrique, $this->getFil()); + return $this; } if ($expression = $this->getExpressionRecherche()) $visitor->visitExpression($expression, - $this->getPertinence(), + $this->isRelevant(), $this->getTri(), $this->getInFiles()); @@ -501,7 +482,7 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { 'dewey', 'collection']; - $pertinence = $this->getPertinence(); + $pertinence = $this->isRelevant(); foreach ($text_inputs as $name) { $operator = $this->getParam('operateur_' . $name) ?? 'and'; if ($value = $this->getParam('rech_' . $name, '')) @@ -516,19 +497,9 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { : $visitor->visitTextInputStartWith($terms, $name, $operator); } - foreach($this->_getThesaurusFulltextSearchCriterias($this->_params) as $name) { + foreach ($this->_getThesaurusFulltextSearchCriterias($this->_params) as $name) $visitor->visitThesaurusTextInput(substr($name, strlen(static::RECH_THESAURUS_PREFIX)), $this->getParam($name)); - } - - if ($type_doc = $this->getTypeDoc()) - $visitor->visitTypeDoc($type_doc); - - if ($section = $this->getSection()) - $visitor->visitSection($section); - - if ($annexe = $this->getAnnexe()) - $visitor->visitAnnexe($annexe); $visitor->visitDigitalLib($this->getParam('digital_lib', false)); @@ -550,13 +521,6 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { if ($created_until = $this->getCreatedUntil()) $visitor->visitCreatedUntil($created_until); - if (1 < ($page = $this->getPage())) - $visitor->visitPage($page); - - if ($tri = $this->getTri()) - $visitor->visitTri($tri, - $this->getListeTris()[$tri] ?? ''); - $visitor->visitCoteDebutFin($this->getCoteDebut(), $this->getCoteFin()); if ($notice_domain = (int) $this->getParam('notice_domain', 0)) @@ -571,7 +535,7 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { $visitor->visitByWork($this->isByWork()); $visitor->visitSearchUrl($this->getUrlCriteresWithFacettes()); - $this->visitByRechercheType($visitor); + $this->_visitByRechercheType($visitor); foreach ($this->getFacettes() as $facette) $visitor->visitFacette($facette); @@ -580,7 +544,6 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { $visitor->visitMultiFacet($facet); $this->getAuthorities()->acceptVisitor($visitor); - $this->getAxes()->acceptVisitor($visitor); $filtres = $this->getFiltres(); @@ -590,6 +553,12 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { if ($search = $this->_getBookmark()) $visitor->visitBookmarkedSearch($search->getVersion($this->getParam('bookmarked_version'))); + if (1 < ($page = $this->getPage())) + $visitor->visitPage($page); + + if ($tri = $this->getTri()) + $visitor->visitTri($tri, $this->getListeTris()[$tri] ?? ''); + if ($limit = $this->getLimit()) $visitor->visitLimit($limit); @@ -607,13 +576,33 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { } - public function getSection() : string { + public function getSection(): string + { return $this->getParam('section', ''); } - public function getAnnexe() : string { - return $this->validCodeOrNull($this->getParam('annexe', '')) ?? ''; + public function getAnnexe(): string + { + return $this->getParam('annexe', ''); + } + + + public function getTypeDoc(): string + { + return $this->getParam('type_doc', ''); + } + + + public function getMatiere(): string + { + return $this->getParam('matiere', ''); + } + + + public function getGenre(): string + { + return $this->getParam('genre', ''); } @@ -649,14 +638,15 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { } - public function replaceEmptyRechercheByStar($params) { - if (isset( $params['expressionRecherche']) && $params['expressionRecherche']==='') - $params['expressionRecherche']='*'; + public function replaceEmptyRechercheByStar(array $params) : array { + if (isset($params['expressionRecherche']) && '' === $params['expressionRecherche']) + $params ['expressionRecherche'] = '*'; + return $params; } - protected function _prepareParamsForValidation($params) { + protected function _prepareParamsForValidation(array $params) : array { return parent::_prepareParamsForValidation($this->replaceEmptyRechercheByStar($params)); } @@ -671,20 +661,21 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { } - public function getUrlRetourRechercheInitiale(){ + public function getUrlRetourRechercheInitiale() : array { if ($url = $this->_getNotSearchPagesBackUrl()) return array_filter($url); if (array_key_exists('rubrique', $this->_params)) return ['controller' => 'recherche', - 'action' => 'guidee' ]; - + 'action' => 'guidee']; $action = 'avancee'; - if (array_key_exists('expressionRecherche',$this->_params) || array_key_exists('id_panier',$this->_params) || array_key_exists('id_catalogue',$this->_params)) + if (array_key_exists('expressionRecherche', $this->_params) + || array_key_exists('id_panier', $this->_params) + || array_key_exists('id_catalogue', $this->_params)) $action = 'saisie'; - $url = array_merge(array_intersect_key($this->_params, self::$criteres), + $url = array_merge(array_intersect_key($this->_params, static::$criteres), ['controller' => 'recherche', 'action' => $action ]); @@ -692,42 +683,37 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { } - protected function _getNotSearchPagesBackUrl() { - if (array_key_exists('retour_panier',$this->_params)) + protected function _getNotSearchPagesBackUrl() : array { + if (array_key_exists('retour_panier', $this->_params)) return ['controller' => 'panier', 'action' => 'index', 'id_panier' => $this->_params['retour_panier']] ; - - if (array_key_exists('retour_abonne',$this->_params)) + if (array_key_exists('retour_abonne', $this->_params)) return ['controller' => 'abonne', 'action' => $this->_params['retour_abonne'], 'page' => $this->getParam('page') , 'page_size' => $this->getParam('page_size')]; - if (array_key_exists('retour_avis',$this->_params)) + if (array_key_exists('retour_avis', $this->_params)) return ['controller' => 'blog', 'action' => 'viewcritiques', 'id_module' => $this->_params['retour_avis'], 'retour_avis' => $this->_params['retour_avis']] ; - return null; + return []; } - public function getUrlCriteres() : array { + public function getUrlCriteres(): array + { return $this->getUrlCriteresWithFacettes(); } - public function getUrlCriteresWithFacettes() : array { - $params = $this->_params; - - if ($facettes = $this->getFacettesUrlEncoded()) - $params['facettes'] = $facettes; - - unset($params['facette']); - unset($params['filtres']); + public function getUrlCriteresWithFacettes(): array + { + $params = $this->_urlWithMergeParamAllFacets($this->_params, $this->_filtersForFacets()); if ($params) return array_merge(['controller' => $this->getController(), @@ -739,70 +725,71 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { } - public function getCVSUrlCriteresWithFacettes() { - $intersect=$this->_params; + public function getCVSUrlCriteresWithFacettes(): array + { + $intersect = $this->_urlWithMergeParamAllFacets($this->_params, $this->_filtersForFacets()); - if ($facettes = $this->getFacettesUrlEncoded()) - $intersect['facettes'] = $facettes; - - unset($intersect['facette']); - unset($intersect['filtres']); if ($intersect) return array_merge(['controller' => 'noticeajax', 'action' => 'cvs-search'], $intersect); - return ['controller'=>'noticeajax', + return ['controller' => 'noticeajax', 'action' => 'cvs-search']; + } + + protected function _filtersForFacets(): array + { + return ['filtres', 'facette', 'genre', 'section', 'annexe', 'type_doc']; } - public function getNewUrlCriteresRebond($code_rebond) { + public function getNewUrlCriteresRebond(?string $code_rebond): array + { $url = $this->getUrlCriteresWithoutFacettes(); - $url['code_rebond'] = $code_rebond; - return $url; + $url ['code_rebond'] = $code_rebond; + return $url; } - public function getNewUrlCriteresSerie($serie) { + public function getNewUrlCriteresSerie(string $serie): array + { return $this->_newUrlSortedByNoveltyFor('serie', $serie); } - public function getNewUrlCriteresCollection($collection) { + public function getNewUrlCriteresCollection($collection): array + { return $this->_newUrlSortedByNoveltyFor('rech_collection', $collection); } - public function getNewUrlCriteresWork($work) { + public function getNewUrlCriteresWork($work): array + { $params = $this->_newUrlSortedByNoveltyFor('work', $work); - $params['by_work'] = 0; + $params ['by_work'] = 0; + return $params; } - protected function _newUrlSortedByNoveltyFor($field, $value) { + protected function _newUrlSortedByNoveltyFor(string $field, $value): array + { $url = $this->getUrlCriteresWithoutFacettes(); - $url[$field] = $value; - $url['tri'] = self::SORT_NOVELTY_DESC; + $url [$field] = $value; + $url ['tri'] = static::SORT_NOVELTY_DESC; + return $url; } - public function getUrlCriteresWithoutFacettes() { - $intersect = $this->_params; - unset($intersect['facette']); - unset($intersect['facettes']); - unset($intersect['multifacets']); - unset($intersect['filtres']); - unset($intersect['page']); - unset($intersect['serie']); - unset($intersect['code_rebond']); - - foreach($this->_getThesaurusFulltextSearchCriterias($intersect) as $key) - unset($intersect[$key]); + public function getUrlCriteresWithoutFacettes(): array + { + $intersect = $this->_unsetsUrl($this->_params, ['facette', 'facettes', 'multifacets', 'filtres', 'page', 'serie', 'code_rebond', 'genre', 'annexe', 'section', 'type_doc']); + $intersect = $this->_unsetsUrl($intersect, + $this->_getThesaurusFulltextSearchCriterias($intersect)); return array_merge(['controller' => $this->getController(), 'action' => $this->getAction()], @@ -810,17 +797,11 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { } - public function getUrlCriteresWithOutElements($elements) { - $params = $this->_params; - - if ($facettes = $this->getFacettesUrlEncoded()) - $params['facettes'] = $facettes; - - unset($params['filtres']); - unset($params['facette']); - - foreach($elements as $element) - unset($params[$element]); + public function getUrlCriteresWithOutElements(array $elements): array + { + $params = $this->_urlWithMergeParamAllFacets($this->_params, + array_merge($this->_filtersForFacets(), + $elements)); return array_merge(['controller' => $this->getController(), 'action' => $this->getAction()], @@ -828,20 +809,15 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { } - public function getUrlCriteresWithoutElement($element) { + public function getUrlCriteresWithoutElement($element): array + { return $this->getUrlCriteresWithoutElements([$element]); } - public function getUrlCriteresWithoutTri() { - $intersect=$this->_params; - - if ($facettes = $this->getFacettesUrlEncoded()) - $intersect['facettes'] = $facettes; - - unset($intersect['facette']); - unset($intersect['filtres']); - unset($intersect['tri']); + public function getUrlCriteresWithoutTri(): array + { + $intersect = $this->_urlWithMergeParamAllFacets($this->_params, ['filtres', 'tri', 'facette', 'genre', 'section', 'annexe', 'type_doc']); return array_merge(['controller' => $this->getController(), 'action' => $this->getAction()], @@ -849,98 +825,141 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { } - public function getUrlRetourListe() { - if (!array_key_exists('code_rebond', $this->_params) - && ($url = $this->_getNotSearchPagesBackUrl())) + public function getUrlRetourListe(): array + { + if ( ! array_key_exists('code_rebond', $this->_params) + && ($url = $this->_getNotSearchPagesBackUrl())) return array_filter($url); return $this->getUrlCriteresWithFacettes(); } - public function getUrlPager() { + public function getUrlPager(): array + { return array_merge($this->getUrlRetourListe(), ['controller' => $this->getController(), 'action' => $this->getAction()]); } - public function getUrlRemoveFacette($facette) { - $facettes = array_diff($this->getFacettes(), [$facette->getCle()]); + public function getUrlRemoveFacette(Class_Facet $facet): array + { + return $this->_urlRemoveFacets($facet, $this->getFacettes(), 'facettes'); + } + + + public function getUrlRemoveMultiFacet(Class_Facet $facet): array + { + return $this->_urlRemoveFacets($facet, $this->getMultiFacets(), 'multifacets'); + } + + + protected function _urlRemoveFacets(Class_Facet $facet, array $facets, string $field): array + { + $multifacets = array_diff($facets, [$facet->getCle()]); + $url = $this->getUrlRetourListe(); - $url['facettes'] = implode('-', $facettes); - $url['page'] = null; - return array_filter($url); + $url [$field] = implode('-', $multifacets); + + return $this->_filtersUrl($url); } - public function getUrlRemoveMultiFacet($code) { + public function getUrlRemoveMultiFacets(string $code): array + { $multifacets = []; - foreach($this->getMultiFacets() as $facet) { - if (!$facet) + foreach ($this->getMultiFacets() as $facet) { + if ( ! $facet) continue; $model = Class_Facet::find($facet); if ($model->getCodeRubrique() != $code) - $multifacets[] = $facet; + $multifacets [] = $facet; } $url = $this->getUrlRetourListe(); - $url['multifacets'] = $multifacets ? implode('-', $multifacets) : null; - $url['page'] = null; - $url['genre'] = null; - return array_filter($url); + $url ['multifacets'] = implode('-', $multifacets); + + return $this->_filtersUrl($url); } - public function getUrlRemoveAuthority($authority) { + public function getUrlRemoveAuthority(Class_CriteresRecherche_AuthorityParam $authority): array + { $url = $this->getUrlRetourListe(); - $url['authorities'] = $this->getAuthorities() - ->without($authority) - ->asParamString(); - $url['page'] = null; - $url['genre'] = null; - return array_filter($url); + $url ['authorities'] = $this->getAuthorities() + ->without($authority) + ->asParamString(); + + return $this->_filtersUrl($url); } - public function multifacetsUpdate($update) { - $url = $this->getUrlRetourListe(); - $multifacets = isset($url['multifacets']) ? explode('-', $url['multifacets']) : []; + public function getUrlRemoveBookmarkVersion(): array + { + return $this->_filtersUrl($this->getUrlRetourListe(), + ['bookmarked_search', 'bookmarked_version']); + } - $add = $remove = []; - foreach($update as $facet => $state) - 1 == $state ? ($add[] = $facet): ($remove[] = $facet); - $multifacets = array_diff($multifacets, $remove); - $multifacets = array_unique(array_merge($multifacets, $add)); - $this->setParam('multifacets', implode('-', $multifacets)); + public function getUrlNouvelleRecherche(): array + { + $action = $this->hasParam('expressionRecherche') + ? 'simple' + : 'avancee'; - return $this; + return ['controller' => 'recherche', + 'action' => $action]; } - public function getUrlWithMultifacetsUpdate($update) { - return array_filter($this->multifacetsUpdate($update)->getUrlRetourListe()); + protected function _urlWithMergeParamAllFacets(array $params, array $filters): array + { + if ($facettes = $this->getFacettesUrlEncoded()) + $params ['facettes'] = $facettes; + + if ($multifacets = $this->getMultiFacets()) + $params ['multifacets'] = implode('-', $multifacets); + + return $this->_unsetsUrl($params, $filters); } - public function getUrlRemoveBookmarkVersion() { - $url = $this->getUrlRetourListe(); - unset($url['bookmarked_search']); - unset($url['bookmarked_version']); + protected function _filtersUrl(array $url, array $filters = []): array + { unset($url['page']); - return array_filter($url); + + return array_filter($this->_unsetsUrl($url, $filters)); } - public function getUrlNouvelleRecherche() { - $action = $this->hasParam('expressionRecherche') - ? 'simple' - : 'avancee'; + protected function _unsetsUrl(array $url, array $filters = []): array + { + foreach ($filters as $filter) + unset($url[$filter]); - return ['controller' => 'recherche', - 'action' => $action]; + return $url; + } + + + public function multifacetsUpdate(array $update): self + { + $multifacets = $this->getMultiFacets(); + + $add = $remove = []; + foreach ($update as $facet => $state) + 1 == $state ? ($add [] = $facet): ($remove [] = $facet); + + $multifacets = array_diff($multifacets, $remove); + $multifacets = array_unique(array_merge($multifacets, $add)); + $this->setParam('multifacets', implode('-', $multifacets)); + $this->setParam('genre', null); + $this->setParam('section', null); + $this->setParam('annexe', null); + $this->setParam('type_doc', null); + + return $this; } @@ -964,17 +983,18 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { } - public function getBibs() { + public function getBibs() : array { $bibs = explode(',', $this->getParam('bib_select','')); if ($this->_profil && ($selection_bib = $this->_profil->getIdSite())) - $bibs[] = $selection_bib; + $bibs [] = $selection_bib; + return array_filter($bibs); } public function getRubrique() { - return $this->getParam('rubrique',''); + return $this->getParam('rubrique', ''); } @@ -989,8 +1009,9 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { } - public function clearProfil() { + public function clearProfil() : self { $this->_profil = null; + return $this; } @@ -1011,7 +1032,7 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { } - public function isWallMode() { + public function isWallMode() : bool { return Class_Systeme_ModulesAppli::LISTE_FORMAT_MUR == $this->getFormat(); } @@ -1027,7 +1048,7 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { } - public function getAvailableFormats() { + public function getAvailableFormats() : array { return Class_Systeme_ModulesAppli::getAvailableListeNoticeFormat(); } @@ -1042,18 +1063,18 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { } - public function ownedBy($user) { - if (!$user) + public function ownedBy(Class_Users $user) : bool { + if ( ! $user) return false; - if (!$search = $this->_getBookmark()) + if ( ! $search = $this->_getBookmark()) return false; return $search->belongsTo($user); } - public function getBookmarkedLabel() { + public function getBookmarkedLabel() : ?string { return ($search = $this->_getBookmark()) ? $this->_('Ma recherche "%s"', $search->getLabel()) : null; @@ -1097,12 +1118,14 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { } - public function setOrderHelper($instance) { + public function setOrderHelper(?Class_CriteresRecherche_Order $instance) : self { $this->_order_helper = $instance; + + return $this; } - public function getOrderHelper() { + public function getOrderHelper() : Class_CriteresRecherche_Order { if ($this->_order_helper) return $this->_order_helper; @@ -1110,7 +1133,7 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { } - public function isDomainOrSelectionWithoutFacets() { + public function isDomainOrSelectionWithoutFacets() : bool { if ( ! ($this->isRecherchePanier() || $this->isRechercheCatalogue())) return false; @@ -1122,12 +1145,14 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { public function setController(string $controller) : self { $this->_controller = $controller; + return $this; } public function setAction(string $action) : self { $this->_action = $action; + return $this; } diff --git a/library/Class/CriteresRecherche/Abstract.php b/library/Class/CriteresRecherche/Abstract.php index ec0f22cfa1e98e63268198255bbb2f96233f69b5..dd8f6088a8224830b5a639cbf8e8086288c5ce3e 100644 --- a/library/Class/CriteresRecherche/Abstract.php +++ b/library/Class/CriteresRecherche/Abstract.php @@ -56,7 +56,7 @@ abstract class Class_CriteresRecherche_Abstract { $_time, $_validator; - public static function setMaxSearchResults($max) { + public static function setMaxSearchResults($max) : void { static::$_MAX_SEARCH_RESULTS = $max; } @@ -66,10 +66,6 @@ abstract class Class_CriteresRecherche_Abstract { } - /** - * @param $rech array paramètres de recherche et leurs valeurs - * @return Class_CritereRecherche - */ public function setParams(array $rech, array $preferences = []) : self { if (isset($rech['q']) && $rech['q']) { $rech['expressionRecherche'] = $rech['q']; @@ -97,7 +93,7 @@ abstract class Class_CriteresRecherche_Abstract { } - public function getParams() { + public function getParams() : array { return $this->_params; } @@ -107,7 +103,7 @@ abstract class Class_CriteresRecherche_Abstract { } - public function unsetParam($name) { + public function unsetParam(string $name) : self { if (array_key_exists($name, $this->_params)) unset($this->_params[$name]); @@ -115,19 +111,20 @@ abstract class Class_CriteresRecherche_Abstract { } - public function setParam($name, $value) { + public function setParam(string $name, $value) : self { $this->filterParams([$name => $value]); + return $this; } - public function hasParam($name) { + public function hasParam(string $name) : bool { return array_key_exists($name, $this->_params); } public function getAvailablePageSize() : array { - $profil_param = (new Class_Profil_Preferences_SearchResult())->getPageSize($this->_profil); + $profil_param = (new Class_Profil_Preferences_SearchResult)->getPageSize($this->_profil); $options = array_unique(['10' => 10, '20' => 20, '30' => 30, @@ -135,6 +132,7 @@ abstract class Class_CriteresRecherche_Abstract { '50' => 50, $profil_param => $profil_param]); ksort($options); + return $options; } @@ -151,6 +149,7 @@ abstract class Class_CriteresRecherche_Abstract { public function setTime($time) : self { $this->_time = $time; + return $this; } @@ -203,16 +202,17 @@ abstract class Class_CriteresRecherche_Abstract { } - public function getValidateFacette() { - if (!isset($this->_validate_facette)) - $this->_validate_facette = new ZendAfi_Validate_Facette(); + public function getValidateFacette() : ZendAfi_Validate_Facette { + if ( ! isset($this->_validate_facette)) + $this->_validate_facette = new ZendAfi_Validate_Facette; + return $this->_validate_facette; } public function getFacettes() : array { $facettes = explode('-', $this->getParam('facettes', '')); - $facettes[] = $this->getParam('facette', ''); + $facettes [] = $this->getParam('facette', ''); return array_unique(array_filter($facettes, [$this->getValidateFacette(), @@ -220,37 +220,38 @@ abstract class Class_CriteresRecherche_Abstract { } - public function getFacettesUrlEncoded() { - $facettes = $this->getFacettes(); - return $facettes ? implode('-', $facettes) : null; + public function getFacettesUrlEncoded() : ?string { + return ($facettes = $this->getFacettes()) ? implode('-', $facettes) : null; } - protected function _prepareParamsForValidation($params) { + protected function _prepareParamsForValidation(array $params) : array { return $params; } - protected function _getValidator() { + protected function _getValidator() : Class_CriteresRecherche_Validator { return $this->_validator ? $this->_validator - : $this->_validator = new Class_CriteresRecherche_Validator(); + : $this->_validator = new Class_CriteresRecherche_Validator; } - public function getCriteres() { + public function getCriteres() : array { return $this->_params; } public function setPageSize($size) : self { - $this->_params['page_size'] = $size; + $this->_params ['page_size'] = $size; + return $this; } public function setPage($page) : self { - $this->_params['page'] = $page; + $this->_params ['page'] = $page; + return $this; } @@ -265,8 +266,7 @@ abstract class Class_CriteresRecherche_Abstract { } - /** @return array suitable for url helpers */ - public function getUrlPager() { + public function getUrlPager() : array { return $this->getUrlCriteres(); } @@ -286,6 +286,5 @@ abstract class Class_CriteresRecherche_Abstract { abstract public function isEmpty() : bool; - /** @return array suitable for url helpers */ abstract public function getUrlCriteres() : array; } diff --git a/library/Class/CriteresRecherche/AxeParam.php b/library/Class/CriteresRecherche/AxeParam.php index c9e99d24ce32d329065693b048d41f8399a8f4bc..e98575690f5a1f2458abe07f46f5a6ee328bbc44 100644 --- a/library/Class/CriteresRecherche/AxeParam.php +++ b/library/Class/CriteresRecherche/AxeParam.php @@ -20,56 +20,68 @@ */ -class Class_CriteresRecherche_AxeParam { +class Class_CriteresRecherche_AxeParam +{ + const BLOCK_SEPARATOR = '~'; - protected - $_name = '', - $_blocks; + protected string $_name = ''; + protected Storm_Collection $_blocks; - public function __construct() { + public function __construct() + { $this->_blocks = new Storm_Collection; } - public function setName(string $name) : self { + public function setName(string $name): self + { $this->_name = $name; + return $this; } - public function name() : string { + public function name(): string + { return $this->_name; } - public function fromString(string $value) : self { - $blocks = explode(static::BLOCK_SEPARATOR, $value); - foreach($blocks as $block) - $this->_blocks->append(Class_CriteresRecherche_AxeParamBlock::fromString($block)); + public function fromString(string $value, bool $pertinence = false): self + { + foreach (explode(static::BLOCK_SEPARATOR, $value) as $block) + $this->_blocks->append(Class_CriteresRecherche_AxeParamBlock::fromString($block, + $pertinence)); return $this; } - public function includes(Class_CriteresRecherche_AxeParamBlock $block) : bool { + public function includes(Class_CriteresRecherche_AxeParamBlock $block): bool + { return $this->_blocks->includes($block); } - public function add(Class_CriteresRecherche_AxeParamBlock $block) : self { + public function add(Class_CriteresRecherche_AxeParamBlock $block): self + { $this->_blocks->add($block); + return $this; } - public function addAll($blocks) : self { + public function addAll($blocks): self + { $this->_blocks->addAll($blocks); + return $this; } - public function asString() : string { + public function asString(): string + { return implode(static::BLOCK_SEPARATOR, $this->_blocks ->collect(fn($each) => $each->asString()) @@ -77,13 +89,16 @@ class Class_CriteresRecherche_AxeParam { } - public function asParamArray() : array { + public function asParamArray(): array + { return (new Class_CriteresRecherche_AxeParamArrayGenerator)->generateFor($this); } - public function eachBlocksDo(Closure $closure) : self { + public function eachBlocksDo(Closure $closure): self + { $this->_blocks->eachDo($closure); + return $this; } } diff --git a/library/Class/CriteresRecherche/AxeParamBlock.php b/library/Class/CriteresRecherche/AxeParamBlock.php index 33bb90feb5d6fbe9c1e0ecc804b54110cdc33c49..06a5fc4e2cb3c6482a42e3bf2c17eb5920fd814e 100644 --- a/library/Class/CriteresRecherche/AxeParamBlock.php +++ b/library/Class/CriteresRecherche/AxeParamBlock.php @@ -20,7 +20,8 @@ */ -class Class_CriteresRecherche_AxeParamBlock { +class Class_CriteresRecherche_AxeParamBlock +{ const AND_PREFIX = 'a', @@ -30,9 +31,11 @@ class Class_CriteresRecherche_AxeParamBlock { protected Class_CriteresRecherche_AxeParamValues $_values; protected Class_MoteurRecherche_Terms $_terms; + protected bool $_pertinence = false; public static function newFor(?Class_CriteresRecherche_AxeParamBlock $current_block, - string $operator) : self { + string $operator): self + { if (static::OP_AND == $operator) return new static(); @@ -45,44 +48,52 @@ class Class_CriteresRecherche_AxeParamBlock { } - public static function fromString(string $value) : self { + public static function fromString(string $value, bool $pertinence = false): self + { $prefix = substr($value, 0, 1); $block = substr($value, 1); return static::NOT_PREFIX == $prefix - ? new Class_CriteresRecherche_AxeParamBlockNot($block) - : new static($block); + ? new Class_CriteresRecherche_AxeParamBlockNot($block, $pertinence) + : new static($block, $pertinence); } - public function __construct(string $block = '') { + public function __construct(string $block = '', bool $pertinence = false) + { $this->_terms = new Class_MoteurRecherche_Terms; $this->_values = new Class_CriteresRecherche_AxeParamValues($block); + $this->_pertinence = $pertinence; } - public function operator() : string { + public function operator(): string + { return static::OP_AND; } - public function eachValuesDo(Closure $closure) { + public function eachValuesDo(Closure $closure) + { $this->_values->eachDo($closure); } - public function addValue(Class_CriteresRecherche_AxeParamValue $value) : self { + public function addValue(Class_CriteresRecherche_AxeParamValue $value): self + { $this->_values->add($value); return $this; } - public function asString() : string { + public function asString(): string + { return static::AND_PREFIX . $this->_values->asString(); } - public function applyTo(Storm_Query_Criteria $criteria) : self { + public function applyTo(Storm_Query_Criteria $criteria): self + { return $this ->_applyValuesOperator($criteria) ->_applyFacetsTo($criteria) @@ -93,13 +104,16 @@ class Class_CriteresRecherche_AxeParamBlock { } - protected function _applyValuesOperator(Storm_Query_Criteria $criteria) : self { + protected function _applyValuesOperator(Storm_Query_Criteria $criteria): self + { $criteria->beOr(); + return $this; } - protected function _applyFacetsTo(Storm_Query_Criteria $criteria) : self { + protected function _applyFacetsTo(Storm_Query_Criteria $criteria): self + { if ( ! $facets = $this->_values->facetValues()->getArrayCopy()) return $this; @@ -113,17 +127,18 @@ class Class_CriteresRecherche_AxeParamBlock { } - protected function _applyFulltextsTo(Storm_Query_Criteria $criteria) : self { + protected function _applyFulltextsTo(Storm_Query_Criteria $criteria): self + { $fulltexts = $this->_values->selectFulltexts(); if ($fulltexts->isEmpty()) return $this; $groups = []; - foreach($fulltexts as $fulltext) + foreach ($fulltexts as $fulltext) $groups = $this->_groupFulltext($fulltext, $groups); - foreach($groups as $field => $values) + foreach ($groups as $field => $values) $this->_applyFulltextGroupTo($field, $values, $criteria); return $this; @@ -131,14 +146,15 @@ class Class_CriteresRecherche_AxeParamBlock { protected function _groupFulltext(Class_CriteresRecherche_AxeParamValue $value, - array $groups) : array { - if (!$field = $value->typeField()) + array $groups): array + { + if ( ! $field = $value->typeField()) return $groups; - if (!isset($groups[$field])) - $groups[$field] = []; + if ( ! isset($groups[$field])) + $groups [$field] = []; - $groups[$field][] = $value->value(); + $groups [$field][] = $value->value(); return $groups; } @@ -146,17 +162,26 @@ class Class_CriteresRecherche_AxeParamBlock { protected function _applyFulltextGroupTo(string $field, array $values, - Storm_Query_Criteria $criteria) : self { + Storm_Query_Criteria $criteria): self + { $match = (new Storm_Query_MatchBoolean($field)); - $all_variants = new Storm_Collection; - $this->_terms - ->analyse(implode(' ', $values)) - ->withVariantsDo(fn($variants) => $all_variants->addAll($variants)); + foreach ($values as $value) { + $or_terms = new Storm_Collection; + $this->_terms + ->analyse($value); - $this->_terms - ->withExactWordsDo(fn($words) => $match->exact_or($words)); - $match->against_and(array_unique($all_variants->getArrayCopy())); + $callback = ($this->_pertinence || 1 === $this->_terms->wordsCount()) + ? fn($variants) => $or_terms->addAll($variants) + : fn($variants) => $or_terms->add(Storm_Query_Clause_MatchTerms::and($variants)); + + $this->_terms + ->withVariantsDo($callback) + ->withExactWordsDo(fn($words) => $or_terms + ->add(Storm_Query_Clause_MatchTerms::orExact($words))); + + $match->against_or($or_terms->getArrayCopy()); + } $this->_applyMatchTo($match, $criteria); @@ -164,7 +189,8 @@ class Class_CriteresRecherche_AxeParamBlock { } - protected function _applyFulltextFacetsTo(Storm_Query_Criteria $criteria) : self { + protected function _applyFulltextFacetsTo(Storm_Query_Criteria $criteria): self + { $this->_values ->selectFulltextFacets() ->eachDo(fn($value) => $this->_applyFulltextFacetTo($value, $criteria)); @@ -174,7 +200,8 @@ class Class_CriteresRecherche_AxeParamBlock { protected function _applyFulltextFacetTo(Class_CriteresRecherche_AxeParamValue $value, - Storm_Query_Criteria $criteria) : self { + Storm_Query_Criteria $criteria): self + { $indexation = Class_Indexation::getInstance(); $this->_terms ->analyse($value->rawValue()) @@ -190,7 +217,8 @@ class Class_CriteresRecherche_AxeParamBlock { } - protected function _applyAuthoritiesTo(Storm_Query_Criteria $criteria) : self { + protected function _applyAuthoritiesTo(Storm_Query_Criteria $criteria): self + { $this->_values ->selectAuthorities() ->eachDo(fn($value) => $this->_applyAuthorityTo($value, $criteria)); @@ -200,7 +228,8 @@ class Class_CriteresRecherche_AxeParamBlock { protected function _applyAuthorityTo(Class_CriteresRecherche_AxeParamValue $value, - Storm_Query_Criteria $criteria) : self { + Storm_Query_Criteria $criteria): self + { $raw_value = $value->rawValue(); if (Class_CodifThesaurus::ID_KEY_LENGTH + 2 > strlen($raw_value)) @@ -220,8 +249,10 @@ class Class_CriteresRecherche_AxeParamBlock { protected function _applyMatchTo(Storm_Query_MatchBoolean $match, - Storm_Query_Criteria $criteria) : self { + Storm_Query_Criteria $criteria): self + { $criteria->match($match); + return $this; } } diff --git a/library/Class/CriteresRecherche/AxesParam.php b/library/Class/CriteresRecherche/AxesParam.php index 76958a72f95f13b1c5eac47d9e8e7036b6d15b52..838009e0f21a9723a97879aa47b3bf15b4e169d5 100644 --- a/library/Class/CriteresRecherche/AxesParam.php +++ b/library/Class/CriteresRecherche/AxesParam.php @@ -20,20 +20,26 @@ */ -class Class_CriteresRecherche_AxesParam { +class Class_CriteresRecherche_AxesParam +{ + const PARAM_SEPARATOR = '.', OPERATOR_SUFFIX = '_operator', AXE_SUFFIX = '_axe'; - protected $_axe_params; + protected Storm_Collection $_axe_params; + protected bool $_pertinence = false; - public function __construct() { + public function __construct(bool $pertinence = false) + { $this->_axe_params = new Storm_Collection; + $this->_pertinence = $pertinence; } - public function fromParamArray(array $params) : self { + public function fromParamArray(array $params): self + { $this->_axe_params ->addAll((new Class_CriteresRecherche_AxesParamArrayFactory()) ->axeParamsFrom($params)); @@ -42,51 +48,57 @@ class Class_CriteresRecherche_AxesParam { } - public function paramArrayOf(string $name) : array { + public function paramArrayOf(string $name): array + { return ($axe_param = $this->_axe_params->detect(fn($each) => $name === $each->name())) ? $axe_param->asParamArray() : []; } - public function fromParamString(string $value) : self { - foreach(explode(static::PARAM_SEPARATOR, $value) as $part) + public function fromParamString(string $value): self + { + foreach (explode(static::PARAM_SEPARATOR, $value) as $part) $this->_addFromString($part); return $this; } - public function acceptVisitor($visitor) { + public function acceptVisitor($visitor) + { $this->_axe_params->eachDo(fn($each) => $visitor->visitAxe($each)); } - protected function _addFromString(string $value) : self { - $this->_axe_params->append((new Class_CriteresRecherche_AxeParam)->fromString($value)); + protected function _addFromString(string $value): self + { + $this->_axe_params->append((new Class_CriteresRecherche_AxeParam) + ->fromString($value, $this->_pertinence)); + return $this; } - public function injectInto(Class_CriteresRecherche_Abstract $criteres) : Class_CriteresRecherche_Abstract{ + public function injectInto(Class_CriteresRecherche_Abstract $criteres): Class_CriteresRecherche_Abstract + { return $this->_axe_params->isEmpty() ? $criteres : $criteres->setParam('axes', $this->asParamString()); } - public function asParamString() : string { + public function asParamString(): string + { return implode(static::PARAM_SEPARATOR, $this->_axe_params - ->collect(function($each) - { - return $each->asString(); - }) + ->collect(fn($each) => $each->asString()) ->getArrayCopy()); } - public function isAxeName(string $name) : bool { + public function isAxeName(string $name): bool + { return null !== $this->_axe_params ->detect(fn($param) => $param->name() == substr($name, 0, strlen($param->name()))); } diff --git a/library/Class/CriteresRecherche/CatalogueParams.php b/library/Class/CriteresRecherche/CatalogueParams.php index 05d7a2c8be64024e0d441ae840056d335980a794..66c4312c027d61d8cd15ce770997f3716e882e23 100644 --- a/library/Class/CriteresRecherche/CatalogueParams.php +++ b/library/Class/CriteresRecherche/CatalogueParams.php @@ -23,11 +23,10 @@ class Class_CriteresRecherche_CatalogueParams extends Class_CriteresRecherche_Params { - protected $_basic_criterias = ['annee_debut', 'annee_fin', - 'cote_debut', 'cote_fin']; + protected array $_basic_criterias = ['annee_debut', 'annee_fin', + 'cote_debut', 'cote_fin']; - - public function applyTo($criteria, $params) { + public function applyTo(Class_CriteresRecherche $criteria, array $params) : array { parent::applyTo($criteria, $params); $this->_extractBasicCriterias(); @@ -35,7 +34,7 @@ class Class_CriteresRecherche_CatalogueParams } - protected function _modelsMap() { + protected function _modelsMap() : array { return ['type_doc' => Class_TypeDoc::class, 'genre' => Class_CodifGenre::class, 'langue' => Class_CodifLangue::class, @@ -52,7 +51,9 @@ class Class_CriteresRecherche_CatalogueParams } - protected function _extractFacetsForIds(array $ids, string $model_class, string $id_field) : array { + protected function _extractFacetsForIds(array $ids, + string $model_class, + string $id_field) : array { $facets = []; foreach ($ids as $id) $facets [$model_class::CODE_FACETTE . $id] = 1; @@ -62,7 +63,7 @@ class Class_CriteresRecherche_CatalogueParams protected function _extractBasicCriterias() { - foreach($this->_basic_criterias as $name) + foreach ($this->_basic_criterias as $name) $this->_extractBasicCriteria($name); if (isset($this->_params['nouveaute']) && $this->_params['nouveaute']) { @@ -73,7 +74,7 @@ class Class_CriteresRecherche_CatalogueParams protected function _extractBasicCriteria($name) { - if (!isset($this->_params[$name])) + if ( ! isset($this->_params[$name])) return; $this->_criteria->setParam($name, $this->_params[$name]); diff --git a/library/Class/CriteresRecherche/Params.php b/library/Class/CriteresRecherche/Params.php index 4b23f27002c38d0f7f197a5b80f5ecdf8c75adf4..7b33379f11aea09ae3fe12082a4b343511685bd8 100644 --- a/library/Class/CriteresRecherche/Params.php +++ b/library/Class/CriteresRecherche/Params.php @@ -22,17 +22,16 @@ class Class_CriteresRecherche_Params { - protected - $_dynamic_prefix, - $_criteria, - $_params = []; + protected string $_dynamic_prefix; + protected Class_CriteresRecherche $_criteria; + protected array $_params = []; public function __construct() { $this->_dynamic_prefix = 'rech_' . Class_CodifThesaurus::CODE_FACETTE; } - public function applyTo($criteria, $params) { + public function applyTo(Class_CriteresRecherche $criteria, array $params) : array { $this->_criteria = $criteria; $this->_params = $params; @@ -45,7 +44,7 @@ class Class_CriteresRecherche_Params { } - protected function _modelsMap() { + protected function _modelsMap() : array { return ['langue' => Class_CodifLangue::class, 'library' => Class_Bib::class, 'author' => Class_CodifAuteur::class, @@ -64,7 +63,7 @@ class Class_CriteresRecherche_Params { fn($name) => isset($this->_params[$name]), ARRAY_FILTER_USE_KEY); - foreach($models_in_params as $name => $model_class) + foreach ($models_in_params as $name => $model_class) $this->_extractFacetsFor($name, $model_class, $model_class::getIdField()); return $this; @@ -82,14 +81,16 @@ class Class_CriteresRecherche_Params { }, ARRAY_FILTER_USE_BOTH); - foreach(array_keys($thesaurus_in_params) as $code) + foreach (array_keys($thesaurus_in_params) as $code) $this->_extractFacetsFor($code, Class_CodifThesaurus::class, 'id_thesaurus'); return $this; } - protected function _extractFacetsFor(string $name, string $model_class, string $id_field) : self { + protected function _extractFacetsFor(string $name, + string $model_class, + string $id_field) : self { $ids = explode(';', $this->_params[$name]); unset($this->_params[$name]); @@ -100,22 +101,26 @@ class Class_CriteresRecherche_Params { } - protected function _extractFacetsForIds(array $ids, string $model_class, string $id_field) : array { + protected function _extractFacetsForIds(array $ids, + string $model_class, + string $id_field) : array { $facets = []; $models = $model_class::findAllBy([$id_field => $ids]); + foreach ($models as $model) $facets [$model->asFacet()] = 1; + return $facets; } protected function _extractSearchByDynamicFacetsLabels() : self { - if (!$this->_paramsStartingWithDynamicPrefix()) + if ( ! $params = $this->_paramsStartingWithDynamicPrefix()) return $this; $facets = []; - foreach(Class_CodifThesaurus::getDynamicCodes() as $code) - $facets = $this->_injectDynamicFacetIn($code, $facets); + foreach ($params as $code => $value) + $facets = $this->_injectDynamicFacetIn($code, $value, $facets); $this->_criteria->multifacetsUpdate($facets); @@ -123,32 +128,33 @@ class Class_CriteresRecherche_Params { } - protected function _injectDynamicFacetIn($code, $facets) { - $param = $this->_dynamic_prefix . $code; - if (!$value = $this->_getParam($param)) - return $facets; + protected function _injectDynamicFacetIn(string $code, string $value, array $facets) : array { + unset($this->_params[$code]); - unset($this->_params[$param]); - if (!$thesaurus = Class_CodifThesaurus::findFirstBy(['code' => $code, 'libelle' => $value])) + $id_thesaurus = str_replace($this->_dynamic_prefix, '', $code); + if ( ! $thesaurus = Class_CodifThesaurus::query() + ->start('id_thesaurus', $id_thesaurus) + ->eq('libelle', $value) + ->fetchFirst()) return $facets; - $facets[$thesaurus->getFacetteIndex()] = 1; + $facets [$thesaurus->getFacetteIndex()] = 1; return $facets; } - protected function _getParam($name) { - return isset($this->_params[$name]) ? $this->_params[$name] : null; + protected function _getParam(string $name) { + return isset($this->_params[$name]) ? $this->_params[$name] : null; } - protected function _paramsStartingWithDynamicPrefix() { + protected function _paramsStartingWithDynamicPrefix() : array { return array_filter($this->_params, [$this, '_startsWithDynamicPrefix'], ARRAY_FILTER_USE_KEY); } - protected function _startsWithDynamicPrefix($value) { + protected function _startsWithDynamicPrefix(string $value) : bool { return $this->_dynamic_prefix === substr($value, 0, strlen($this->_dynamic_prefix)); } } diff --git a/library/Class/CriteresRecherche/Validator.php b/library/Class/CriteresRecherche/Validator.php index 45a992976364024bc5df2dc8f6043b7a06257983..46d3ecb7033fb2859e324943bab00a80c44059bf 100644 --- a/library/Class/CriteresRecherche/Validator.php +++ b/library/Class/CriteresRecherche/Validator.php @@ -21,6 +21,7 @@ class Class_CriteresRecherche_Validator { + const PATTERN_YEAR = '/^[0-9]{4}$/', PATTERN_FACET = '/^[a-zA-Z0-9]+$/', @@ -28,17 +29,17 @@ class Class_CriteresRecherche_Validator { PATTERN_MULTI_IDS = '/^[0-9,]+$/', PATTERN_ALPHA = '/^[a-zA-Z0-9-_ *.]+$/'; - public function isValid($key, $params) { + public function isValid(string $key, array $params) : bool { return $this->_validatorFor($key)->isValid($key, $params); } - protected function _validatorFor($name) { + protected function _validatorFor(string $name) { if ($validator = $this->_regexValidatorFor($name)) return $validator; if ('operateur_' == substr($name, 0, 10)) - return new Class_CriteresRecherche_ValidatorOperator(); + return new Class_CriteresRecherche_ValidatorOperator; if ('section' == $name) { $ids = (new Storm_Model_Collection(Class_CodifSection::findAllVisibleOrderedByLabel())) @@ -48,11 +49,11 @@ class Class_CriteresRecherche_Validator { return new Class_CriteresRecherche_ValidatorInArray($ids); } - return new Class_CriteresRecherche_ValidatorValid(); + return new Class_CriteresRecherche_ValidatorValid; } - protected function _regexValidatorFor($name) { + protected function _regexValidatorFor(string $name) : ?Class_CriteresRecherche_ValidatorRegex { $map = [static::PATTERN_YEAR => ['annee_debut', 'annee_fin'], static::PATTERN_FACET => ['rubrique', 'code_rebond'], static::PATTERN_MULTIFACET => ['multifacets'], @@ -60,9 +61,11 @@ class Class_CriteresRecherche_Validator { static::PATTERN_ALPHA => ['serie', 'cote_debut', 'cote_fin', 'work'] ]; - foreach($map as $pattern => $names) + foreach ($map as $pattern => $names) if (in_array($name, $names)) return new Class_CriteresRecherche_ValidatorRegex($pattern); + + return null; } } @@ -70,46 +73,56 @@ class Class_CriteresRecherche_Validator { class Class_CriteresRecherche_ValidatorValid { - public function isValid($key, $params) { + + public function isValid(string $key, array $params) : bool { return true; } } + class Class_CriteresRecherche_ValidatorRegex { - protected $_pattern; - public function __construct($pattern) { + protected string $_pattern = ''; + + public function __construct(string $pattern) { $this->_pattern = $pattern; } - public function isValid($key, $params) { + public function isValid(string $key, array $params) : bool { return preg_match($this->_pattern, $params[$key]); } } + class Class_CriteresRecherche_ValidatorInArray { - protected $_possibles = []; + protected array $_possibles = []; - public function __construct($possibles) { + public function __construct(array $possibles) { $this->_possibles = $possibles; } - public function isValid($key, $params) { - return is_numeric($params[$key]) && in_array($params[$key], $this->_possibles); + public function isValid(string $key, array $params) : bool { + foreach (explode(';', $params[$key]) as $param) + if ( ! is_numeric($param) || ! in_array($param, $this->_possibles)) + return false; + + return true; } } + class Class_CriteresRecherche_ValidatorOperator { - public function isValid($key, $params) { + + public function isValid(string $key, array $params) : bool { $matching_rech = str_replace('operateur_', 'rech_', $key); return array_key_exists($matching_rech, $params) diff --git a/library/Class/MoteurRecherche.php b/library/Class/MoteurRecherche.php index bdffbcca733addb4de6f588dfdebd4f0bbc5e65c..424d0e26453e94419d31aff9ef343edef6c6f6be 100644 --- a/library/Class/MoteurRecherche.php +++ b/library/Class/MoteurRecherche.php @@ -47,6 +47,7 @@ class Class_MoteurRecherche { public function beNotExtensible() : self { $this->_extensible = false; + return $this; } @@ -279,7 +280,7 @@ class Class_MoteurRecherche { protected function _shouldExtend(Class_CriteresRecherche_Abstract $criteres_recherche) : bool { - return $this->isExtensible() && ! $criteres_recherche->getPertinence(); + return $this->isExtensible() && ! $criteres_recherche->isRelevant(); } diff --git a/library/Class/MoteurRecherche/Clauses.php b/library/Class/MoteurRecherche/Clauses.php index 2b970795351ae3ee1ef7b7a64acf80122356dee3..7d059d5afc4d4dd0dd3806cd58eb9e6117338463 100644 --- a/library/Class/MoteurRecherche/Clauses.php +++ b/library/Class/MoteurRecherche/Clauses.php @@ -55,7 +55,7 @@ class Class_MoteurRecherche_Clauses { public function composeForSubCriteria() : self { foreach ($this->_multi_facets as $facets) - $this->_matchAllAxes()->against_and($facets); + $this->_matchAllAxes()->against_and(array_unique($facets)); if ($this->_match_axes && $this->_match_in_file) $this->_criteria->or((new Storm_Query_Criteria) @@ -80,8 +80,9 @@ class Class_MoteurRecherche_Clauses { public function isExtensible() : bool { - return !$this->_terms->isExactSearch() - && 1 < $this->wordsCount(); + return $this->_axes_criteria + || ( ! $this->_terms->isExactSearch() + && 1 < $this->wordsCount()); } @@ -187,6 +188,18 @@ class Class_MoteurRecherche_Clauses { } + public function visitMultiFacet(string $multi_facet) : void { + if ( ! $multi_facet) + return; + + $facet = Class_Facet::find($multi_facet); + if ($facet && ($code = $facet->getCodeRubrique())) { + $this->_multi_facets [$code] ??= []; + $this->_multi_facets [$code] [] = Class_Notice_Facettes::PREFIX . $multi_facet; + } + } + + public function visitCodeRebond(string $code_rebond) : void { $this->visitFacette($code_rebond); } @@ -246,25 +259,12 @@ class Class_MoteurRecherche_Clauses { } - public function visitTypeDoc(array $type_docs) : void { - $this->_queryFacet(array_map(fn($type_doc) => Class_CodifTypeDoc::CODE_FACETTE . $type_doc, - $type_docs)); - } - - - public function visitSection(string $section) : void { - $this->visitFacette(Class_CodifSection::CODE_FACETTE . $section); - } - - - public function visitAnnexe(string $annexe) : void { - $this->visitFacette(Class_CodifAnnexe::CODE_FACETTE . $annexe); - } - - public function visitDigitalLib(bool $flag) : void { - if ($flag) - $this->visitTypeDoc(array_keys(Class_TypeDoc::getDigitalDocTypes())); + if ( ! $flag) + return; + + foreach (array_keys(Class_TypeDoc::getDigitalDocTypes()) as $type_doc) + $this->visitMultiFacet(Class_CodifTypeDoc::CODE_FACETTE . $type_doc); } @@ -357,18 +357,6 @@ class Class_MoteurRecherche_Clauses { } - public function visitMultiFacet(string $multi_facet) : void { - if ( ! $multi_facet) - return; - - $facet = Class_Facet::find($multi_facet); - if ($facet && ($code = $facet->getCodeRubrique())) { - $this->_multi_facets [$code] ??= []; - $this->_multi_facets [$code] [] = Class_Notice_Facettes::PREFIX . $multi_facet; - } - } - - public function visitAuthority(Class_CriteresRecherche_AuthorityParam $authority) : void { if ($facets = $authority->facets()) $this->_queryFacet($facets); @@ -399,7 +387,7 @@ class Class_MoteurRecherche_Clauses { $block->applyTo($criteria); if ($criteria->hasClauses()) - $this->_axes_criteria[] = $criteria; + $this->_axes_criteria [] = $criteria; return $this; } diff --git a/library/Class/MoteurRecherche/Result.php b/library/Class/MoteurRecherche/Result.php index ec9a6f065ba0071e3578bfabe4f41fce8be55eba..ce9faec53321f1edf8c27ff70985f921f56ac491 100644 --- a/library/Class/MoteurRecherche/Result.php +++ b/library/Class/MoteurRecherche/Result.php @@ -252,14 +252,11 @@ class Class_MoteurRecherche_Result { } - public function inspectOn($inspector) { + public function inspectOn(ZendAfi_View_Helper_SearchInspector $inspector) : self { if ( ! $inspector) - return; - - $this->fetchRecords(); + return $this; - $inspector->visitMatchingSearchTerms($this->getMatchingSearchTerms()) - ->visitQuery($this->_query->assembleDb()); + $inspector->visitQuery($this->_query->assembleDb()); return $this; } diff --git a/library/Class/MoteurRecherche/Terms.php b/library/Class/MoteurRecherche/Terms.php index b9ee503a001856341470d84851978233a0670550..fe4e017ec61ffdf0043efb9a3403b4f1cad311db 100644 --- a/library/Class/MoteurRecherche/Terms.php +++ b/library/Class/MoteurRecherche/Terms.php @@ -29,6 +29,8 @@ class Class_MoteurRecherche_Terms { public function analyse(string $expression) : self { $this->_terms = []; + $this->_exact_terms = []; + $this->_all_words = []; $this->_expression = $expression; if ( ! $expression) return $this; @@ -128,10 +130,10 @@ class Class_MoteurRecherche_Terms { $term = new Class_MoteurRecherche_Term($token); if ($phonetix = $term->getPhonetix()) - $phonetixs[$phonetix][] = $token; + $phonetixs [$phonetix][] = $token; if ($singular = $term->getSingular()) - $phonetixs[$singular][] = $token; + $phonetixs [$singular][] = $token; return $phonetixs; } @@ -148,16 +150,7 @@ class Class_MoteurRecherche_Terms { public function isExactSearch() : bool { - return !empty($this->_exact_terms); - } - - - public function asWhereAgainst(bool $is_extended) : string { - if ($this->isEmpty()) - return ''; - - return " AGAINST(" . $this->exactTermsBeforePhonetic($is_extended) - . ($is_extended ? '' : ' IN BOOLEAN MODE') . ')'; + return ! empty($this->_exact_terms); } @@ -183,56 +176,6 @@ class Class_MoteurRecherche_Terms { } - public function exactTermsBeforePhonetic(bool $is_extended = false) : string { - $against_exact = array_map(fn($expr) => '+"' . $expr . '"', - $this->_exact_terms); - - $against = array_map(fn($term) => $term->asAgainstClause($is_extended), - $this->_terms); - - $againsts = [implode(' ', $against_exact), - implode(' ', $against)]; - - return $this->_quote(trim(implode(' ', array_filter($againsts)))); - } - - - public function asAnyAgainst() : string { - if ($this->isEmpty()) - return ''; - - $variants = array_map(fn($term) => '"' . $term . '"', - $this->_exact_terms); - foreach ($this->_terms as $term) - $variants[] = $term->variants(); - - $variants = $this->_quote('+(' . implode(' ', $variants) . ')'); - - return 'AGAINST(' . $variants . ' IN BOOLEAN MODE)'; - } - - - public function asSelectAgainst(string $axe) : string { - return $this->_selectAgainst($axe, implode(' ', $this->_all_words)); - } - - - public function asSelectAgainstMainTerms(string $axe) : string { - return $this->_selectAgainst($axe, - Class_Indexation::getInstance() - ->getMainWordsWith($this->_all_words)); - } - - - public function asSelectAgainstThesaurusTerms(string $id_thesaurus) : string { - $terms = array_map(fn($term) => '+' . $id_thesaurus . '_' . $term, - Class_Indexation::getInstance() - ->getMotsRechercheExacte(implode(' ', $this->_all_words))); - return sprintf('MATCH(other_terms) AGAINST(%s IN BOOLEAN MODE)', - $this->_quote(implode(' ' , $terms))); - } - - public function withExactAllWordsDo(Closure $callback) : self { $callback($this->_expression); @@ -240,11 +183,6 @@ class Class_MoteurRecherche_Terms { } - protected function _selectAgainst(string $axe, string $all_words) : string { - return sprintf('MATCH(%s) AGAINST(\'%s\')', $axe, $all_words); - } - - public function withExactDo(Closure $callback) : self { if (empty($this->_exact_terms) && $this->wordsCount() > 1) $callback($this->_expression); @@ -263,19 +201,8 @@ class Class_MoteurRecherche_Terms { public function withMainWordsDo(Closure $callback) : self { $callback(Class_Indexation::getInstance()->getMainWordsWith($this->_all_words)); - return $this; - } - - protected function _selectAgainstExact(string $axe, string $exact_words) : string { - return sprintf('MATCH(%s) AGAINST(%s IN BOOLEAN MODE)', - $axe, - $this->_quote('"' . $exact_words . '"')); - } - - - protected function _quote(string $expression) : string { - return Zend_Db_Table_Abstract::getDefaultAdapter()->quote($expression); + return $this; } } @@ -320,6 +247,11 @@ class Class_MoteurRecherche_Term { } + public function getPlural() : string { + return $this->_plural; + } + + public function disablePhonetix(string $value) : self { if ($this->_phonetix == $value) $this->_phonetix = false; @@ -351,6 +283,13 @@ class Class_MoteurRecherche_Term { public function isValid() : bool { return null !== $this->_singular; } + + + public function isSame(Class_MoteurRecherche_Term $term) : bool { + return $this->getSingular() === $term->getSingular() + && $this->getPlural() === $term->getPlural() + && $this->getPhonetix() === $term->getPhonetix(); + } } diff --git a/library/Class/Notice.php b/library/Class/Notice.php index 04293c6ae59f69e57934831aac80bb829c13f376..99248e4c7f97a68be0d531b9ecf8a4e050e532c3 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -745,14 +745,11 @@ class Class_Notice extends Storm_Model_Abstract { if ( ! $id_notice) return []; - $ix = new Class_Indexation; - // Preferences $champs = Class_MoteurRecherche::RECORD_WORDS; $champs_tags = 'DPMZ'; $nb_max = 50; - $limite_notices = 15; // Lire les champs les plus significatifs $notice = $this->getLoader()->query() @@ -764,29 +761,8 @@ class Class_Notice extends Storm_Model_Abstract { if ( ! $notice) return false; - // Decoupage des mots index - $recherche = ''; - foreach (Class_MoteurRecherche::RECORD_WORDS as $champ) { - // Exclude facets fields from this usage. - if ($champ == 'facets') - continue; - - foreach (explode(' ', trim($notice[$champ] ?? '')) as $mot) - if ('P_' !== substr($mot, 0, 2) && $mot = $ix->getExpressionRecherche($mot)) - $recherche .= ' ' . $mot; - } - - // Lancer la requete - $items = $this->getLoader()->query() - ->select('facettes') - ->match((new Storm_Query_MatchBoolean($champs)) - ->against_or($recherche)) - ->not_eq('id_notice', $id_notice) - ->limit_page(0, $limite_notices) - ->fetchAll(); - // Récup des tags uniques et comptage des occurences - if ( ! count($items)) + if ( ! ($items = $this->_withAllFieldsFindItems($notice, $id_notice))) return []; $temp = []; @@ -802,9 +778,9 @@ class Class_Notice extends Storm_Model_Abstract { continue; $temp[$facette] = $this->getLoader()->query() - ->match((new Storm_Query_MatchBoolean($champs)) - ->against_and($facette)) - ->countAll(); + ->match((new Storm_Query_MatchBoolean($champs)) + ->against_and($facette)) + ->countAll(); } } @@ -828,6 +804,48 @@ class Class_Notice extends Storm_Model_Abstract { } + protected function _withAllFieldsFindItems(array $record, int $id) : array { + $match = null; + + foreach (Class_MoteurRecherche::RECORD_WORDS as $field) + $match = $this->_forFieldAnalyseWord($match, $field, $record); + + return $match + ? $this->getLoader()->query() + ->select('facettes') + ->match($match) + ->not_eq('id_notice', $id) + ->limit_page(0, 15) + ->fetchAll() + : []; + } + + + protected function _forFieldAnalyseWord(?Storm_Query_MatchBoolean $match, + string $field, + array $record) : ?Storm_Query_MatchBoolean { + if ( ! $field || 'facets' === $field) + return $match; + + $words = trim($record[$field] ?? ''); + if ( ! $words) + return $match; + + $terms = new Class_MoteurRecherche_Terms; + + foreach (explode(' ', $words) as $word) { + if ( ! $word || 'P_' === substr($word, 0, 2)) + continue; + + $match ??= new Storm_Query_MatchBoolean(Class_MoteurRecherche::RECORD_WORDS); + $terms->analyse($word) + ->withVariantsDo(fn($variants) => $match->against_or($variants)); + } + + return $match; + } + + // ---------------------------------------------------------------- // Champ 856$b (identifiants cms sito et rss) // ---------------------------------------------------------------- diff --git a/library/Class/Notice/RubriqueFacette.php b/library/Class/Notice/RubriqueFacette.php index 3ac594f9f649e00e51ac2dabead90a5cefda9080..f4e5a95154f5c1d299a423e3a90d794cf4c12736 100644 --- a/library/Class/Notice/RubriqueFacette.php +++ b/library/Class/Notice/RubriqueFacette.php @@ -77,9 +77,10 @@ class Class_Notice_RubriqueFacette { protected static function settingArrayToFacet($codes) { $facets = []; + foreach ($codes as $facet) { - $facet = new static($facet); - $facets [$facet->getLibelle()] = $facet; + $model = new static($facet); + $facets [$model->getLibelle()] = $model; } return $facets; @@ -120,6 +121,4 @@ class Class_Notice_RubriqueFacette { public function getCode() { return $this->_code; } - - -} \ No newline at end of file +} diff --git a/library/Trait/SearchCriteriaVisitor.php b/library/Trait/SearchCriteriaVisitor.php index 9d4b7b458e9942b73501cd6250372d199c4698ca..d809c78f82c3909eb4feb2f8271f12a49afe9504 100644 --- a/library/Trait/SearchCriteriaVisitor.php +++ b/library/Trait/SearchCriteriaVisitor.php @@ -58,18 +58,9 @@ trait Trait_SearchCriteriaVisitor { bool $in_file = false) : void {} - public function visitTypeDoc(array $types_docs) : void {} - - public function visitEditor(string $editor) : void {} - public function visitSection(string $section) : void {} - - - public function visitAnnexe(string $annexe) : void {} - - public function visitDigitalLib(bool $flag) : void {} diff --git a/library/ZendAfi/Controller/Action/Helper/CatalogSearch.php b/library/ZendAfi/Controller/Action/Helper/CatalogSearch.php index 50e42ee40d51b2f2b75fd30480acece18e64bbfe..cb4b06eb3825a4f6d8e106a1a48cbcf5328d201b 100644 --- a/library/ZendAfi/Controller/Action/Helper/CatalogSearch.php +++ b/library/ZendAfi/Controller/Action/Helper/CatalogSearch.php @@ -24,15 +24,12 @@ class ZendAfi_Controller_Action_Helper_CatalogSearch extends ZendAfi_Controller_Action_Helper_Abstract { use Trait_InspectorGadget; - const SAISIE = 'saisie'; const RESET = 'reset'; - protected Class_CriteresRecherche $_criteria; protected array $_preferences; - public function direct(Class_CriteresRecherche $criteria) { return $this->catalogSearch($criteria); } @@ -86,17 +83,17 @@ class ZendAfi_Controller_Action_Helper_CatalogSearch $new_params = (new Class_CriteresRecherche_Params) ->applyTo($this->_criteria, $params); - if ( $new_params != $params) { + if ($new_params != $params) { $params = $new_params; $should_redirect = true; } - if ( $multifacets = $this->_extractMultifacetsPost()) { + if ($multifacets = $this->_extractMultifacetsPost()) { $this->_criteria->multifacetsUpdate($multifacets); $should_redirect = true; } - if ( $this->_request->isPost()) { + if ($this->_request->isPost()) { $should_redirect = true; $this->_criteria = (new Class_CriteresRecherche_AuthoritiesParam($params)) ->injectInto($this->_criteria); @@ -183,7 +180,7 @@ class ZendAfi_Controller_Action_Helper_CatalogSearch ? $title : $this->_view->_('Résultat de la recherche'); - if($this->_criteria->getPertinence()) + if($this->_criteria->isRelevant()) $this->_view->titre .= $this->_(' (recherche élargie triée par pertinence)'); $search_result @@ -216,9 +213,11 @@ class ZendAfi_Controller_Action_Helper_CatalogSearch } - protected function _extractMultifacetsPost() { + protected function _extractMultifacetsPost() : array { return $this->_request->isPost() - ? ZendAfi_View_Helper_Facettes::extractMultiFacets($this->_request->getPost()) + ? ZendAfi_View_Helper_Facettes::extractMultiFacets(($post = $this->_request->getPost()) + ? $post + : []) : []; } diff --git a/library/ZendAfi/Feed/SearchResultHeader.php b/library/ZendAfi/Feed/SearchResultHeader.php index e05d1db220b620c65dadcde106e9b91d0782cc9f..750440027e1bae78639fd3ed7eeba15c82c7ca99 100644 --- a/library/ZendAfi/Feed/SearchResultHeader.php +++ b/library/ZendAfi/Feed/SearchResultHeader.php @@ -18,15 +18,16 @@ * along with BOKEH; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + + class ZendAfi_Feed_SearchResultHeader { use Trait_Translator, Trait_SearchCriteriaVisitor; - protected - $_header, - $_criterias = [], - $_multi_facets = [], - $_description = ''; - + protected $_header; + protected array $_criterias = []; + protected array $_multi_facets = []; + protected string $_description = ''; + protected string $_tri = ''; public function __construct($header) { $this->_header = $header; @@ -56,39 +57,26 @@ class ZendAfi_Feed_SearchResultHeader { strtolower($criteria_labels[$name]). $this->_($type_recherche == 'commence' ? $this->_(' commence par') : ':') .' ' . $value; - $this->addCriteria($libelle); + $this->_addCriteria($libelle); } public function visitRubrique(string $rubrique, string $fil) : void { - $this->addCriteria($this->_('Rubrique'), - Class_Codification::getInstance()->getLibelleFacette($rubrique)); - } - - - public function visitSection(string $section) : void { - $this->addCriteria($this->_('Section'), - Class_Codification::getInstance()->getLibelleFacette('S' . $section)); + $this->_addCriteria($this->_('Rubrique'), + Class_Codification::getInstance()->getLibelleFacette($rubrique)); } - public function visitAnnexe(string $annexe) : void { - $this->addCriteria($this->_('Annexe'), - Class_Codification::getInstance()->getLibelleFacette('Y' . $annexe)); - } - - - public function visitSerie(string $serie, string $tri) : void { $title = Class_Notice::findFirstNoticeForClefChapeau($serie)->getTitreChapeau(); - $this->addCriteria($this->_('Série'), $title); + $this->_addCriteria($this->_('Série'), $title); } public function visitCodeRebond(string $code_rebond) : void { - $this->addCriteria($this->_('Recherche élargie à '), - Class_Codification::getInstance()->getLibelleFacette($code_rebond)); + $this->_addCriteria($this->_('Recherche élargie à '), + Class_Codification::getInstance()->getLibelleFacette($code_rebond)); } @@ -100,8 +88,12 @@ class ZendAfi_Feed_SearchResultHeader { $search_result->getRecordsCount()); $search_result->acceptCriteresVisitor($this); - $this->_injectMutiFacets(); - $this->_header->title = $this->_('Recherche: ').implode('. ', $this->_criterias); + $this->_injectMultiFacets(); + + if ($this->_tri) + $this->_addCriteria($this->_('Trié par: %s', $this->_tri)); + + $this->_header->title = $this->_('Recherche: ') . implode('. ', $this->_criterias); } @@ -116,14 +108,7 @@ class ZendAfi_Feed_SearchResultHeader { public function visitExpression(string $expression) : void { - $this->addCriteria($this->_('Expression'), $expression); - } - - - public function visitTypeDoc(array $type_docs) : void { - $type_doc = array_shift($type_docs); - $this->addCriteria($this->_('Type de document: %s', - Class_Codification::getInstance()->getLibelleFacette(Class_TypeDoc::CODE_FACETTE . $type_doc))); + $this->_addCriteria($this->_('Expression'), $expression); } @@ -132,34 +117,34 @@ class ZendAfi_Feed_SearchResultHeader { return; $libelle = $this->_('Nouveautés de moins de: ') . $nouveaute . ' ' . $this->_('mois'); - $this->addCriteria($libelle); + $this->_addCriteria($libelle); } public function visitCatalogue(Class_Catalogue $catalogue) : void { - $this->addCriteria($this->_('Domaine'), $catalogue->getLibelle()); + $this->_addCriteria($this->_('Domaine'), $catalogue->getLibelle()); } public function visitPanier(Class_PanierNotice $panier) : void { - $this->addCriteria($this->_('Panier'), $panier->getLibelle()); + $this->_addCriteria($this->_('Panier'), $panier->getLibelle()); } public function visitDigitalLib(bool $digital_lib) : void { if ($digital_lib) - $this->addCriteria($this->_('Bibliothèque numérique seulement')); + $this->_addCriteria($this->_('Bibliothèque numérique seulement')); } public function visitTri(string $tri, string $libelle) : void { - $this->addCriteria($this->_('Trié par: ') . $libelle); + $this->_tri = $libelle; } public function visitFacette(string $facette) : void { $facette = Class_Facet::find($facette); - $this->addCriteria($facette->getCodeRubriqueLibelle(), $facette->getLibelleFacette()); + $this->_addCriteria($facette->getCodeRubriqueLibelle(), $facette->getLibelleFacette()); } @@ -170,8 +155,8 @@ class ZendAfi_Feed_SearchResultHeader { $model = Class_Facet::find($facet); $key = $model->getCodeRubriqueLibelle(); if ( ! isset($this->_multi_facets[$key])) - $this->_multi_facets[$key] = []; - $this->_multi_facets[$key][] = $model->getLibelleFacette(); + $this->_multi_facets [$key] = []; + $this->_multi_facets [$key][] = $model->getLibelleFacette(); } @@ -179,18 +164,18 @@ class ZendAfi_Feed_SearchResultHeader { if ( ! $version) return; - $this->addCriteria($this->_('Nouveautés du %s', - strftime($this->_('%d %B %Y'), $version->getDate()))); + $this->_addCriteria($this->_('Nouveautés du %s', + strftime($this->_('%d %B %Y'), $version->getDate()))); } - protected function _injectMutiFacets() { - foreach($this->_multi_facets as $label => $values) - $this->addCriteria($label, implode($this->_(' OU ', $values))); + protected function _injectMultiFacets() : void { + foreach ($this->_multi_facets as $label => $values) + $this->_addCriteria($label, implode($this->_(' OU '), $values)); } - protected function addCriteria($name, $value = null) { - $this->_criterias []= $name . ($value ? (': ' . $value) : ''); + protected function _addCriteria(string $name, ?string $value = null) : void { + $this->_criterias [] = $name . ($value ? (': ' . $value) : ''); } } diff --git a/library/ZendAfi/View/Helper/Facettes.php b/library/ZendAfi/View/Helper/Facettes.php index c291e3d72d400792cd4d01b7b88832464370785e..9d8c04574ae68503ed48442cba13a8ffeee6c489 100644 --- a/library/ZendAfi/View/Helper/Facettes.php +++ b/library/ZendAfi/View/Helper/Facettes.php @@ -19,18 +19,17 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + class ZendAfi_View_Helper_Facettes extends ZendAfi_View_Helper_BaseHelper { const MULTI_FACET_KEY = 'multifacet_'; - protected $_criteres, $_current, $_preferences, $_wrapper_class = 'facette'; - public function facettes($facets, $preferences, $criteres) { if (!$facets) return; @@ -127,14 +126,14 @@ class ZendAfi_View_Helper_Facettes extends ZendAfi_View_Helper_BaseHelper { public function listeFacettesElementHTML($type, $values, $url, $closed = false) { $count = (new Class_AdminVar_UnleashedFacets())->isUnleashed($type) ? count($values) - : $this->_preferences['facettes_nombre']; + : (int) $this->_preferences['facettes_nombre']; $first_facets = array_splice($values, 0, $count); $following_facets = array_splice($values, 0, $count); $html = ''; - foreach($first_facets as $code => $count) - $html .= $this->renderLIFacette($url, $code, $count); + foreach ($first_facets as $code => $count) + $html .= $this->_renderLIFacette($url, $code, $count); if ($following_facets) $html .= $this->_renderFollowingFacets($type, $following_facets, $url); @@ -147,8 +146,8 @@ class ZendAfi_View_Helper_Facettes extends ZendAfi_View_Helper_BaseHelper { protected function _renderFollowingFacets($type, $facets, $url) { $html = ''; - foreach($facets as $code => $count) - $html .= $this->renderLIFacette($url, $code, $count); + foreach ($facets as $code => $count) + $html .= $this->_renderLIFacette($url, $code, $count); return $this ->_tag('li', @@ -169,20 +168,25 @@ class ZendAfi_View_Helper_Facettes extends ZendAfi_View_Helper_BaseHelper { } - public function renderLIFacette($url, $code, $count) { - $url['facette'] = $code; - return $this->renderLi($url, $code, $count); + protected function _renderLIFacette(array $url, string $code, int $count): string + { + $url ['facette'] = $code; + + return $this->_renderLi($url, $code, $count); } - protected function renderLi($url, $code, $count) { + protected function _renderLi(array $url, string $code, int $count): string + { $label = Class_Codification::getInstance()->getLibelleFacette($code); $title = Class_Codification::getInstance()->getNomChamp($code); return $this ->_tag('li', $this->_renderFacetHTML($code, $url, $label, $title, $count), - ['class' => 'facet_item facette' . ($this->isActive($code) ? ' selected' : '')]); + ['class' => 'facet_item facette' . ($this->_isActive($code) + ? ' selected' + : '')]); } @@ -196,12 +200,12 @@ class ZendAfi_View_Helper_Facettes extends ZendAfi_View_Helper_BaseHelper { protected function renderCheckbox($code, $label='') { - $attribs = ['checked' => $this->isMultiActive($code), + $attribs = ['checked' => $this->_isMultiActive($code), 'title' => $this->_('Sélectionner %s', $label)]; if (!$this->_preferences['multi_facettes']) $attribs['style'] = 'display: none;'; - return $this->view->formCheckbox($this->multiFacetNameFor($code), null, $attribs); + return $this->view->formCheckbox($this->_multiFacetNameFor($code), null, $attribs); } @@ -233,46 +237,48 @@ class ZendAfi_View_Helper_Facettes extends ZendAfi_View_Helper_BaseHelper { } - protected function isActive($code) { + protected function _isActive(string $code): bool + { return in_array($code, $this->_criteres->getFacettes()); } - protected function isMultiActive($code) { + protected function _isMultiActive(string $code) : bool { return in_array($code, $this->_criteres->getMultiFacets()); } - protected function multiFacetNameFor($code) { + protected function _multiFacetNameFor(string $code) : string { return static::MULTI_FACET_KEY . $code; } - public static function multifacetCodeFromKey($key) { + public static function multifacetCodeFromKey(string $key) : ?string { return static::isMultiFacetKey($key) ? substr($key, strlen(static::MULTI_FACET_KEY)) : null; } - public static function isMultiFacetKey($key) { + public static function isMultiFacetKey(string $key) : bool { return static::MULTI_FACET_KEY == substr($key, 0, strlen(static::MULTI_FACET_KEY)); } - public static function extractMultiFacets($datas) { - if (!$datas) - return null; + public static function extractMultiFacets(array $datas): array + { + if ( ! $datas) + return []; $facets = []; - foreach($datas as $k => $v) + foreach ($datas as $k => $v) $facets = static::_extractMultiFacet($facets, $k, $v); return $facets; } - protected static function _extractMultiFacet($facets, $k, $v) { + protected static function _extractMultiFacet(array $facets, string $k, $v) : array { if ($facet = static::multifacetCodeFromKey($k)) { - $facets[$facet] = $v; + $facets [$facet] = $v; return $facets; } @@ -282,8 +288,8 @@ class ZendAfi_View_Helper_Facettes extends ZendAfi_View_Helper_BaseHelper { if ('' === $v) return $facets; - if (!is_array($v)) { - $facets[$v] = 1; + if ( ! is_array($v)) { + $facets [$v] = 1; return $facets; } diff --git a/library/ZendAfi/View/Helper/SearchInspector.php b/library/ZendAfi/View/Helper/SearchInspector.php index e053af2093ce61cd4cdc2dbac6ef0047408a34a4..96dd4fb0fbbef62d6cc55480cedfc83e0f280fcd 100644 --- a/library/ZendAfi/View/Helper/SearchInspector.php +++ b/library/ZendAfi/View/Helper/SearchInspector.php @@ -21,13 +21,12 @@ class ZendAfi_View_Helper_SearchInspector extends ZendAfi_View_Helper_BaseHelper { - protected - $_datas = []; - public function searchInspector($search_result) { + protected array $_datas = []; - if (!$search_result) - return; + public function searchInspector(?Class_MoteurRecherche_Result $search_result) : string { + if ( ! $search_result) + return ''; $this->_datas = []; @@ -38,86 +37,33 @@ class ZendAfi_View_Helper_SearchInspector extends ZendAfi_View_Helper_BaseHelper } - protected function _renderDatas() { + protected function _renderDatas() : string { $html = ''; - foreach ($this->_datas as $label => $value) + + foreach ($this->_datas as $label => $values) $html .= $this->_tag('hr') . $this->_tag('h2', $label) - . $this->_tag('div', (string)$value); + . $this->_renderValues($values); return $html; } - public function visitAllFacettes($value) { - $this->_datas[$this->_('Toutes les facettes')] = $value; - return $this; - } - - - public function visitMultiFacets($value) { - $this->_datas[$this->_('Facettes multiples')] = json_encode($value); - return $this; - } - - - public function visitDomainConditions($value) { - $this->_datas[$this->_('Clauses issues du domaine')] = $value; - return $this; - } - - - public function visitFilterDomainConditions($value) { - $this->_datas[$this->_('Filtres issus du domaine')] = $value; - return $this; - } + protected function _renderValues($values) : string { + if ( ! is_array($values)) + return $this->_tag('div', (string) $values); + $html = ''; + foreach ($values as $value) + $html .= $this->_tag('li', $value); - public function visitConditions($value) { - $this->_datas[$this->_('Clauses simples')] = implode(' and ', $value); - return $this; + return $this->_tag('div', $this->_tag('ul', $html)); } public function visitQuery(string $sql) : self { - $this->_datas[$this->_('Requête')] = $sql; - - return $this; - } - - - public function visitConditionsWithOperator($value) { - $this->_datas[$this->_('Clauses avec opérateur')] = json_encode($value); - return $this; - } - - - public function visitOrConditions($value) { - $this->_datas[$this->_('Clauses en mode OU')] = json_encode($value); - return $this; - } - - - public function visitCompleteWhere($value) { - $this->_datas[$this->_('Clause where complète')] = $value; - return $this; - } - - - public function visitOrder($value) { - $this->_datas[$this->_('Ordre')] = $value ? $value : $this->_('aucun'); - return $this; - } - - - public function visitLimit($value) { - $this->_datas[$this->_('Limite')] = $value ? $value : $this->_('aucune'); - return $this; - } - + $this->_datas [$this->_('Requête')] = $sql; - public function visitMatchingSearchTerms($terms) { - $this->_datas[$this->_('Termes correspondant')] = json_encode($terms); return $this; } } diff --git a/library/ZendAfi/View/Helper/TagCriteresRecherche.php b/library/ZendAfi/View/Helper/TagCriteresRecherche.php index de246c6fcc7289c1e429dce5c624879c3c612480..66550787cac7aa76918bbe12a09cf0eea9db57ff 100644 --- a/library/ZendAfi/View/Helper/TagCriteresRecherche.php +++ b/library/ZendAfi/View/Helper/TagCriteresRecherche.php @@ -92,22 +92,6 @@ class ZendAfi_View_Helper_TagCriteresRecherche extends ZendAfi_View_Helper_BaseH } - public function visitAnnexe(string $annexe) : void { - $this - ->htmlAppend($this->view->_('Site: %s', Class_Codification::getInstance()->getLibelleFacette('Y' . $annexe))) - ->htmlAppend(' » ' . $this->_tag('a', $this->_('Elargir la recherche à tous les sites'), - ['href' => $this->view->url(['annexe' => null])])); - } - - - public function visitTypeDoc(array $type_docs) : void { - $type_doc = array_shift($type_docs); - $url = $this->_criteres_recherche->getUrlCriteresWithoutElement('type_doc'); - $libelle = $this->view->_('Type de document: %s', Class_Codification::getInstance()->getLibelleFacette('T' . $type_doc)); - $this->htmlAppend($this->getSuppressionImgUrlForLibelle($libelle, $url)); - } - - public function visitSerie(string $serie, string $tri) : void { $url = $this->_criteres_recherche->getUrlCriteresWithoutElement('serie'); $libelle = Class_Codification::getLibelleForSerie(Class_Notice::findFirstNoticeForClefChapeau($serie)); @@ -176,6 +160,20 @@ class ZendAfi_View_Helper_TagCriteresRecherche extends ZendAfi_View_Helper_BaseH } + public function visitMultiFacet(string $facet) : void { + if ( ! $facet) + return; + + $model = Class_Facet::find($facet); + $key = $model->getRubrique()->getCode(); + if ( ! isset($this->_multi_facets[$key])) + $this->_multi_facets[$key] = ['label' => $model->getCodeRubriqueLibelle(), + 'values' => []]; + + $this->_multi_facets[$key]['values'][] = $model->getLibelleFacette(); + } + + public function getSuppressionImgUrlForLibelle($libelle, $url) { unset($url['page']); $title = $this->view->_('Retirer le critère: %s', $libelle); @@ -218,13 +216,6 @@ class ZendAfi_View_Helper_TagCriteresRecherche extends ZendAfi_View_Helper_BaseH } - public function visitSection(string $section) : void { - $url = $this->_criteres_recherche->getUrlCriteresWithoutElement('section'); - $libelle = $this->_('Section: %s', Class_Codification::getInstance()->getLibelleFacette('S'.$section)); - $this->htmlAppend($this->getSuppressionImgUrlForLibelle($libelle,$url)); - } - - public function visitFiltre(array $filtre) : void { $labels = []; foreach ($filtre as $facet) { @@ -237,24 +228,10 @@ class ZendAfi_View_Helper_TagCriteresRecherche extends ZendAfi_View_Helper_BaseH } - public function visitMultiFacet(string $facet) : void { - if ( ! $facet) - return; - - $model = Class_Facet::find($facet); - $key = $model->getRubrique()->getCode(); - if ( ! isset($this->_multi_facets[$key])) - $this->_multi_facets[$key] = ['label' => $model->getCodeRubriqueLibelle(), - 'values' => []]; - - $this->_multi_facets[$key]['values'][] = $model->getLibelleFacette(); - } - - protected function _injectMultiFacets() { foreach($this->_multi_facets as $code => $definition) { $label = $definition['label'] . ': ' . implode($this->_(' OU '), $definition['values']); - $url = $this->_criteres_recherche->getUrlRemoveMultiFacet($code); + $url = $this->_criteres_recherche->getUrlRemoveMultiFacets($code); $this->htmlAppend($this->getSuppressionImgUrlForLibelle($label, $url)); } } diff --git a/library/digital_resources/Cvs/Query.php b/library/digital_resources/Cvs/Query.php index 1af016e09075930f50f996acb38958d3346c9961..7076682879be519220b2d2af07845718473ac2b2 100644 --- a/library/digital_resources/Cvs/Query.php +++ b/library/digital_resources/Cvs/Query.php @@ -65,7 +65,7 @@ class Cvs_Query { } - public function visitFacette($facette) { + public function visitFacette(string $facette) : void { $this->_query [] = Class_Codification::getInstance()->getLibelleFacette($facette); } diff --git a/library/storm b/library/storm index d5d3b5ac495e80816e4875c3d042f73d4faee3a9..471d1fa9475497f7933ea41654f672630a93cab1 160000 --- a/library/storm +++ b/library/storm @@ -1 +1 @@ -Subproject commit d5d3b5ac495e80816e4875c3d042f73d4faee3a9 +Subproject commit 471d1fa9475497f7933ea41654f672630a93cab1 diff --git a/library/templates/Chili/View/Search/Facets.php b/library/templates/Chili/View/Search/Facets.php index 280a5287d9b1ef3defd8d09c7a5e07d1f257b630..0dcfa837cd1b94c30479f26e10798354547af640 100644 --- a/library/templates/Chili/View/Search/Facets.php +++ b/library/templates/Chili/View/Search/Facets.php @@ -19,12 +19,11 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -class Chili_View_Search_Facets extends Intonation_View_Search_Facets { - protected - $_total = [], - $_uniq_id; +class Chili_View_Search_Facets extends Intonation_View_Search_Facets { + protected array $_total = []; + protected string $_uniq_id; public function search_Facets($facets, $preferences, $criteres) { $this->_uniq_id = uniqid(); @@ -62,7 +61,7 @@ class Chili_View_Search_Facets extends Intonation_View_Search_Facets { protected function renderCheckbox($code, $label='') { return $this->_preferences['multi_facettes'] - ? $this->view->formCheckbox($this->multiFacetNameFor($code), + ? $this->view->formCheckbox($this->_multiFacetNameFor($code), null, ['id' => $this->_getUniqId($code), 'checked' => $this->isMultiActive($code)]) @@ -71,7 +70,7 @@ class Chili_View_Search_Facets extends Intonation_View_Search_Facets { protected function _getUniqId($code) { - return $this->multiFacetNameFor($code) . '_' . $this->_uniq_id; + return $this->_multiFacetNameFor($code) . '_' . $this->_uniq_id; } diff --git a/library/templates/Intonation/Library/Search/Criteria.php b/library/templates/Intonation/Library/Search/Criteria.php index 69147835dd1ab667c1f43e2e444d3c4e0d63cf4b..e0567e8736959a9094a7f2fdab0a3036204809f5 100644 --- a/library/templates/Intonation/Library/Search/Criteria.php +++ b/library/templates/Intonation/Library/Search/Criteria.php @@ -24,26 +24,21 @@ class Intonation_Library_Search_Criteria extends Class_CriteresRecherche { protected bool $_could_be_save = true; - - public function getUrlRemoveFacette($facette) { - return $this->getUrlRemoveAllFacet($facette); + public function getUrlRemoveFacette(Class_Facet $facet) : array { + return $this->getUrlRemoveAllFacet($facet); } - public function getUrlRemoveAllFacet($facet) { - $code = $facet->getCodeRubrique(); - - $url_without_multifacet = $this->getUrlRemoveMultiFacet($code); + public function getUrlRemoveAllFacet(Class_Facet $facet) : array { + $url_without_multifacet = $this->getUrlRemoveMultiFacet($facet); $url_without_facet = parent::getUrlRemoveFacette($facet); $url = $this->getUrlRetourListe(); - $url['facettes'] = $url_without_facet['facettes'] ?? null; - $url['multifacets'] = $url_without_multifacet['multifacets'] ?? null; - $url['page'] = null; - $url['genre'] = null; - $url['facette'] = null; + $url ['facettes'] = $url_without_facet['facettes'] ?? null; + $url ['multifacets'] = $url_without_multifacet['multifacets'] ?? null; + $url ['page'] = null; return $url; } diff --git a/library/templates/Intonation/Library/Widget/Search/View.php b/library/templates/Intonation/Library/Widget/Search/View.php index db197baecf587eccd5733fdc3187974196967877..82cfa6ec531b27f272462aa1fe1d32620cf9f266 100644 --- a/library/templates/Intonation/Library/Widget/Search/View.php +++ b/library/templates/Intonation/Library/Widget/Search/View.php @@ -144,18 +144,17 @@ abstract class IntonationSearchRenderAbstract { } - public function visitFacette($facette) { + public function visitFacette(string $facette) { return $this->_extractFacetForForm(new Class_Facet($facette)); } - public function visitMultiFacet($facette) { + public function visitMultiFacet(string $facette) { return $this->_extractFacetForForm(new Class_Facet($facette)); } - public function visitThesaurusTextInput(string $id_thesaurus, string $expression) : void { - } + public function visitThesaurusTextInput(string $id_thesaurus, string $expression) : void {} protected function _extractFacetForForm($facet) { diff --git a/library/templates/Intonation/View/Search/HtmlCriteria.php b/library/templates/Intonation/View/Search/HtmlCriteria.php index 92ead3ba59f8845a3349340536ca21ccab6abfcb..d99abd6090aadb636ae540c3311e333614b6b350 100644 --- a/library/templates/Intonation/View/Search/HtmlCriteria.php +++ b/library/templates/Intonation/View/Search/HtmlCriteria.php @@ -28,7 +28,6 @@ class Intonation_View_Search_HtmlCriteria extends ZendAfi_View_Helper_TagCritere $_criteria, $_facets_cache = []; - public function search_HtmlCriteria($criteres_recherche) { if ($this->_cache) return $this->_cache; @@ -45,7 +44,6 @@ class Intonation_View_Search_HtmlCriteria extends ZendAfi_View_Helper_TagCritere } - protected function _wrapCriteria() { if ( ! $this->_html) return $this; @@ -100,7 +98,6 @@ class Intonation_View_Search_HtmlCriteria extends ZendAfi_View_Helper_TagCritere } - protected function _wrapHtml() { return $this->_html ? ($this->_tag('div', $this->_html, @@ -151,39 +148,30 @@ class Intonation_View_Search_HtmlCriteria extends ZendAfi_View_Helper_TagCritere } - public function visitAnnexe(string $annexe) : void { - $text = $this->_('Site: %s', - Class_Codification::getInstance()->getLibelleFacette('Y' . $annexe)); - - $url = $this->_criteres_recherche->getUrlCriteresWithoutElement('annexe'); - - $this->htmlAppend($this->getSuppressionImgUrlForLibelle($text, $url)); - } - - public function htmlAppend($text, $attribs = []) { if (empty($attribs)) $attribs = ['class' => 'd-inline text-left align-items-center']; + return parent::htmlAppend($text, $attribs); } public function visitFacette(string $facette) : void { - $facet = new Class_Facet($facette); - $facet_label = $facet->getLibelleFacette(); + $this->_facets_cache [] = $this->_labelFacet($facette); - $this->_facets_cache [] = $facet_label; parent::visitFacette($facette); } public function visitMultiFacet(string $facet) : void { - $facette = new Class_Facet($facet); - $facel_label = $facette->getLibelleFacette(); - - if ( in_array($facel_label, $this->_facets_cache)) + if (in_array($this->_labelFacet($facet), $this->_facets_cache)) return; parent::visitMultiFacet($facet); } + + + protected function _labelFacet(string $facet) : string { + return (new Class_Facet($facet))->getLibelleFacette(); + } } diff --git a/library/templates/Intonation/View/Search/TextCriteria.php b/library/templates/Intonation/View/Search/TextCriteria.php index 526aed48b2d40482fb9ec9c0a27b35dcf0965856..4b31ae73352b94c8ee8877b345f802f2f3eac6df 100644 --- a/library/templates/Intonation/View/Search/TextCriteria.php +++ b/library/templates/Intonation/View/Search/TextCriteria.php @@ -55,12 +55,6 @@ class Intonation_View_Search_TextCriteria extends Intonation_View_Search_HtmlCri } - public function visitAnnexe(string $annexe) : void { - $this - ->htmlAppend($this->view->_('Site: %s', Class_Codification::getInstance()->getLibelleFacette('Y' . $annexe))); - } - - public function getSuppressionImgUrlForLibelle($label, $url) { return $label; } diff --git a/scripts/emacs/yasnippet/snippets/text-mode/php-mode/__construct b/scripts/emacs/yasnippet/snippets/text-mode/php-mode/__construct index fe1dff34f0d43c5c4165c61621f18d925c8de3e2..e867ff58879eed7c6bd5f1916901de6cfb72a5d8 100644 --- a/scripts/emacs/yasnippet/snippets/text-mode/php-mode/__construct +++ b/scripts/emacs/yasnippet/snippets/text-mode/php-mode/__construct @@ -1,6 +1,7 @@ #contributor : Patrick Barroca <pbarroca@afi-sa.fr> #name : __construct ... # -- -public function __construct() { +public function __construct() +{ $0 } \ No newline at end of file diff --git a/scripts/emacs/yasnippet/snippets/text-mode/php-mode/class b/scripts/emacs/yasnippet/snippets/text-mode/php-mode/class index 0ae04cf01ef22de9fb284ea98ac72bab952f2583..ffe5331b20464632f7ecefa9fbb854345c2bda13 100644 --- a/scripts/emacs/yasnippet/snippets/text-mode/php-mode/class +++ b/scripts/emacs/yasnippet/snippets/text-mode/php-mode/class @@ -3,7 +3,7 @@ # -- <?php /** - * Copyright (c) 2012-2023, Agence Française Informatique (AFI). All rights reserved. + * Copyright (c) 2012-2024, Agence Française Informatique (AFI). All rights reserved. * * BOKEH is free software; you can redistribute it and/or modify * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by diff --git a/scripts/emacs/yasnippet/snippets/text-mode/php-mode/pro b/scripts/emacs/yasnippet/snippets/text-mode/php-mode/pro index 113c44d6520fd07523bd1c91934775e854549372..b408358d4ce841003af56e45d8b8b54a22266fb4 100644 --- a/scripts/emacs/yasnippet/snippets/text-mode/php-mode/pro +++ b/scripts/emacs/yasnippet/snippets/text-mode/php-mode/pro @@ -1,6 +1,7 @@ #contributor : Ghislain Loas <gloas@afi-sa.fr>, Patrick Barroca <pbarroca@afi-sa.fr> #name : pro # -- -protected function _${name}(${params}) : ${return_type} { +protected function _${name}(${params}): ${return_type} +{ return $0; } \ No newline at end of file diff --git a/scripts/emacs/yasnippet/snippets/text-mode/php-mode/pub b/scripts/emacs/yasnippet/snippets/text-mode/php-mode/pub index 4cc783d2d06f3d08ab3d555efccddd67da28cd09..a925e79bb14ef6aad39d08234281b8ac9271d737 100644 --- a/scripts/emacs/yasnippet/snippets/text-mode/php-mode/pub +++ b/scripts/emacs/yasnippet/snippets/text-mode/php-mode/pub @@ -1,6 +1,7 @@ #contributor : Ghislain Loas <gloas@afi-sa.fr>, Patrick Barroca <pbarroca@afi-sa.fr> #name : pub # -- -public function ${name}(${params}) : ${return_type} { +public function ${name}(${params}): ${return_type} +{ return $0; } \ No newline at end of file diff --git a/scripts/emacs/yasnippet/snippets/text-mode/php-mode/setup b/scripts/emacs/yasnippet/snippets/text-mode/php-mode/setup index c2eaa8ec6d56e24442c45da212cf9ee7427a6ed6..2d860fd4314294fbc15d817676564dc8c7c572b9 100644 --- a/scripts/emacs/yasnippet/snippets/text-mode/php-mode/setup +++ b/scripts/emacs/yasnippet/snippets/text-mode/php-mode/setup @@ -1,7 +1,8 @@ #contributor : Laurent Laffont <llaffont@afi-sa.fr> #name : funct ...(...) # -- -public function setUp() { +public function setUp() +{ parent::setUp(); $0 } \ No newline at end of file diff --git a/scripts/emacs/yasnippet/snippets/text-mode/php-mode/should b/scripts/emacs/yasnippet/snippets/text-mode/php-mode/should index 26f5d62b8c5e8305e4701511c258322c6d29d60a..75b8d71b13e39d70fc3ef6f83766ddc3580dc498 100644 --- a/scripts/emacs/yasnippet/snippets/text-mode/php-mode/should +++ b/scripts/emacs/yasnippet/snippets/text-mode/php-mode/should @@ -2,6 +2,7 @@ #name : should ...(...) # -- /** @test */ -public function ${context}Should${Expectation}() { +public function ${context}Should${Expectation}() +{ $0 } \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/RechercheControllerAtomTest.php b/tests/application/modules/opac/controllers/RechercheControllerAtomTest.php index 9f4cb35598e4e1725f105ca0b9a31093c5e1f932..4c95931340c77419db69bbc8f1b80a88474abe28 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerAtomTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerAtomTest.php @@ -451,6 +451,6 @@ class RechercheControllerAtomWithAdvancedSearchTest public function feedTitleShouldContainsRechercheAllCriteriasAndPertinence() { $this->_xpath->assertXPathContentContains($this->_response->getBody(), '//atom:feed/atom:title', - 'Recherche: titre: potter. Ou auteur: rowling. Section: Adulte. Annexe: Annecy. Trié par: Pertinence'); + 'Recherche: titre: potter. Ou auteur: rowling. Section: Adulte. Site: Annecy. Trié par: Pertinence'); } } diff --git a/tests/application/modules/opac/controllers/RechercheControllerTest.php b/tests/application/modules/opac/controllers/RechercheControllerTest.php index 90944a559b9f239e2d1d9fbed0c6ee2bec7a545a..dfcea7c7018a2578db68f60a9af87db3ede7e2ed 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerTest.php @@ -2118,7 +2118,7 @@ class RechercheControllerSimpleActionLibelleFacetteTest /** @test */ public function criteresRechercheShouldContainsLEcole() { - $this->assertXPathContentContains('//div[@class="criteres_recherche"]//div//a[@href="/recherche/simple/operateur_auteurs/and/rech_auteurs/musso/operateur_dewey/and/rech_dewey/pomme/type_recherche/fulltext/tri/%2A/genre/1%3B19/rech_thesaurus_SUJE/Japon/rech_thesaurus_UNKN/Unknown+stuff"]', + $this->assertXPathContentContains('//div[@class="criteres_recherche"]//div//a[@href="/recherche/simple/operateur_auteurs/and/rech_auteurs/musso/operateur_dewey/and/rech_dewey/pomme/type_recherche/fulltext/tri/%2A/rech_thesaurus_SUJE/Japon/rech_thesaurus_UNKN/Unknown+stuff/multifacets/G1-G19"]', 'Éditeur : l\'ecole'); } @@ -3576,7 +3576,7 @@ class RechercheControlleSiteInResultAndModeThumbnailTest class RechercheControllerMultiFacettesTest extends RechercheControllerNoticeTestCase { /** @test */ - public function postShouldRedirectToMultifacetsT1T4() { + public function postShouldRedirectToMultifacets_T1_T4() { $this->postDispatch('/recherche/simple/expressionRecherche/pomme/tri/*', ['multifacet_T1' => 1, 'multifacet_T4' => 1]); diff --git a/tests/library/Class/AvisNoticeTest.php b/tests/library/Class/AvisNoticeTest.php index e26436f1630a6ace4336f5c0150821b70e2da94c..69a0b41894bf049a5edb99aa863306faf21bd755 100644 --- a/tests/library/Class/AvisNoticeTest.php +++ b/tests/library/Class/AvisNoticeTest.php @@ -681,8 +681,7 @@ class AvisNoticeAvisFromPreferencesTest extends ModelTestCase { $this->assertEquals([3, 4], array_map(fn($avis) => $avis->getId(), Class_AvisNotice::getAvisFromPreferences(['id_panier' => 1]))); - $this->assertSqlEquals(["SELECT `codif_type_doc`.* FROM `codif_type_doc` WHERE (`codif_type_doc`.`type_doc_id` LIKE 'Cvs2%')", - "SELECT `avis_notices`.`id` FROM `notices_avis` AS `avis_notices` INNER JOIN `notices` ON `avis_notices`.`clef_oeuvre` = `notices`.`clef_oeuvre` AND `notices`.`clef_alpha` IN ('POTTER--HARRY') AND `notices`.`type` = 1 WHERE (`avis_notices`.`flags` = 0 AND (`avis_notices`.`statut` = 1 OR `avis_notices`.`abon_ou_bib` = 1) AND (`avis_notices`.`statut` = 1 OR `avis_notices`.`abon_ou_bib` = 0)) ORDER BY `avis_notices`.`date_avis` DESC LIMIT 30", + $this->assertSqlEquals(["SELECT `avis_notices`.`id` FROM `notices_avis` AS `avis_notices` INNER JOIN `notices` ON `avis_notices`.`clef_oeuvre` = `notices`.`clef_oeuvre` AND `notices`.`clef_alpha` IN ('POTTER--HARRY') AND `notices`.`type` = 1 WHERE (`avis_notices`.`flags` = 0 AND (`avis_notices`.`statut` = 1 OR `avis_notices`.`abon_ou_bib` = 1) AND (`avis_notices`.`statut` = 1 OR `avis_notices`.`abon_ou_bib` = 0)) ORDER BY `avis_notices`.`date_avis` DESC LIMIT 30", "SELECT `notices_avis`.* FROM `notices_avis` WHERE (`notices_avis`.`id` IN (3, 4)) ORDER BY `notices_avis`.`date_avis` DESC"]); } @@ -693,8 +692,7 @@ class AvisNoticeAvisFromPreferencesTest extends ModelTestCase { array_map(fn($avis) => $avis->getId(), Class_AvisNotice::getAvisFromPreferences(['id_panier' => 1, 'abon_ou_bib' => 0]))); - $this->assertSqlEquals(["SELECT `codif_type_doc`.* FROM `codif_type_doc` WHERE (`codif_type_doc`.`type_doc_id` LIKE 'Cvs2%')", - "SELECT `avis_notices`.`id` FROM `notices_avis` AS `avis_notices` INNER JOIN `notices` ON `avis_notices`.`clef_oeuvre` = `notices`.`clef_oeuvre` AND `notices`.`clef_alpha` IN ('POTTER--HARRY') AND `notices`.`type` = 1 WHERE (`avis_notices`.`flags` = 0 AND `avis_notices`.`abon_ou_bib` = 0 AND (`avis_notices`.`statut` = 1 OR `avis_notices`.`abon_ou_bib` = 1) AND (`avis_notices`.`statut` = 1 OR `avis_notices`.`abon_ou_bib` = 0)) ORDER BY `avis_notices`.`date_avis` DESC LIMIT 30", + $this->assertSqlEquals(["SELECT `avis_notices`.`id` FROM `notices_avis` AS `avis_notices` INNER JOIN `notices` ON `avis_notices`.`clef_oeuvre` = `notices`.`clef_oeuvre` AND `notices`.`clef_alpha` IN ('POTTER--HARRY') AND `notices`.`type` = 1 WHERE (`avis_notices`.`flags` = 0 AND `avis_notices`.`abon_ou_bib` = 0 AND (`avis_notices`.`statut` = 1 OR `avis_notices`.`abon_ou_bib` = 1) AND (`avis_notices`.`statut` = 1 OR `avis_notices`.`abon_ou_bib` = 0)) ORDER BY `avis_notices`.`date_avis` DESC LIMIT 30", "SELECT `notices_avis`.* FROM `notices_avis` WHERE (`notices_avis`.`id` IN (3)) ORDER BY `notices_avis`.`date_avis` DESC"]); } @@ -705,8 +703,7 @@ class AvisNoticeAvisFromPreferencesTest extends ModelTestCase { array_map(fn($avis) => $avis->getId(), Class_AvisNotice::getAvisFromPreferences(['id_panier' => 1, 'abon_ou_bib' => 1]))); - $this->assertSqlEquals(["SELECT `codif_type_doc`.* FROM `codif_type_doc` WHERE (`codif_type_doc`.`type_doc_id` LIKE 'Cvs2%')", - "SELECT `avis_notices`.`id` FROM `notices_avis` AS `avis_notices` INNER JOIN `notices` ON `avis_notices`.`clef_oeuvre` = `notices`.`clef_oeuvre` AND `notices`.`clef_alpha` IN ('POTTER--HARRY') AND `notices`.`type` = 1 WHERE (`avis_notices`.`flags` = 0 AND `avis_notices`.`abon_ou_bib` = 1 AND (`avis_notices`.`statut` = 1 OR `avis_notices`.`abon_ou_bib` = 1) AND (`avis_notices`.`statut` = 1 OR `avis_notices`.`abon_ou_bib` = 0)) ORDER BY `avis_notices`.`date_avis` DESC LIMIT 30", + $this->assertSqlEquals(["SELECT `avis_notices`.`id` FROM `notices_avis` AS `avis_notices` INNER JOIN `notices` ON `avis_notices`.`clef_oeuvre` = `notices`.`clef_oeuvre` AND `notices`.`clef_alpha` IN ('POTTER--HARRY') AND `notices`.`type` = 1 WHERE (`avis_notices`.`flags` = 0 AND `avis_notices`.`abon_ou_bib` = 1 AND (`avis_notices`.`statut` = 1 OR `avis_notices`.`abon_ou_bib` = 1) AND (`avis_notices`.`statut` = 1 OR `avis_notices`.`abon_ou_bib` = 0)) ORDER BY `avis_notices`.`date_avis` DESC LIMIT 30", "SELECT `notices_avis`.* FROM `notices_avis` WHERE (`notices_avis`.`id` IN (4)) ORDER BY `notices_avis`.`date_avis` DESC"]); } @@ -718,8 +715,7 @@ class AvisNoticeAvisFromPreferencesTest extends ModelTestCase { array_map(fn($avis) => $avis->getId(), Class_AvisNotice::getAvisFromPreferences(['id_panier' => 1, 'abon_ou_bib' => 0]))); - $this->assertSqlEquals(["SELECT `codif_type_doc`.* FROM `codif_type_doc` WHERE (`codif_type_doc`.`type_doc_id` LIKE 'Cvs2%')", - "SELECT `avis_notices`.`id` FROM `notices_avis` AS `avis_notices` INNER JOIN `notices` ON `avis_notices`.`clef_oeuvre` = `notices`.`clef_oeuvre` AND `notices`.`clef_alpha` IN ('POTTER--HARRY') AND `notices`.`type` = 1 WHERE (`avis_notices`.`flags` = 0 AND `avis_notices`.`abon_ou_bib` = 0 AND (`avis_notices`.`statut` = 1 OR `avis_notices`.`abon_ou_bib` = 0)) ORDER BY `avis_notices`.`date_avis` DESC LIMIT 30", + $this->assertSqlEquals(["SELECT `avis_notices`.`id` FROM `notices_avis` AS `avis_notices` INNER JOIN `notices` ON `avis_notices`.`clef_oeuvre` = `notices`.`clef_oeuvre` AND `notices`.`clef_alpha` IN ('POTTER--HARRY') AND `notices`.`type` = 1 WHERE (`avis_notices`.`flags` = 0 AND `avis_notices`.`abon_ou_bib` = 0 AND (`avis_notices`.`statut` = 1 OR `avis_notices`.`abon_ou_bib` = 0)) ORDER BY `avis_notices`.`date_avis` DESC LIMIT 30", "SELECT `notices_avis`.* FROM `notices_avis` WHERE (`notices_avis`.`id` IN (1, 3)) ORDER BY `notices_avis`.`date_avis` DESC"]); } @@ -731,8 +727,7 @@ class AvisNoticeAvisFromPreferencesTest extends ModelTestCase { array_map(fn($avis) => $avis->getId(), Class_AvisNotice::getAvisFromPreferences(['id_panier' => 1, 'abon_ou_bib' => 'all']))); - $this->assertSqlEquals(["SELECT `codif_type_doc`.* FROM `codif_type_doc` WHERE (`codif_type_doc`.`type_doc_id` LIKE 'Cvs2%')", - "SELECT `avis_notices`.`id` FROM `notices_avis` AS `avis_notices` INNER JOIN `notices` ON `avis_notices`.`clef_oeuvre` = `notices`.`clef_oeuvre` AND `notices`.`clef_alpha` IN ('POTTER--HARRY') AND `notices`.`type` = 1 WHERE (`avis_notices`.`flags` = 0 AND (`avis_notices`.`statut` = 1 OR `avis_notices`.`abon_ou_bib` = 0)) ORDER BY `avis_notices`.`date_avis` DESC LIMIT 30", + $this->assertSqlEquals(["SELECT `avis_notices`.`id` FROM `notices_avis` AS `avis_notices` INNER JOIN `notices` ON `avis_notices`.`clef_oeuvre` = `notices`.`clef_oeuvre` AND `notices`.`clef_alpha` IN ('POTTER--HARRY') AND `notices`.`type` = 1 WHERE (`avis_notices`.`flags` = 0 AND (`avis_notices`.`statut` = 1 OR `avis_notices`.`abon_ou_bib` = 0)) ORDER BY `avis_notices`.`date_avis` DESC LIMIT 30", "SELECT `notices_avis`.* FROM `notices_avis` WHERE (`notices_avis`.`id` IN (1, 3, 4)) ORDER BY `notices_avis`.`date_avis` DESC"]); } @@ -745,8 +740,7 @@ class AvisNoticeAvisFromPreferencesTest extends ModelTestCase { Class_AvisNotice::getAvisFromPreferences(['id_panier' => 1, 'nb_aff_avis' => 2, 'abon_ou_bib' => 'all']))); - $this->assertSqlEquals(["SELECT `codif_type_doc`.* FROM `codif_type_doc` WHERE (`codif_type_doc`.`type_doc_id` LIKE 'Cvs2%')", - "SELECT `avis_notices`.`id` FROM `notices_avis` AS `avis_notices` INNER JOIN `notices` ON `avis_notices`.`clef_oeuvre` = `notices`.`clef_oeuvre` AND `notices`.`clef_alpha` IN ('POTTER--HARRY') AND `notices`.`type` = 1 WHERE (`avis_notices`.`flags` = 0 AND (`avis_notices`.`statut` = 1 OR `avis_notices`.`abon_ou_bib` = 0)) ORDER BY `avis_notices`.`date_avis` DESC LIMIT 6", + $this->assertSqlEquals(["SELECT `avis_notices`.`id` FROM `notices_avis` AS `avis_notices` INNER JOIN `notices` ON `avis_notices`.`clef_oeuvre` = `notices`.`clef_oeuvre` AND `notices`.`clef_alpha` IN ('POTTER--HARRY') AND `notices`.`type` = 1 WHERE (`avis_notices`.`flags` = 0 AND (`avis_notices`.`statut` = 1 OR `avis_notices`.`abon_ou_bib` = 0)) ORDER BY `avis_notices`.`date_avis` DESC LIMIT 6", "SELECT `notices_avis`.* FROM `notices_avis` WHERE (`notices_avis`.`id` IN (1, 3, 4)) ORDER BY `notices_avis`.`date_avis` DESC"]); } @@ -759,8 +753,7 @@ class AvisNoticeAvisFromPreferencesTest extends ModelTestCase { array_map(fn($avis) => $avis->getId(), Class_AvisNotice::getAvisFromPreferences(['id_panier' => 1, 'abon_ou_bib' => 'all']))); - $this->assertSqlEquals(["SELECT `codif_type_doc`.* FROM `codif_type_doc` WHERE (`codif_type_doc`.`type_doc_id` LIKE 'Cvs2%')", - "SELECT `avis_notices`.`id` FROM `notices_avis` AS `avis_notices` INNER JOIN `notices` ON `avis_notices`.`clef_oeuvre` = `notices`.`clef_oeuvre` AND `notices`.`clef_alpha` IN ('POTTER--HARRY') AND `notices`.`type` = 1 WHERE (`avis_notices`.`flags` = 0 AND (`avis_notices`.`statut` = 1 OR `avis_notices`.`abon_ou_bib` = 1)) ORDER BY `avis_notices`.`date_avis` DESC LIMIT 30", + $this->assertSqlEquals(["SELECT `avis_notices`.`id` FROM `notices_avis` AS `avis_notices` INNER JOIN `notices` ON `avis_notices`.`clef_oeuvre` = `notices`.`clef_oeuvre` AND `notices`.`clef_alpha` IN ('POTTER--HARRY') AND `notices`.`type` = 1 WHERE (`avis_notices`.`flags` = 0 AND (`avis_notices`.`statut` = 1 OR `avis_notices`.`abon_ou_bib` = 1)) ORDER BY `avis_notices`.`date_avis` DESC LIMIT 30", "SELECT `notices_avis`.* FROM `notices_avis` WHERE (`notices_avis`.`id` IN (2, 3, 4)) ORDER BY `notices_avis`.`date_avis` DESC"]); } diff --git a/tests/library/Class/CatalogueTest.php b/tests/library/Class/CatalogueTest.php index d5cd9b9bf51e82a00f35821a7d16e8cb23faefe2..bae3a8ad303b5f9336241683ef072ea20fd41e5a 100644 --- a/tests/library/Class/CatalogueTest.php +++ b/tests/library/Class/CatalogueTest.php @@ -293,7 +293,7 @@ class CatalogueGetSelectionFacetteTest extends CatalogueTestCase { $this->_fetchRequestsBy(['id_catalogue' => $domain->getId()]); $expected_request ? $this->assertSql($expected_request) - : $this->assertSqlEquals(["SELECT `codif_type_doc`.* FROM `codif_type_doc` WHERE (`codif_type_doc`.`type_doc_id` LIKE 'Cvs2%')"]); + : $this->assertSqlEmpty(); } @@ -364,8 +364,7 @@ class CatalogueGetRequetesWithFacettesAndNoCatalogueTest extends CatalogueTestCa $this->_fetchRequestsBy($params, 'req_ids'); $this->_fetchRequestsBy($params, 'req_facettes'); - $this->assertSqlEquals(["SELECT `codif_type_doc`.* FROM `codif_type_doc` WHERE (`codif_type_doc`.`type_doc_id` LIKE 'Cvs2%')", - "SELECT `notices`.* FROM `notices` WHERE ((`notices`.`url_vignette` > '' AND `notices`.`url_vignette` != 'NO') AND `notices`.`type` = 1) LIMIT 50", + $this->assertSqlEquals(["SELECT `notices`.* FROM `notices` WHERE ((`notices`.`url_vignette` > '' AND `notices`.`url_vignette` != 'NO') AND `notices`.`type` = 1) LIMIT 50", "SELECT COUNT(*) AS `numberof` FROM `notices` WHERE ((`notices`.`url_vignette` > '' AND `notices`.`url_vignette` != 'NO') AND `notices`.`type` = 1)", "SELECT `notices`.`id_notice` FROM `notices` WHERE ((`notices`.`url_vignette` > '' AND `notices`.`url_vignette` != 'NO') AND `notices`.`type` = 1) LIMIT 50", "SELECT `notices`.`id_notice`, `notices`.`type_doc`, `notices`.`facettes` FROM `notices` WHERE ((`notices`.`url_vignette` > '' AND `notices`.`url_vignette` != 'NO') AND `notices`.`type` = 1) LIMIT 50"]); diff --git a/tests/library/Class/CriteresRechercheTest.php b/tests/library/Class/CriteresRechercheTest.php index 57b71d35c2a4de996ce7cbe934341038c7b81f20..43cc67ad05a2818a9f87939120debbcad0b77d8f 100644 --- a/tests/library/Class/CriteresRechercheTest.php +++ b/tests/library/Class/CriteresRechercheTest.php @@ -36,6 +36,7 @@ abstract class CriteresRechercheTestCase extends ModelTestCase { class CriteresRechercheRetourTest extends CriteresRechercheTestCase { + public function expectedUrls() { return [ @@ -123,7 +124,6 @@ class CriteresRechercheRetourTest extends CriteresRechercheTestCase { 'action' => 'index', 'id_panier' => '23']], - [['retour_abonne' => 'loans-history', 'page' => 2, 'page_size' => 10], @@ -146,7 +146,6 @@ class CriteresRechercheRetourTest extends CriteresRechercheTestCase { ['controller' => 'abonne', 'action' => 'prets']], - [['id_panier' => '23', 'retour_abonne' => 'prets', 'retour_avis' => 5, @@ -175,7 +174,7 @@ class CriteresRechercheRetourTest extends CriteresRechercheTestCase { ['controller' => 'recherche', 'action' => 'simple', - 'genre' => '10;13']] + 'multifacets' => 'G10-G13']] ]; } @@ -203,7 +202,6 @@ class CriteresRechercheRetourRechercheInitialeTest 'action' => 'saisie', 'expressionRecherche' => 'millenium']], - [['rech_titres' => 'metropolitan', 'rech_auteurs' =>'', 'code_rebond' => 'A333'], ['controller' => 'recherche', @@ -238,6 +236,7 @@ class CriteresRechercheRetourRechercheInitialeTest class CriteresRechercheNouvelleTest extends CriteresRechercheTestCase { + public function expectedUrls() { return [[['expressionRecherche' => 'millenium', 'code_rebond' => 'A26'], @@ -269,6 +268,7 @@ class CriteresRechercheNouvelleTest extends CriteresRechercheTestCase { class CriteresRechercheUrlFacetteTest extends CriteresRechercheTestCase { + public function expectedUrls() { return [[['expressionRecherche' => '1q84', 'code_rebond' => 'A26', @@ -280,7 +280,6 @@ class CriteresRechercheUrlFacetteTest extends CriteresRechercheTestCase { 'code_rebond' => 'A26', 'facettes' => 'T3']], - [['rech_titres' => 'metropolitan', 'rech_auteurs' =>'', 'facettes' => 'T1-YMET'], @@ -290,7 +289,6 @@ class CriteresRechercheUrlFacetteTest extends CriteresRechercheTestCase { 'rech_titres' => 'metropolitan', 'facettes' => 'T1-YMET']], - [['rech_titres' => 'metropolitan', 'rech_auteurs' =>'', 'operateur_editeur' => 'and', @@ -303,7 +301,6 @@ class CriteresRechercheUrlFacetteTest extends CriteresRechercheTestCase { 'rech_titres' => 'metropolitan', 'facettes' => 'T1-YMET']], - [['id_catalogue' => '100', 'filtres' => 'B1;B2'], @@ -328,6 +325,7 @@ class CriteresRechercheUrlFacetteTest extends CriteresRechercheTestCase { class CriteresRechercheFilterParamsTest extends CriteresRechercheTestCase { + public function expectedUrls() { return [[['expressionRecherche' => '1q84', 'code_rebond' => 'A26', @@ -361,7 +359,6 @@ class CriteresRechercheFilterParamsTest extends CriteresRechercheTestCase { ['rech_titres' => 'No-logo', 'operateur_titres' => 'or']], - [['expressionRecherche' => 'Oz', 'serie' =>'OZ'], @@ -383,8 +380,10 @@ class CriteresRechercheFilterParamsTest extends CriteresRechercheTestCase { class CriteresRechercheSerieTest extends CriteresRechercheTestCase { + public function setUp() { parent::setUp(); + $this->criteres_recherche->setParams(['id_catalogue' => 3, 'id_panier' => 2, 'serie' => 'CASSIO']); @@ -413,7 +412,9 @@ class CriteresRechercheSerieTest extends CriteresRechercheTestCase { + class CriteresRechercheCatalogueSortTest extends CriteresRechercheTestCase { + /** @test */ public function shouldBeSortedByPublication() { $this->criteres_recherche->setParams(['id_catalogue' => 2]); @@ -425,9 +426,12 @@ class CriteresRechercheCatalogueSortTest extends CriteresRechercheTestCase { + class CriteresRechercheWithGenreTest extends AbstractControllerTestCase { + public function setUp() { parent::setUp(); + $this->criteres_recherche = new Class_CriteresRecherche(); $this->criteres_recherche->setParams(['genre' => '10;56']); } @@ -444,6 +448,7 @@ class CriteresRechercheWithGenreTest extends AbstractControllerTestCase { + class TestingSearchCriteriaVisitor { use Trait_SearchCriteriaVisitor; } diff --git a/tests/library/Class/MoteurRechercheTest.php b/tests/library/Class/MoteurRechercheTest.php index 04bfb28ecbcdefbdb1ad7a705f6e6d4bd72bd20f..761defeaf827ad5d980efb4b5a9de0165b16ff1a 100644 --- a/tests/library/Class/MoteurRechercheTest.php +++ b/tests/library/Class/MoteurRechercheTest.php @@ -150,7 +150,7 @@ class MoteurRechercheAvanceeTest extends MoteurRechercheTestCase { 'type_recherche' => 'commence', 'pertinence' => true, 'tri' => 'alpha_titre'], - 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((`notices`.`auteurs` LIKE 'P_CLASTRES%' AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_YMED1 +(F_YTUN F_YTAP)' IN BOOLEAN MODE)) AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC"], + 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((`notices`.`auteurs` LIKE 'P_CLASTRES%' AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+(F_YTUN F_YTAP) +F_YMED1' IN BOOLEAN MODE)) AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC"], [['rech_matieres' => 'Philosophie', 'operateur_matieres' => 'and not', @@ -195,7 +195,7 @@ class MoteurRechercheAvanceeTest extends MoteurRechercheTestCase { 'type_recherche' => 'commence', 'pertinence' => true, 'tri' => 'alpha_titre'], - 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((`notices`.`auteurs` LIKE 'P_STIEGLER%' AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_YMED1 +F_G23 +F_A345 +(F_YTUN F_YTAP) +(F_S1 F_S12 F_S9) +(F_B3 F_B4)' IN BOOLEAN MODE)) AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC"], + 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((`notices`.`auteurs` LIKE 'P_STIEGLER%' AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_G23 +F_A345 +(F_YTUN F_YTAP) +(F_S1 F_S12 F_S9) +(F_B3 F_B4) +F_YMED1' IN BOOLEAN MODE)) AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC"], [['rech_titres' => 'Les décisions absurdes', 'operateur_auteurs' => 'and', @@ -207,7 +207,7 @@ class MoteurRechercheAvanceeTest extends MoteurRechercheTestCase { 'type_recherche' => 'commence', 'pertinence' => true, 'tri' => 'alpha_titre'], - 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((`notices`.`titres` LIKE 'P_LES P_DECISIONS P_ABSURDES%' AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_S1 +F_YMED1 +F_M4669 +(F_YTUN F_YTAP) +(F_B3 F_B4)' IN BOOLEAN MODE)) AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC"], + 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((`notices`.`titres` LIKE 'P_LES P_DECISIONS P_ABSURDES%' AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_M4669 +(F_YTUN F_YTAP) +(F_B3 F_B4) +F_S1 +F_YMED1' IN BOOLEAN MODE)) AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC"], [['rech_auteurs' => 'Stiegler', 'operateur_auteurs' => 'and', @@ -220,7 +220,7 @@ class MoteurRechercheAvanceeTest extends MoteurRechercheTestCase { 'type_recherche' => 'commence', 'pertinence' => true, 'tri' => 'alpha_titre'], - 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((`notices`.`auteurs` LIKE 'P_STIEGLER%' AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_YMED1 +F_G23 +F_A345 +(F_T1 F_Tbokeh_page) +(F_YTUN F_YTAP) +(F_S1 F_S12 F_S9) +F_B3' IN BOOLEAN MODE)) AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC"], + 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((`notices`.`auteurs` LIKE 'P_STIEGLER%' AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_G23 +F_A345 +(F_T1 F_Tbokeh_page) +(F_YTUN F_YTAP) +(F_S1 F_S12 F_S9) +F_B3 +F_YMED1' IN BOOLEAN MODE)) AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC"], [['rech_titres' => 'parquets', 'operateur_titres' => 'and'], @@ -318,7 +318,7 @@ class MoteurRechercheSimpleTest extends MoteurRechercheTestCase { 'selection_annexe' => 'TUN;TAP', 'tri' => 'alpha_titre', 'no_extension' => '1'], - 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+(COMMUNE COMMUNES KOMUN) +(PARI PARIS) +F_YMED1 +(F_YTUN F_YTAP)' IN BOOLEAN MODE) AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC"], + 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+(COMMUNE COMMUNES KOMUN) +(PARI PARIS) +(F_YTUN F_YTAP) +F_YMED1' IN BOOLEAN MODE) AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC"], [['expressionRecherche' => '2-7427-3315-9', 'geo_zone' => 2, @@ -353,7 +353,7 @@ class MoteurRechercheSimpleTest extends MoteurRechercheTestCase { 'selection_annexe' => 'TUN;TAP', 'selection_sections' => '1;12;9', 'no_extension' => '1'], - 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+(LOGO LOGOS) +F_YMED1 +F_M52291 +F_A15067 +(F_YTUN F_YTAP) +(F_S1 F_S12 F_S9)' IN BOOLEAN MODE) AND `notices`.`type` = 1) ORDER BY MATCH(`notices`.`auteurs`) AGAINST('P_LOGO') DESC, MATCH(`notices`.`titres`) AGAINST('P_LOGO') DESC, MATCH(`notices`.`titres`) AGAINST('LOGO') DESC, MATCH(`notices`.`auteurs`) AGAINST('LOGO') DESC, `notices`.`date_creation` DESC"], + 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+(LOGO LOGOS) +F_M52291 +F_A15067 +(F_YTUN F_YTAP) +(F_S1 F_S12 F_S9) +F_YMED1' IN BOOLEAN MODE) AND `notices`.`type` = 1) ORDER BY MATCH(`notices`.`auteurs`) AGAINST('P_LOGO') DESC, MATCH(`notices`.`titres`) AGAINST('P_LOGO') DESC, MATCH(`notices`.`titres`) AGAINST('LOGO') DESC, MATCH(`notices`.`auteurs`) AGAINST('LOGO') DESC, `notices`.`date_creation` DESC"], [['expressionRecherche' => 'logo', 'multifacets' => 'Tper_title', @@ -369,7 +369,7 @@ class MoteurRechercheSimpleTest extends MoteurRechercheTestCase { 'type_doc' => 'delete("*"),1,uraiets,2', 'selection_sections' => '1;goup<ip;9', 'no_extension' => '1'], - 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+(SECURITY SECURITYS SEKURITI) +(F_T1 F_T2) +F_Y8 +(F_S1 F_S9) +F_E34 +F_B12' IN BOOLEAN MODE) AND `notices`.`type` = 1) ORDER BY MATCH(`notices`.`auteurs`) AGAINST('P_SECURITY') DESC, MATCH(`notices`.`titres`) AGAINST('P_SECURITY') DESC, MATCH(`notices`.`titres`) AGAINST('SECURITY') DESC, MATCH(`notices`.`auteurs`) AGAINST('SECURITY') DESC, `notices`.`date_creation` DESC"], + 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+(SECURITY SECURITYS SEKURITI) +F_Y8 +(F_S1 F_S9) +F_E34 +F_B12 +(F_T1 F_Turaiets F_T2)' IN BOOLEAN MODE) AND `notices`.`type` = 1) ORDER BY MATCH(`notices`.`auteurs`) AGAINST('P_SECURITY') DESC, MATCH(`notices`.`titres`) AGAINST('P_SECURITY') DESC, MATCH(`notices`.`titres`) AGAINST('SECURITY') DESC, MATCH(`notices`.`auteurs`) AGAINST('SECURITY') DESC, `notices`.`date_creation` DESC"], [['expressionRecherche' => '', 'digital_lib' => '1'], @@ -557,7 +557,7 @@ class MoteurRechercheRebondTest extends MoteurRechercheTestCase { 'code_rebond' => 'A888', 'annexe' => 'MEDIAT', 'type_doc' => '1'], - 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_A888' IN BOOLEAN MODE) AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC"], + 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_A888 +F_YMEDIAT +F_T1' IN BOOLEAN MODE) AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC"], [['rech_auteurs' => 'The Ex', 'operateur_auteurs' => 'or', @@ -1002,6 +1002,19 @@ class MoteurRechercheExtendingTest extends MoteurRechercheTestCase { $this->assertSqlEquals(["SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+(VIE VIES VI) +(GEEK GEEKS JEK)' IN BOOLEAN MODE) AND `notices`.`type` = 1) ORDER BY MATCH(`notices`.`titres`, `notices`.`auteurs`) AGAINST('\"LA VIE DES GEEKS\"' IN BOOLEAN MODE) DESC, MATCH(`notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`) AGAINST('\"LA VIE DES GEEKS\"' IN BOOLEAN MODE) DESC, MATCH(`notices`.`auteurs`) AGAINST('P_VIE P_GEEKS') DESC, MATCH(`notices`.`titres`) AGAINST('P_VIE P_GEEKS') DESC, MATCH(`notices`.`titres`) AGAINST('VIE GEEKS') DESC, MATCH(`notices`.`auteurs`) AGAINST('VIE GEEKS') DESC, `notices`.`date_creation` DESC"]); } + + + /** @test */ + public function withoutResultInAxeParamsSearchShouldExtend() { + (new Class_MoteurRecherche) + ->lancerRecherche((new Class_CriteresRecherche) + ->setParams(['axes' => 'a10renard+poisson', + 'titre' => 'Recherche+avancée'])); + + $this->assertSqlEquals(["SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (MATCH(`notices`.`titres`) AGAINST('(+(RENARD RENARDS RENAR) +(POISSON POISSONS POISON))' IN BOOLEAN MODE) AND `notices`.`type` = 1)", + + "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (MATCH(`notices`.`titres`) AGAINST('RENARD RENARDS RENAR POISSON POISSONS POISON' IN BOOLEAN MODE) AND `notices`.`type` = 1)"]); + } } diff --git a/tests/library/ZendAfi/View/Helper/FacettesTest.php b/tests/library/ZendAfi/View/Helper/FacettesTest.php index bca48ae262e833d550a8c56265333561097e0bfb..661001b87d756fcdf66d446d11f238db65dfe883 100644 --- a/tests/library/ZendAfi/View/Helper/FacettesTest.php +++ b/tests/library/ZendAfi/View/Helper/FacettesTest.php @@ -19,73 +19,101 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + abstract class ZendAfi_View_Helper_FacettesTestCase extends ViewHelperTestCase { - protected - $_html, - $_storm_default_to_volatile = true; + + protected $_html; public function setUp() { parent::setUp(); - $this->_helper = new ZendAfi_View_Helper_Facettes(); + $this->_helper = new ZendAfi_View_Helper_Facettes; $this->_helper->setView(new ZendAfi_Controller_Action_Helper_View()); $this->_prepareFixtures(); - $this->fixture('Class_CodifMatiere', + $this->fixture(Class_CodifMatiere::class, ['id' => 6567, 'libelle' => 'Pommes : albums']); - $this->fixture('Class_CodifThesaurus', + $this->fixture(Class_CodifThesaurus::class, ['id' => 1, 'id_thesaurus' => 'GENR0001', 'libelle' => 'Electron libre.']); - $this->fixture('Class_CodifAnnexe', + $this->fixture(Class_CodifSection::class, + ['id' => 1, + 'libelle' => 'Adultes']); + $this->fixture(Class_CodifSection::class, + ['id' => 2, + 'libelle' => 'Jeunesses']); + $this->fixture(Class_CodifSection::class, + ['id' => 3, + 'libelle' => 'Adolescents']); + + $this->fixture(Class_CodifGenre::class, + ['id' => 4, + 'libelle' => 'Romans']); + $this->fixture(Class_CodifGenre::class, + ['id' => 5, + 'libelle' => 'Mangas']); + $this->fixture(Class_CodifGenre::class, + ['id' => 6, + 'libelle' => 'Policiers']); + + $this->fixture(Class_CodifAnnexe::class, ['id' => 1, 'id_origine' => 'MDE', 'libelle' => 'Maison environnement']); - - $this->fixture('Class_CodifAuteur', + $this->fixture(Class_CodifAnnexe::class, + ['id' => 2, + 'id_origine' => 'SEY', + 'libelle' => 'Seynod']); + $this->fixture(Class_CodifAnnexe::class, + ['id' => 3, + 'id_origine' => 'MEY', + 'libelle' => 'Meythet']); + + $this->fixture(Class_CodifAuteur::class, ['id' => '4656', 'libelle' => 'Caradog Prichard',]); - - $this->fixture('Class_CodifAuteur', + $this->fixture(Class_CodifAuteur::class, ['id' => '4657', 'libelle' => 'Louis-Jean Calvet']); - - $this->fixture('Class_CodifAuteur', + $this->fixture(Class_CodifAuteur::class, ['id' => '6752', 'libelle' => 'Maurice Henry']); - - $this->fixture('Class_CodifAuteur', + $this->fixture(Class_CodifAuteur::class, ['id' => '63246', 'libelle' => 'François Chattot']); - - $this->fixture('Class_CodifAuteur', + $this->fixture(Class_CodifAuteur::class, ['id' => '12309', 'libelle' => 'Olivier Richard']); - - $this->fixture('Class_CodifAuteur', + $this->fixture(Class_CodifAuteur::class, ['id' => '446', 'libelle' => 'Clare Brown']); - - $this->fixture('Class_CodifAuteur', + $this->fixture(Class_CodifAuteur::class, ['id' => '800', 'libelle' => 'Karine Delobbe']); - - $this->fixture('Class_CodifAuteur', + $this->fixture(Class_CodifAuteur::class, ['id' => '12168', 'libelle' => 'Mehdi Lallaoui']); - - $this->fixture('Class_CodifAuteur', + $this->fixture(Class_CodifAuteur::class, ['id' => '9875', 'libelle' => 'Régine Azria']); $this->_facettes = ['T' => ['T1' => 34], 'M' => ['M6567' => 22], 'HGENR' => ['HGENR0001' => 1], - 'Y' => ['YMDE' => 1], + 'Y' => ['YMDE' => 1, + 'YSEY' => 1, + 'YMEY' => 1], + 'S' => ['S1' => 1, + 'S2' => 1, + 'S3' => 1], + 'G' => ['G4' => 1, + 'G5' => 1, + 'G6' => 1], 'A' => ['A4656' => 58, 'A4657' => 40, 'A6752' => 21, @@ -98,7 +126,6 @@ abstract class ZendAfi_View_Helper_FacettesTestCase extends ViewHelperTestCase { $this->_html = $this->_helper ->facettes($this->_facettes, - ['facettes_codes' => 'Y;A;M;HGENR', 'multi_facettes' => 1, 'facettes_nombre' => 2], @@ -107,16 +134,18 @@ abstract class ZendAfi_View_Helper_FacettesTestCase extends ViewHelperTestCase { } - protected function _prepareFixtures() { - } + protected function _prepareFixtures() {} } + class ZendAfi_View_Helper_FacettesRestrainedTest extends ZendAfi_View_Helper_FacettesTestCase { protected function _prepareFixtures() { - $this->fixture('Class_AdminVar', ['id' => 'UNLEASHED_FACETS', 'valeur' => '']); + $this->fixture(Class_AdminVar::class, + ['id' => 'UNLEASHED_FACETS', + 'valeur' => '']); } @@ -172,12 +201,10 @@ class ZendAfi_View_Helper_FacettesRestrainedTest extends ZendAfi_View_Helper_Fac /** @test */ public function facetFrancoisChattotTitleShouldContainsRefineSearchForAuthor() { $this->assertXPath($this->_html, - '//a[@class="facette"][contains(@href, "/A63246")][contains(@title, "Affiner le résultat par auteur: François Chattot")]', $this->_html); + '//a[@class="facette"][contains(@href, "/A63246")][contains(@title, "Affiner le résultat par auteur: François Chattot")]'); } - - /** @test */ public function linkForFacetOlivierRichardShouldNotBePresent() { $this->assertNotXPath($this->_html, @@ -195,6 +222,7 @@ class ZendAfi_View_Helper_FacettesRestrainedTest extends ZendAfi_View_Helper_Fac + class ZendAfi_View_Helper_FacettesUnleashedTest extends ZendAfi_View_Helper_FacettesTestCase { @@ -216,7 +244,9 @@ class ZendAfi_View_Helper_FacettesUnleashedTest class ZendAfi_View_Helper_MultiFacettesTest extends ZendAfi_View_Helper_FacettesTestCase { protected function _prepareFixtures() { - $this->fixture('Class_AdminVar', ['id' => 'UNLEASHED_FACETS', 'valeur' => '']); + $this->fixture(Class_AdminVar::class, + ['id' => 'UNLEASHED_FACETS', + 'valeur' => '']); } @@ -229,15 +259,15 @@ class ZendAfi_View_Helper_MultiFacettesTest extends ZendAfi_View_Helper_Facettes /** @test */ public function checkboxForFacetT1houldBePresent() { - $this->assertXPath($this->_html, - '//li[@class="facet_item facette"]//input[@name="multifacet_T1"][@value="1"]', $this->_html); + $this->assertXPath($this->_html, + '//li[@class="facet_item facette"]//input[@name="multifacet_T1"][@value="1"]'); } /** @test */ public function hiddenCheckboxForFacetT1houldBePresent() { - $this->assertXPath($this->_html, - '//li[@class="facet_item facette"]//input[@name="multifacet_T1"][@value="0"][@type="hidden"]', $this->_html); + $this->assertXPath($this->_html, + '//li[@class="facet_item facette"]//input[@name="multifacet_T1"][@value="0"][@type="hidden"]'); } } @@ -251,7 +281,6 @@ class ZendAfi_View_Helper_DisabledMultiFacettesTest extends ZendAfi_View_Helper_ $this->_html = $this->_helper ->facettes($this->_facettes, - ['facettes_codes' => 'Y;A;M;HGENR', 'multi_facettes' => 0, 'facettes_nombre' => 2], @@ -261,20 +290,114 @@ class ZendAfi_View_Helper_DisabledMultiFacettesTest extends ZendAfi_View_Helper_ protected function _prepareFixtures() { - $this->fixture('Class_AdminVar', ['id' => 'UNLEASHED_FACETS', 'valeur' => '']); + $this->fixture(Class_AdminVar::class, + ['id' => 'UNLEASHED_FACETS', + 'valeur' => '']); } /** @test */ public function buttonAfinerForMultiFacetshouldBeHidden() { $this->assertXPathContentContains($this->_html, - '//div[@class="facette"]/form//button[@style="display: none;"][@name="multi_facets_submit"]', 'Affiner'); + '//div[@class="facette"]/form//button[@style="display: none;"][@name="multi_facets_submit"]', 'Affiner'); } /** @test */ public function checkboxForFacetT1houldBeHidden() { - $this->assertXPath($this->_html, - '//li[@class="facet_item facette"]//input[@style="display: none;"][@name="multifacet_T1"][@value="1"]', $this->_html); + $this->assertXPath($this->_html, + '//li[@class="facet_item facette"]//input[@style="display: none;"][@name="multifacet_T1"][@value="1"]'); } -} \ No newline at end of file +} + + + + +class ZendAfi_View_Helper_FacettesFromAdvancedSearchTest + extends ZendAfi_View_Helper_FacettesTestCase { + + public function setUp() { + parent::setUp(); + + $this->_html = $this->_helper + ->facettes($this->_facettes, + ['facettes_codes' => 'S;Y;A;M;G', + 'multi_facettes' => 1, + 'facettes_nombre' => 2], + + new Class_CriteresRecherche(['expressionRecherche' => '*', + 'section' => '1;2', + 'annexe' => 'MDE;ANE', + 'multifacets' => 'G5-G6'])); + } + + + protected function _prepareFixtures() { + $this->fixture(Class_AdminVar::class, + ['id' => 'UNLEASHED_FACETS', + 'valeur' => '']); + } + + + /** @test */ + public function checkboxForFacetYMDEshouldNotBeChecked() { + $this->assertXPath($this->_html, + '//li[@class="facet_item facette"]//input[@name="multifacet_YMDE"][@value="0"]'); + } + + + /** @test */ + public function checkboxForFacetYSEYshouldBeChecked() { + $this->assertXPath($this->_html, + '//li[@class="facet_item facette"]//input[@name="multifacet_YSEY"][@value="1"]'); + } + + + /** @test */ + public function checkboxForFacetYMEYshouldBeChecked() { + $this->assertXPath($this->_html, + '//li[@class="facet_item facette"]//input[@name="multifacet_YMEY"][@value="1"]'); + } + + + /** @test */ + public function checkboxForFacetS1shouldBeChecked() { + $this->assertXPath($this->_html, + '//li[@class="facet_item facette"]//input[@name="multifacet_S1"][@value="1"]'); + } + + + /** @test */ + public function checkboxForFacetS2shouldBeChecked() { + $this->assertXPath($this->_html, + '//li[@class="facet_item facette"]//input[@name="multifacet_S2"][@value="1"]'); + } + + + /** @test */ + public function checkboxForFacetS3shouldNotBeChecked() { + $this->assertXPath($this->_html, + '//li[@class="facet_item facette"]//input[@name="multifacet_S3"][@value="0"]'); + } + + + /** @test */ + public function checkboxForFacetG4shouldBeChecked() { + $this->assertXPath($this->_html, + '//li[@class="facet_item facette"]//input[@name="multifacet_G4"][@value="1"]'); + } + + + /** @test */ + public function checkboxForFacetG5shouldBeChecked() { + $this->assertXPath($this->_html, + '//li[@class="facet_item facette"]//input[@name="multifacet_G5"][@value="1"]'); + } + + + /** @test */ + public function checkboxForFacetG6shouldNotBeChecked() { + $this->assertXPath($this->_html, + '//li[@class="facet_item facette"]//input[@name="multifacet_G6"][@value="0"]'); + } +} diff --git a/tests/scenarios/AdvancedSearch/AdvancedSearchResultTest.php b/tests/scenarios/AdvancedSearch/AdvancedSearchResultTest.php index 1e724c8b2886431df5ea0239f187b2a01c078405..15e54476e008321fa063029bd4158c81555f2012 100644 --- a/tests/scenarios/AdvancedSearch/AdvancedSearchResultTest.php +++ b/tests/scenarios/AdvancedSearch/AdvancedSearchResultTest.php @@ -109,6 +109,8 @@ class AdvancedSearchResultAxesToSqlTest extends AbstractControllerTestCase { public function setUp() { parent::setUp(); + Class_AdminVar::set('EXTENDED_SEARCH', '0'); + $this->fixture(Class_Notice::class, ['id' => 5203, 'type' => Class_Notice::TYPE_AUTHORITY, @@ -168,13 +170,13 @@ class AdvancedSearchResultAxesToSqlTest extends AbstractControllerTestCase { "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+(F_T3 F_T4)' IN BOOLEAN MODE) AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+(F_S50 F_S49)' IN BOOLEAN MODE) AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+(F_T6 F_T7)' IN BOOLEAN MODE) AND NOT MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+(F_T5 F_T9 F_G3)' IN BOOLEAN MODE)) AND `notices`.`type` = 1)"], ['n0T5-0T9-10mis%C3%A9rables-10la+vengeance', // one block negated with facets and titles - "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((NOT MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+(F_T5 F_T9)' IN BOOLEAN MODE) AND NOT MATCH(`notices`.`titres`) AGAINST('+(MISERABLE MISERABLES MISERABL VENGEANCE VENGEANCES VANJANS)' IN BOOLEAN MODE)) AND `notices`.`type` = 1)"], + "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((NOT MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+(F_T5 F_T9)' IN BOOLEAN MODE) AND NOT MATCH(`notices`.`titres`) AGAINST('MISERABLE MISERABLES MISERABL VENGEANCE VENGEANCES VANJANS' IN BOOLEAN MODE)) AND `notices`.`type` = 1)"], ['n0T5-0T9-10mis%C3%A9rables%7Ea10la+vengeance', // two blocks with titles - "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (((NOT MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+(F_T5 F_T9)' IN BOOLEAN MODE) AND NOT MATCH(`notices`.`titres`) AGAINST('+(MISERABLE MISERABLES MISERABL)' IN BOOLEAN MODE)) AND MATCH(`notices`.`titres`) AGAINST('+(VENGEANCE VENGEANCES VANJANS)' IN BOOLEAN MODE)) AND `notices`.`type` = 1)"], + "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (((NOT MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+(F_T5 F_T9)' IN BOOLEAN MODE) AND NOT MATCH(`notices`.`titres`) AGAINST('MISERABLE MISERABLES MISERABL' IN BOOLEAN MODE)) AND MATCH(`notices`.`titres`) AGAINST('VENGEANCE VENGEANCES VANJANS' IN BOOLEAN MODE)) AND `notices`.`type` = 1)"], ['a11hugo-10spagetti-12patate-13gallimard-14poche', // one block with author - "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((MATCH(`notices`.`auteurs`) AGAINST('+(HUGO HUGOS UGO)' IN BOOLEAN MODE) OR MATCH(`notices`.`titres`) AGAINST('+(SPAGETTI SPAGETTIS SPAJETI)' IN BOOLEAN MODE) OR MATCH(`notices`.`matieres`) AGAINST('+(PATATE PATATES PATAT)' IN BOOLEAN MODE) OR MATCH(`notices`.`editeur`) AGAINST('+(GALLIMARD GALLIMARDS GALIMAR)' IN BOOLEAN MODE) OR MATCH(`notices`.`collection`) AGAINST('+(POCHE POCHES POCH)' IN BOOLEAN MODE)) AND `notices`.`type` = 1)"], + "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((MATCH(`notices`.`auteurs`) AGAINST('HUGO HUGOS UGO' IN BOOLEAN MODE) OR MATCH(`notices`.`titres`) AGAINST('SPAGETTI SPAGETTIS SPAJETI' IN BOOLEAN MODE) OR MATCH(`notices`.`matieres`) AGAINST('PATATE PATATES PATAT' IN BOOLEAN MODE) OR MATCH(`notices`.`editeur`) AGAINST('GALLIMARD GALLIMARDS GALIMAR' IN BOOLEAN MODE) OR MATCH(`notices`.`collection`) AGAINST('POCHE POCHES POCH' IN BOOLEAN MODE)) AND `notices`.`type` = 1)"], ['a2DOC1bizarre-2DOC1%C3%A9trange-2DOC1pas+fr%C3%A9quent', // fulltext dynamic facet "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((MATCH(`notices`.`other_terms`) AGAINST('+HDOC1_BIZARRE' IN BOOLEAN MODE) OR MATCH(`notices`.`other_terms`) AGAINST('+HDOC1_ETRANGE' IN BOOLEAN MODE) OR MATCH(`notices`.`other_terms`) AGAINST('+HDOC1_PAS +HDOC1_FREQUENT' IN BOOLEAN MODE)) AND `notices`.`type` = 1)"], @@ -188,11 +190,17 @@ class AdvancedSearchResultAxesToSqlTest extends AbstractControllerTestCase { ['a12%22bien+commun%22-12%22biens+communs%22', "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (MATCH(`notices`.`matieres`) AGAINST('\"BIEN COMMUN\" \"BIENS COMMUNS\"' IN BOOLEAN MODE) AND `notices`.`type` = 1)"], - ['a12bien+commun-12biens+communs', - "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (MATCH(`notices`.`matieres`) AGAINST('+(BIEN BIENS COMMUN COMMUNS)' IN BOOLEAN MODE) AND `notices`.`type` = 1)"], + ['a10bien+commun-10oeuvre+litéraire', + "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (MATCH(`notices`.`titres`) AGAINST('(+(BIEN BIENS BIN) +(COMMUN COMMUNS KOMIN)) (+(OEUVRE OEUVRES EVR) +(LITERAIRE LITERAIRES LITERAIR))' IN BOOLEAN MODE) AND `notices`.`type` = 1)"], ['a12%22bien+commun%22~a12%22biens+communs%22', - "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((MATCH(`notices`.`matieres`) AGAINST('\"BIEN COMMUN\"' IN BOOLEAN MODE) AND MATCH(`notices`.`matieres`) AGAINST('\"BIENS COMMUNS\"' IN BOOLEAN MODE)) AND `notices`.`type` = 1)"] + "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((MATCH(`notices`.`matieres`) AGAINST('\"BIEN COMMUN\"' IN BOOLEAN MODE) AND MATCH(`notices`.`matieres`) AGAINST('\"BIENS COMMUNS\"' IN BOOLEAN MODE)) AND `notices`.`type` = 1)"], + + ['a10renard+poisson', + "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (MATCH(`notices`.`titres`) AGAINST('(+(RENARD RENARDS RENAR) +(POISSON POISSONS POISON))' IN BOOLEAN MODE) AND `notices`.`type` = 1)"], + + ['a10bois-10escaliers', + "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (MATCH(`notices`.`titres`) AGAINST('BOI BOIS ESCALIER ESCALIERS ESKALI' IN BOOLEAN MODE) AND `notices`.`type` = 1)"] ]; } diff --git a/tests/scenarios/AdvancedSearch/AdvancedSearchTest.php b/tests/scenarios/AdvancedSearch/AdvancedSearchTest.php index fe5609d60d7452640502e8de59454e2b3f219185..2aec72cce09a17f80b02540358bfddacbed3ba8c 100644 --- a/tests/scenarios/AdvancedSearch/AdvancedSearchTest.php +++ b/tests/scenarios/AdvancedSearch/AdvancedSearchTest.php @@ -42,19 +42,19 @@ abstract class AdvancedSearchTestCase extends AbstractControllerTestCase { protected function _prepareFixtures() { - $this->fixture('Class_CosmoVar', + $this->fixture(Class_CosmoVar::class, ['id' => 'types_docs', 'liste' => '0:non identifié\r\n1:livre\r\n2:article']); - $this->fixture('Class_TypeDoc', + $this->fixture(Class_TypeDoc::class, ['id' => 1, 'label' => 'Livre']); - $this->fixture('Class_TypeDoc', + $this->fixture(Class_TypeDoc::class, ['id' => 2, 'label' => 'Article']); - $this->fixture('Class_TypeDoc', + $this->fixture(Class_TypeDoc::class, ['id' => 'Assimil', 'label' => 'Langue']); @@ -62,7 +62,7 @@ abstract class AdvancedSearchTestCase extends AbstractControllerTestCase { ->whenCalled('findUsedTypeDocIds') ->answers([1, 2, 'Assimil']); - $this->fixture('Class_CodifAnnexe', + $this->fixture(Class_CodifAnnexe::class, ['id' => '42', 'libelle' => 'My super annexe', 'id_origine' => 'MSA']); } } @@ -71,6 +71,7 @@ abstract class AdvancedSearchTestCase extends AbstractControllerTestCase { class AdvancedSearchDefaultTest extends AdvancedSearchTestCase { + /** @test */ public function formActionShouldBeRechercheSimple() { $this->assertXPath('//form[contains(@action,"/recherche/simple")]'); @@ -174,8 +175,10 @@ class AdvancedSearchDefaultTest extends AdvancedSearchTestCase { class AdvancedSearchWithCustomFormDefaultTest extends AdvancedSearchDefaultTest { + protected function _prepareFixtures() { parent::_prepareFixtures(); + Class_AdminVar::set('CUSTOM_SEARCH_FORM', 1); } @@ -195,7 +198,6 @@ abstract class AdvancedSearchCustomFormSelectedTestCase extends AdvancedSearchTe $_file_system, $_form_filename = 'userfiles/forms/form.php'; - protected function _prepareFixtures() { parent::_prepareFixtures(); @@ -243,7 +245,10 @@ class AdvancedSearchNofileCustomFormSelectedTest protected function _prepareFixtures() { parent::_prepareFixtures(); - $this->fixture('Class_SearchForm', ['id' => 3, 'filename' => '']); + + $this->fixture(Class_SearchForm::class, + ['id' => 3, + 'filename' => '']); } @@ -261,10 +266,12 @@ class AdvancedSearchNofileCustomFormSelectedNotLoggedTest protected function _prepareFixtures() { parent::_prepareFixtures(); + ZendAfi_Auth::getInstance()->clearIdentity(); - $this->fixture('Class_SearchForm', ['id' => 3, - 'label' => 'DVD', - 'filename' => '']); + $this->fixture(Class_SearchForm::class, + ['id' => 3, + 'label' => 'DVD', + 'filename' => '']); } @@ -409,7 +416,6 @@ class AdvancedSearchFormWithDateSelectorsTest extends AdvancedSearchCustomFormSe 'rule_list_label_length' => [4] ]); - $this->fixture(Class_CodifThesaurus::class, ['id' => 2, 'libelle' => 'Mois de publication', @@ -450,7 +456,6 @@ class AdvancedSearchFormWithDateSelectorsTest extends AdvancedSearchCustomFormSe 'code' => 'UNIMARC', ]); - $this->_file_system ->filePutContents(ROOT_PATH . $this->_form_filename, '<?php ?>'); @@ -579,7 +584,6 @@ abstract class AdvancedSearchValidCustomFormsSelectedAndPublishedTestCase '<?php ?>') ->cd(ROOT_PATH); - Class_SearchForm::setIncluder( function($path, $form) use ($title_search_form, $author_search_form) { if ($path == $author_search_form) @@ -668,14 +672,14 @@ class AdvancedSearchResetSecondFormTest /** @test */ public function resetFormIdOneShouldActivateFormIdOne() { - $this->dispatch('/recherche/avancee/statut/reset/form_id/1', true); + $this->dispatch('/recherche/avancee/statut/reset/form_id/1'); $this->assertXPathContentContains('//script', '.tabify({active:1})'); } /** @test */ public function resetFormEmptyShouldActivateFormIdZero() { - $this->dispatch('/recherche/avancee/statut/reset', true); + $this->dispatch('/recherche/avancee/statut/reset'); $this->assertXPathContentContains('//script', '.tabify({active:0})'); } } @@ -746,7 +750,7 @@ class AdvancedSearchFileManagerPhpFileDispatchTest extends Admin_AbstractControl ->answers('<?php echo "toto"; ?>'); Class_FileManager::setFileSystem($disk); - $this->dispatch('/admin/file-manager/index?browser=userfiles%2Fform.php&focused_browser=browser', true); + $this->dispatch('/admin/file-manager/index?browser=userfiles%2Fform.php&focused_browser=browser'); } @@ -771,51 +775,6 @@ class AdvancedSearchFileManagerPhpFileDispatchTest extends Admin_AbstractControl -class AdvancedSearchMultiFacetsPostDispatchTest extends Admin_AbstractControllerTestCase { - public function setUp() { - parent::setUp(); - $this->fixture('Class_CodifThesaurus', - ['id' => 3, - 'libelle' => 'Document', - 'libelle_facette' => 'Document', - 'id_thesaurus' => 'DOCU', - 'id_origine' => null, - 'code' => 'DOCU', - 'rule_list_zone' => ['995'], - 'rule_list_label_field' => ['t']]); - - $this->fixture('Class_CodifThesaurus', - ['id' => 4, - 'libelle' => 'SIFI', - 'libelle_facette' => 'Science fiction', - 'id_thesaurus' => 'DOCU0001', - 'id_origine' => null, - 'code' => 'DOCU', - 'rule_list_zone' => ['999'], - 'rule_list_label_field' => ['t']]); - } - - - /** @test */ - public function shouldRedirectToRechercheSimpleMultifacetsA12MinusA42MinusM608() { - $this->postDispatch('/recherche/simple', ['custom_multifacets_author' => ['A12', 'A42'], - 'custom_multifacets_subject' => 'M608']); - $this->assertRedirectTo('/recherche/simple/multifacets/A12-A42-M608'); - } - - - - /** @test */ - public function mixMultifacetsAndDynamicFacetsShouldMergeFacets() { - $this->postDispatch('/recherche/simple', ['custom_multifacets_author' => ['A12', 'A42'], - 'custom_multifacets_subject' => 'M608', - 'rech_HDOCU' => 'SIFI']); - $this->assertRedirectTo('/recherche/simple/multifacets/HDOCU0001-A12-A42-M608'); - } -} - - - abstract class AdvancedSearchFormWithPostCacheTestCase extends AdvancedSearchCustomFormSelectedTestCase { @@ -829,7 +788,7 @@ abstract class AdvancedSearchFormWithPostCacheTestCase 'super_input_fulltext_dynamic_facet_DOC1' => ['bizarre'], 'authority_super_input_authority_THES' => ['5203'], 'mode_authority_super_input_authority_THES_0' => '0', - ]; + ]; protected function _prepareFixtures() { parent::_prepareFixtures(); @@ -900,6 +859,7 @@ class AdvancedSearchFormWithPostCacheBackToSearchTest protected function _dispatch() { Zend_Registry::get('session')->searches = ['1234' => $this->_post]; + $this->dispatch('/recherche/avancee/post/1234'); } @@ -1071,7 +1031,6 @@ class AdvancedSearchFormWithDeprecatedDomainsCriteriaTest } - /** @test */ public function THE1suggestSelectedOptionShouldBeValueTwoLibelleCommencePar() { $this->assertXPathContentContains('//select[@id="mode_THE1"]/option[@value=2][@selected]', @@ -1142,16 +1101,15 @@ class AdvancedSearchFormMultiInputTest extends AdvancedSearchCustomFormSelectedT 'name' => 'authority_THES', 'label' => 'Mot-clés', 'tree_roots' => '444322-228822'], - ]; $form - ->addElement('searchAxeMultiInput', - 'mon_super_input', - ['label' => 'hohooh', - 'axes' => $axes]) + ->addElement('searchAxeMultiInput', + 'mon_super_input', + ['label' => 'hohooh', + 'axes' => $axes]) - ->addUniqDisplayGroup('multi'); + ->addUniqDisplayGroup('multi'); }; Class_SearchForm::setIncluder($includer); } @@ -1213,13 +1171,13 @@ class AdvancedSearchFormMultiInputAxeDefaultToFirstTest ]; $form - ->addElement('searchAxeMultiInput', - 'mon_super_input', - ['label' => 'hohooh', - 'axes' => $axes, - 'axeDefaultToFirst' => true]) + ->addElement('searchAxeMultiInput', + 'mon_super_input', + ['label' => 'hohooh', + 'axes' => $axes, + 'axeDefaultToFirst' => true]) - ->addUniqDisplayGroup('multi'); + ->addUniqDisplayGroup('multi'); }; Class_SearchForm::setIncluder($includer); } @@ -1261,16 +1219,16 @@ class AdvancedSearchFormMultiInputDefaultLinesTest ]; $form - ->addElement('searchAxeMultiInput', - 'mon_super_input', - ['label' => 'hohooh', - 'axes' => $axes, - 'defaultLines' => ['operator' => ['and', 'and'], - 'axe' => ['type_doc', 'library'], - 'type_doc' => ['2'], - 'library' => ['18']]]) - - ->addUniqDisplayGroup('multi'); + ->addElement('searchAxeMultiInput', + 'mon_super_input', + ['label' => 'hohooh', + 'axes' => $axes, + 'defaultLines' => ['operator' => ['and', 'and'], + 'axe' => ['type_doc', 'library'], + 'type_doc' => ['2'], + 'library' => ['18']]]) + + ->addUniqDisplayGroup('multi'); }; Class_SearchForm::setIncluder($includer); } @@ -1290,11 +1248,12 @@ class AdvancedSearchFormMultiInputDefaultLinesTest class AdvancedSearchFormUnauthorizedMultiInputTest extends AbstractControllerTestCase { - protected - $_form_filename = 'userfiles/forms/form.php'; + + protected $_form_filename = 'userfiles/forms/form.php'; public function setUp() { parent::setUp(); + Class_AdminVar::set('CUSTOM_SEARCH_FORM', 1); Class_Profil::getCurrentProfil() @@ -1339,12 +1298,12 @@ class AdvancedSearchFormUnauthorizedMultiInputTest extends AbstractControllerTes public function pageShouldContainsErrorForAxe($axe, $error) { $includer = function($path, $form) use($axe) { $form - ->addElement('searchAxeMultiInput', - 'mon_super_input', - ['label' => 'hohooh', - 'axes' => [$axe]]) + ->addElement('searchAxeMultiInput', + 'mon_super_input', + ['label' => 'hohooh', + 'axes' => [$axe]]) - ->addUniqDisplayGroup('multi'); + ->addUniqDisplayGroup('multi'); }; Class_SearchForm::setIncluder($includer); @@ -1361,24 +1320,43 @@ class AdvancedSearchFormUnauthorizedMultiInputTest extends AbstractControllerTes class AdvancedSearchFormWithDomainCriteriaDispatchTest extends AbstractControllerTestCase { + public function setUp() { parent::setUp(); - $this->fixture(Class_CodifLangue::class, ['id' => 'fre', 'libelle' => 'Français']); - $this->fixture(Class_CodifLangue::class, ['id' => 'eng', 'libelle' => 'English']); - $this->fixture(Class_Bib::class, ['id' => 11, 'libelle' => 'Annecy']); - $this->fixture(Class_CodifAuteur::class, ['id' => 2898, 'libelle' => 'Herbert']); + $this->fixture(Class_CodifLangue::class, + ['id' => 'fre', + 'libelle' => 'Français']); + $this->fixture(Class_CodifLangue::class, + ['id' => 'eng', + 'libelle' => 'English']); + $this->fixture(Class_Bib::class, + ['id' => 11, + 'libelle' => 'Annecy']); + $this->fixture(Class_CodifAuteur::class, + ['id' => 2898, + 'libelle' => 'Herbert']); $this->fixture(Class_CodifMatiere::class, - ['id' => 1, 'libelle' => '10 chotomies, c\'est beaucoup']); - - $this->fixture(Class_CodifDewey::class, ['id' => '0011', 'libelle' => 'Vie intellectuelle']); - $this->fixture(Class_CodifPcdm4::class, ['id' => '03', 'libelle' => 'Dictionnaires de musique']); - $this->fixture(Class_CodifCentreInteret::class, ['id' => 1, 'libelle' => 'eau']); - $this->fixture(Class_CodifTags::class, ['id' => 1, 'libelle' => 'Nous avons aimé']); + ['id' => 1, + 'libelle' => '10 chotomies, c\'est beaucoup']); + + $this->fixture(Class_CodifDewey::class, + ['id' => '0011', + 'libelle' => 'Vie intellectuelle']); + $this->fixture(Class_CodifPcdm4::class, + ['id' => '03', + 'libelle' => 'Dictionnaires de musique']); + $this->fixture(Class_CodifCentreInteret::class, + ['id' => 1, + 'libelle' => 'eau']); + $this->fixture(Class_CodifTags::class, + ['id' => 1, + 'libelle' => 'Nous avons aimé']); - $this->fixture(Class_CodifEmplacement::class, ['id' => 1, - 'libelle' => 'Espace musique', - 'regles' => '995$x=1']); + $this->fixture(Class_CodifEmplacement::class, + ['id' => 1, + 'libelle' => 'Espace musique', + 'regles' => '995$x=1']); $this->fixture(Class_CodifThesaurus::class, ['id' => 2, 'libelle' => 'Thiou', @@ -1434,7 +1412,6 @@ class AdvancedSearchFormWithDomainCriteriaDispatchTest extends AbstractControlle } - public function wrongMultifacets() { return [ ['PSUJE', 'SUJE0023;SUJE0144'], @@ -1496,6 +1473,7 @@ class AdvancedSearchFormWithDomainCriteriaDispatchTest extends AbstractControlle class AdvancedSearchAuthoritySuggestTest extends AbstractControllerTestCase { + /** @test */ public function onEmptyValueShouldReturnNothing() { $this->dispatch('/authority-suggest/suggest'); @@ -1557,6 +1535,7 @@ class AdvancedSearchAuthoritySuggestTest extends AbstractControllerTestCase { class ZendAfi_View_Helper_RenderFormOrderInElementsDisplayTest extends ViewHelperTestCase { + /** @var ZendAfi_View_Helper_RenderForm */ protected $_helper; @@ -1565,6 +1544,7 @@ class ZendAfi_View_Helper_RenderFormOrderInElementsDisplayTest extends ViewHelpe public function setUp() { parent::setUp(); + Class_ScriptLoader::resetInstance(); $view = new ZendAfi_Controller_Action_Helper_View(); @@ -1572,59 +1552,57 @@ class ZendAfi_View_Helper_RenderFormOrderInElementsDisplayTest extends ViewHelpe $this->_helper->setView($view); $this->_form = $view->newForm(array('id' => 'form_personne')) - ->addElement('text', 'expressionRecherche', ['label' => "Chercher partout"]) - ->addElement('searchAxe', - 'titres', - ['label' => "Titre"]) - ->addElement('searchAxe', - 'auteurs', - ['label' => "Auteur"]) - ->addElement('searchAxe', - 'matieres', - ['label' => "Mot-clé"]) - ->addElement('select', - 'tri', - ['label' => 'Trier par', - 'onkeypress' => 'if (event.keyCode == 13) {$(this.form).submit();return false; }', - 'multiOptions' => (new Class_CriteresRecherche())->getListeTris()]) - - ->addElement('range', - 'annee', - ['label' => 'Publié entre (Année sous forme 1980)', - 'onkeypress' => 'if (event.keyCode == 13) {$(this.form).submit();return false; }', - 'separator' => '<br/> et ', - 'from_suffix' => '_debut', - 'to_suffix' => '_fin']) - - ->addElement('multiCheckbox', 'custom_multifacets_typedoc', - ['label' => ('Type de document'), - 'onkeypress' => 'if (event.keyCode == 13) {$(this.form).submit();return false; }', - 'multiOptions' => ['' => 'Tous', - 'T1' => 'Ouvrage' , - 'T11' => 'Articles', - 'T2' => 'Périodique' , - 'T17' => 'Périodique électronique', - 'T5' => 'Cédéroms', - 'T4' => 'Vidéo', - 'T15' => 'Livre électronique' + ->addElement('text', 'expressionRecherche', ['label' => "Chercher partout"]) + ->addElement('searchAxe', + 'titres', + ['label' => "Titre"]) + ->addElement('searchAxe', + 'auteurs', + ['label' => "Auteur"]) + ->addElement('searchAxe', + 'matieres', + ['label' => "Mot-clé"]) + ->addElement('select', + 'tri', + ['label' => 'Trier par', + 'onkeypress' => 'if (event.keyCode == 13) {$(this.form).submit();return false; }', + 'multiOptions' => (new Class_CriteresRecherche())->getListeTris()]) + + ->addElement('range', + 'annee', + ['label' => 'Publié entre (Année sous forme 1980)', + 'onkeypress' => 'if (event.keyCode == 13) {$(this.form).submit();return false; }', + 'separator' => '<br/> et ', + 'from_suffix' => '_debut', + 'to_suffix' => '_fin']) + + ->addElement('multiCheckbox', 'custom_multifacets_typedoc', + ['label' => ('Type de document'), + 'onkeypress' => 'if (event.keyCode == 13) {$(this.form).submit();return false; }', + 'multiOptions' => ['' => 'Tous', + 'T1' => 'Ouvrage' , + 'T11' => 'Articles', + 'T2' => 'Périodique' , + 'T17' => 'Périodique électronique', + 'T5' => 'Cédéroms', + 'T4' => 'Vidéo', + 'T15' => 'Livre électronique' ],'autocomplete'=>'off']) - - ->addElement('multiCheckbox', 'genre', - ['label' => '', - 'multiOptions' => ['G7' => 'Limiter aux ressources accessibles en ligne' + ->addElement('multiCheckbox', 'genre', + ['label' => '', + 'multiOptions' => ['G7' => 'Limiter aux ressources accessibles en ligne' ], - 'autocomplete'=>'off' - ]) + 'autocomplete'=>'off' + ]) - ->addUniqDisplayGroup( - 'recherche_avancee'); + ->addUniqDisplayGroup( + 'recherche_avancee'); $this->_html = $this->_helper->renderForm($this->_form); } - /** @test */ public function firstTrShouldContainsChercherPartout() { $this->assertXPathContentContains($this->_html, diff --git a/tests/scenarios/Catalog/CustomCatalogTest.php b/tests/scenarios/Catalog/CustomCatalogTest.php index 8399183dc39525a6dec1ab134a49a90e6eaf612a..c10b1cf0ad9096139cc83cc23121bedc9b0348a3 100644 --- a/tests/scenarios/Catalog/CustomCatalogTest.php +++ b/tests/scenarios/Catalog/CustomCatalogTest.php @@ -782,8 +782,6 @@ class CustomCatalogModelTest extends ModelTestCase { $reqs['req_ids']()->fetchAll(); $this->assertSqlEquals(["UPDATE `notices` SET `facettes` = CLEAN_SPACES(REGEXP_REPLACE(`facettes`, '\\\\bHCCCC0001\\\\b', '')), `facets` = CLEAN_SPACES(REGEXP_REPLACE(`facets`, '\\\\bF_HCCCC0001\\\\b', '')) WHERE (`notices`.`type_doc` NOT IN (8, 9, 10) AND `notices`.`type` = 1 AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_HCCCC0001' IN BOOLEAN MODE))", - "SELECT `codif_type_doc`.* FROM `codif_type_doc` WHERE (`codif_type_doc`.`type_doc_id` LIKE 'Cvs2%')", - "SELECT `notices`.* FROM `notices` WHERE ((`notices`.`annee` >= '2016' AND `notices`.`annee` <= '2018' AND `notices`.`date_creation` >= '2021-01-06' AND `notices`.`cote` >= 'J 28' AND `notices`.`cote` <= 'J 29' AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+(F_T6 F_T7 F_HDOC00001)' IN BOOLEAN MODE)) AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC LIMIT 5000", "SELECT COUNT(*) AS `numberof` FROM `notices` WHERE ((`notices`.`annee` >= '2016' AND `notices`.`annee` <= '2018' AND `notices`.`date_creation` >= '2021-01-06' AND `notices`.`cote` >= 'J 28' AND `notices`.`cote` <= 'J 29' AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+(F_T6 F_T7 F_HDOC00001)' IN BOOLEAN MODE)) AND `notices`.`type` = 1)", diff --git a/tests/scenarios/SearchResult/SearchResultFacetsTest.php b/tests/scenarios/SearchResult/SearchResultFacetsTest.php new file mode 100644 index 0000000000000000000000000000000000000000..2e4c98f6dff6f632666b9fcc0105bdabc0db4264 --- /dev/null +++ b/tests/scenarios/SearchResult/SearchResultFacetsTest.php @@ -0,0 +1,261 @@ +<?php +/** + * Copyright (c) 2012-2023, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH 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). + * + * BOKEH 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 BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +require_once 'tests/scenarios/Templates/TemplatesTest.php'; + +abstract class SearchResultFacetsHeaderTestCase extends TemplatesIntonationTestCase { + + public function setUp() { + parent::setUp(); + + Class_Codification::reset(); + + (new Class_Profil_Preferences)->setModulePref(Class_Profil::find(72), + (new Class_Profil_ModuleDefinition('recherche', + 'resultat', + 'simple')), + ['facettes_codes' => 'Y;S;G;B;M;']); + + $this->fixture(Class_Notice::class, + ['id' => 1, + 'titres' => 'POMME', + 'facettes' => 'T1 Y1 Y2 Y3 S1 S2 S3 G1 G2 G3', + 'type' => 1, + 'unimarc' => file_get_contents(ROOT_PATH . 'tests/fixtures/unimarc_vernon.txt')]); + + $this->fixture(Class_CodifTypeDoc::class, + ['id' => 1, + 'libelle' => 'Livre', + 'famille_id' => 1]); + + $this->fixture(Class_CodifAnnexe::class, + ['id' => 1, + 'id_origine' => 1, + 'libelle' => 'Annecy']); + + $this->fixture(Class_CodifAnnexe::class, + ['id' => 2, + 'id_origine' => 2, + 'libelle' => 'Seynod']); + + $this->fixture(Class_CodifAnnexe::class, + ['id' => 3, + 'id_origine' => 3, + 'libelle' => 'Meythet']); + + $this->fixture(Class_CodifSection::class, + ['id' => 1, + 'libelle' => 'Adultes']); + + $this->fixture(Class_CodifSection::class, + ['id' => 2, + 'libelle' => 'Jeunesses']); + + $this->fixture(Class_CodifSection::class, + ['id' => 3, + 'libelle' => 'Adolescents']); + + $this->fixture(Class_CodifGenre::class, + ['id' => 1, + 'libelle' => 'Romans']); + + $this->fixture(Class_CodifGenre::class, + ['id' => 2, + 'libelle' => 'Mangas']); + + $this->fixture(Class_CodifGenre::class, + ['id' => 3, + 'libelle' => 'Policiers']); + } +} + + + + +class SearchResultFacetsHeaderIndexTest extends SearchResultFacetsHeaderTestCase { + + public function setUp() { + parent::setUp(); + + $this->dispatch('/opac/recherche/simple/expressionRecherche/pomme/id_profil/72/multifacets/Y1-Y2-G1-G2-G3/facettes/S1/facette/S2/section/3/annexe/3'); + } + + + /** @test */ + public function removeCriteriaEtSiteAnnecyOuSeynodOuMeythetShouldExists() { + $this->assertXPath('//a[contains(@class, "card-link active_criteria")][@title="Retirer le critère: Site: Annecy OU Seynod OU Meythet"][contains(@href, "/recherche/simple/expressionRecherche/pomme/multifacets/G1-G2-G3-S3/facettes/S1-S2")]'); + } + + + /** @test */ + public function removeCriteriaEtSectionAdultesShouldExists() { + $this->assertXPath('//a[contains(@class, "card-link active_criteria")][@title="Retirer le critère: Section: Adultes"][contains(@href, "/recherche/simple/expressionRecherche/pomme/multifacets/Y1-Y2-G1-G2-G3-S3-Y3/facettes/S2")]'); + } + + + /** @test */ + public function removeCriteriaEtSectionJeunessesShouldExists() { + $this->assertXPath('//a[contains(@class, "card-link active_criteria")][@title="Retirer le critère: Section: Jeunesses"][contains(@href, "/recherche/simple/expressionRecherche/pomme/multifacets/Y1-Y2-G1-G2-G3-S3-Y3/facettes/S1")]'); + } + + + /** @test */ + public function removeCriteriaEtSectionAdolescentsShouldExists() { + $this->assertXPath('//a[contains(@class, "card-link active_criteria")][@title="Retirer le critère: Section: Adolescents"][contains(@href, "/recherche/simple/expressionRecherche/pomme/multifacets/Y1-Y2-G1-G2-G3-Y3/facettes/S1-S2")]'); + } + + + /** @test */ + public function removeCriteriaMultiGenreRomansMangasPoliciersShouldExists() { + $this->assertXPath('//a[contains(@class, "card-link active_criteria")][@title="Retirer le critère: Genre: Romans OU Mangas OU Policiers"][contains(@href, "/recherche/simple/expressionRecherche/pomme/multifacets/Y1-Y2-S3-Y3/facettes/S1-S2")]'); + } + + + /** @test */ + public function linkResetShouldExistsWithoutCriteriaMultiFacets() { + $this->assertXPath('//a[contains(@class, "reset_criteria")][@href="/recherche/simple/expressionRecherche/pomme"]'); + } +} + + + + +class SearchResultFacetsHeaderPostTest extends SearchResultFacetsHeaderTestCase { + + /** @test */ + public function withoutMultifacetGenre_1_shouldRedirectToRecherchePommeWithMultifacets_G2() { + $this->postDispatch('/recherche/simple/expressionRecherche/pomme/genre/1%3B2', + ['multifacet_G1' => 0]); + + $this->assertRedirectTo('/recherche/simple/expressionRecherche/pomme/multifacets/G2'); + } + + + /** @test */ + public function withoutMultifacetSection_1_shouldRedirectToRecherchePommeWithMultifacets_S2() { + $this->postDispatch('/recherche/simple/expressionRecherche/pomme/section/1%3B2', + ['multifacet_S1' => 0]); + + $this->assertRedirectTo('/recherche/simple/expressionRecherche/pomme/multifacets/S2'); + } + + + /** @test */ + public function withoutMultifacetAnnexe_1_shouldRedirectToRecherchePommeWithMultifacets_Y2() { + $this->postDispatch('/recherche/simple/expressionRecherche/pomme/annexe/1%3B2', + ['multifacet_Y1' => 0]); + + $this->assertRedirectTo('/recherche/simple/expressionRecherche/pomme/multifacets/Y2'); + } + + + /** @test */ + public function withoutMultifacetTypeDoc_1_shouldRedirectToRecherchePommeWithMultifacets_T2() { + $this->postDispatch('/recherche/simple/expressionRecherche/pomme/type_doc/1%3B2', + ['multifacet_T1' => 0]); + + $this->assertRedirectTo('/recherche/simple/expressionRecherche/pomme/multifacets/T2'); + } +} + + + + +/* @see : hotline : https://forge.afi-sa.net/issues/173345 */ +class SearchResultFacetsSqlTest extends AbstractControllerTestCase { + + protected bool $_storm_mock_zend_adapter = true; + protected array $_storm_scopes = [Class_MoteurRecherche::class]; + + public function setUp() { + parent::setUp(); + + $this->fixture(Class_CodifSection::class, + ['id' => 1, + 'invisible' => 0, + 'libelle' => 'Adultes']); + $this->fixture(Class_CodifSection::class, + ['id' => 2, + 'invisible' => 0, + 'libelle' => 'Jeunesses']); + $this->fixture(Class_CodifSection::class, + ['id' => 3, + 'invisible' => 0, + 'libelle' => 'Adolescents']); + + Zend_Registry::get('session')->searches = ['1234' => ['mode_authority_thesaurus' => '0']]; + + $this->dispatch('/recherche/simple/form_id/advanced_form/type_recherche/fulltext/tri/*/annexe/9;8/section/2;3/post/1234/facettes/T2-T3/facette/T4/multifacets/Y10-S1-T1-G5-G6/titre/Recherche+avancée'); + } + + + /** @test */ + public function sqlQueryShouldExists() { + $this->assertSql("SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_T2 +F_T3 +F_T4 +(F_Y10 F_Y9 F_Y8) +(F_S1 F_S2 F_S3) +F_T1 +(F_G5 F_G6)' IN BOOLEAN MODE) AND `notices`.`type` = 1)"); + } +} + + + + +class SearchResultFacetsPostDispatchAdvancedTest extends AbstractControllerTestCase { + + public function setUp() { + parent::setUp(); + + $this->fixture(Class_CodifThesaurus::class, + ['id' => 3, + 'libelle' => 'Document', + 'libelle_facette' => 'Document', + 'id_thesaurus' => 'DOCU', + 'id_origine' => null, + 'code' => 'UNIMARC', + 'rule_list_zone' => ['995'], + 'rule_list_label_field' => ['t']]); + + $this->fixture(Class_CodifThesaurus::class, + ['id' => 4, + 'libelle' => 'SIFI', + 'libelle_facette' => 'Science fiction', + 'id_thesaurus' => 'DOCU0001', + 'id_origine' => null, + 'code' => 'UNIMARC', + 'rule_list_zone' => ['999'], + 'rule_list_label_field' => ['t']]); + } + + + /** @test */ + public function shouldRedirectToRechercheSimpleOrFacetsA12MinusA42MinusM608() { + $this->postDispatch('/recherche/simple', ['custom_multifacets_author' => ['A12', 'A42'], + 'custom_multifacets_subject' => 'M608']); + $this->assertRedirectTo('/recherche/simple/multifacets/A12-A42-M608'); + } + + + /** @test */ + public function mixOrFacetsAndDynamicFacetsShouldMergeFacets() { + $this->postDispatch('/recherche/simple', ['custom_multifacets_author' => ['A12', 'A42'], + 'custom_multifacets_subject' => 'M608', + 'rech_HDOCU' => 'SIFI']); + $this->assertRedirectTo('/recherche/simple/multifacets/HDOCU0001-A12-A42-M608'); + } +} diff --git a/tests/scenarios/Templates/ChiliTest.php b/tests/scenarios/Templates/ChiliTest.php index c93ceeccc2b4419167a5d09195cb688c4fc0ac4f..8975e22bca7fe9acb92c848298c68c4a740ebdfb 100644 --- a/tests/scenarios/Templates/ChiliTest.php +++ b/tests/scenarios/Templates/ChiliTest.php @@ -1199,10 +1199,9 @@ class ChiliSearchResultWithMultiFacetsPostTest (new Class_Profil_ModuleDefinition('recherche', 'resultat', 'simple')), - [ 'facettes_codes' => 'T;B', - 'multi_facettes' => 1, - 'facets_closed_codes' => 'T;B']); - + ['facettes_codes' => 'T;B', + 'multi_facettes' => 1, + 'facets_closed_codes' => 'T;B']); } @@ -1221,6 +1220,15 @@ class ChiliSearchResultWithMultiFacetsPostTest 'multifacet_T1' => 1]); $this->assertRedirectTo('/recherche/simple/expressionRecherche/pomme/multifacets/T1'); } + + + /** @test */ + public function shouldRedirectToRecherchePommeWithMultiFacetsB2() { + $this->postDispatch('/recherche/simple/expressionRecherche/pomme/multifacets/B1-B2', + ['multifacet_B1' => 0]); + + $this->assertRedirectTo('/recherche/simple/expressionRecherche/pomme/multifacets/B2'); + } } diff --git a/tests/scenarios/Templates/TemplatesSearchTest.php b/tests/scenarios/Templates/TemplatesSearchTest.php index 83952ed7077f2b936958a75e9db0dfc2b33ab053..336d2a22a7129bb373ac5545818788c68e3aecb7 100644 --- a/tests/scenarios/Templates/TemplatesSearchTest.php +++ b/tests/scenarios/Templates/TemplatesSearchTest.php @@ -46,6 +46,7 @@ class TemplatesSearchWithSortParameterInWidgetFromIndexPageTest public function setUp() { parent::setUp(); + $this->dispatch('/'); } @@ -89,6 +90,7 @@ class TemplatesSearchWithSortParameterInWidgetFromSearchPageWithTriParamTest public function setUp() { parent::setUp(); + $this->dispatch('/recherche/simple/expressionRecherche/poire/tri/alpha_auteur+desc/form_id/2'); } @@ -301,10 +303,11 @@ class TemplatesDispatchIntonationSearchTest extends TemplatesIntonationTestCase -class TemplatesPostDispatchSearchWithCustomMultifactesTest extends AbstractControllerTestCase { +class TemplatesSearchPostDispatchWithCustomMultifactesTest extends AbstractControllerTestCase { public function setUp() { parent::setUp(); + $this->postDispatch('/opac/recherche/simple/', ['custom_multifacets_annexe' => 'A1', 'custom_multifacets_domains' => 'D1', 'custom_multifacets_HSUPP' => 'HSUPP0001', @@ -512,6 +515,7 @@ class TemplatesSearchRecordsTest extends TemplatesIntonationTestCase { public function setUp() { parent::setUp(); + $this->fixture(Class_Notice::class, ['id' => 456, 'titre_principal' => 'Psycho', @@ -531,10 +535,6 @@ class TemplatesSearchRecordsTest extends TemplatesIntonationTestCase { - - - - abstract class TemplatesSearchDispatchIntonationSearchListFormatWallTestCase extends TemplatesIntonationTestCase { @@ -792,6 +792,7 @@ class TemplatesSearchDispatchNoticeAjaxResourcesTest public function setUp() { parent::setUp(); + $this->dispatch('/noticeajax/resources/id/34'); } @@ -916,7 +917,7 @@ class TemplatesSearchReservationPickupAjaxConnectedUserTest /** @test */ public function CranShouldBeSelectable() { - $this->_xpath->assertXPath($this->_html, '//input[@type="radio"][@value=37]',$this->_html); + $this->_xpath->assertXPath($this->_html, '//input[@type="radio"][@value=37]', $this->_html); } @@ -1056,6 +1057,7 @@ class TemplatesSearchDispatchWithDefaultRenderingTest extends TemplatesSearchDis public function setUp() { parent::setUp(); + $this->dispatch('/opac/recherche/simple/expressionRecherche/accroc/id_profil/5'); } @@ -1073,6 +1075,7 @@ class TemplatesSearchDispatchWithWallDefaultRenderingTest extends TemplatesSearc public function setUp() { parent::setUp(); + (new Class_Profil_Preferences()) ->setModulePref(Class_Profil::getCurrentProfil(), (new Class_Profil_ModuleDefinition('recherche', @@ -1222,6 +1225,7 @@ class TemplatesSearchDispatchWithUserSettingsEnabledTest public function setUp() { parent::setUp(); + $this->dispatch('recherche/simple/expressionRecherche/france'); } @@ -1317,6 +1321,7 @@ class TemplatesSearchDispatchWallModeRenderingInChiliTest extends TemplatesSearc public function setUp() { parent::setUp(); + $this->dispatch('/opac/recherche/simple/expressionRecherche/accroc/id_profil/5/liste_format/4'); } @@ -1420,7 +1425,9 @@ class TemplatesSearchEditActionTest extends Admin_AbstractControllerTestCase { public function setUp() { parent::setUp(); + $this->_buildTemplateProfil(['id' => 45]); + $this->dispatch('admin/widget/edit-action/id/recherche_resultat_simple/id_profil/45'); } @@ -1594,6 +1601,7 @@ class TemplatesSearchWithDomainIdsSettingsFromIndexPageTest public function setUp() { parent::setUp(); + $this->_buildTemplateProfil(['id' => 1, 'libelle' => 'My search page']) ->setBoiteOfTypeInDivision(1, @@ -1623,8 +1631,10 @@ class TemplatesSearchWithDomainIdsSettingsFromIndexPageTest class TemplatesDispatchIntonationSearchWithXslTest extends TemplatesIntonationTestCase { + public function setUp() { parent::setUp(); + Class_FileManager::setFileSystem(new Class_FileManager_FileSystem); $this->fixture(Class_Notice::class, @@ -1648,6 +1658,7 @@ class TemplatesDispatchIntonationSearchWithXslTest extends TemplatesIntonationTe ->answers([[1, ''],[2,'']]); Zend_Registry::set('sql', $mock_sql); + $this->dispatch('/opac/recherche/simple/expressionRecherche/europe/id_profil/72'); } @@ -1762,8 +1773,10 @@ class TemplatesSearchBackToFormTest extends AbstractControllerTestCase { /* see https://forge.afi-sa.net/issues/185768 */ class TemplatesSearchReserverActionTest extends TemplatesIntonationTestCase { + public function setUp() { parent::setUp(); + ZendAfi_Auth::getInstance()->clearIdentity(); $this->fixture(Class_Notice::class,