diff --git a/VERSIONS_WIP/75068 b/VERSIONS_WIP/75068 new file mode 100644 index 0000000000000000000000000000000000000000..4c5bb469641c520a2e08670def9a5dfbfa780561 --- /dev/null +++ b/VERSIONS_WIP/75068 @@ -0,0 +1 @@ + - ticket #75068 : Facettes dynamiques : filtrer le résultat de recherche à partir du libellé d'une facette dynamique \ No newline at end of file diff --git a/application/modules/opac/controllers/RechercheController.php b/application/modules/opac/controllers/RechercheController.php index d4e5ab71851d0e75fdd4b7f3c1da310f88bf5f95..d13becdc225766cbaf14697fbfb7082e68f6efb0 100644 --- a/application/modules/opac/controllers/RechercheController.php +++ b/application/modules/opac/controllers/RechercheController.php @@ -87,6 +87,15 @@ class RechercheController extends ZendAfi_Controller_Action { unset($params['q']); } + if($dynamic_facets = $this->_extractDynamicFacets($params) ) { + $url = $this->newCriteresRecherches($params) + ->getUrlWithMultifacetsUpdate($dynamic_facets); + return $this->_redirect($this->view->url($url, + null, + true), + ['prependBase' => false]); + } + if ($multifacets = $this->_extractMultifacetsPost()) { $url = $this->newCriteresRecherches($params) ->getUrlWithMultifacetsUpdate($multifacets); @@ -156,6 +165,25 @@ class RechercheController extends ZendAfi_Controller_Action { } + protected function _extractDynamicFacets(&$params) { + $facets = []; + + foreach(Class_CodifThesaurus::getDynamicCodes() as $code) { + $param = 'rech_' . Class_CodifThesaurus::CODE_FACETTE . $code; + if (!$value = $this->_getParam($param)) + continue; + + unset($params[$param]); + $instance = Class_CodifThesaurus::findFirstBy(['code' => $code, + 'libelle' => $value]); + if($instance) + $facets[$instance->getFacetteIndex()] = 1; + } + + return array_filter($facets); + } + + protected function _extractMultifacetsPost() { if (!$this->_request->isPost()) return; diff --git a/library/Class/CodifThesaurus.php b/library/Class/CodifThesaurus.php index 3869cdba287ac2a97f2140cd8388894ebb40f710..2b77afde53a2af2298baf405343458f83f1de327 100644 --- a/library/Class/CodifThesaurus.php +++ b/library/Class/CodifThesaurus.php @@ -413,6 +413,18 @@ class CodifThesaurusLoader extends Storm_Model_Loader { protected function _like($field, $clause) { return $field . ' like \''. $clause . '\''; } + + + public function getDynamicCodes() { + $dynamic_facets = Class_CodifThesaurus::findAllBy(['rules not' => null, + 'code not' => null, + 'id_thesaurus not' => null]); + $params = []; + foreach($dynamic_facets as $facet) + $params [] = $facet->getCode(); + + return array_unique($params); + } } @@ -435,7 +447,8 @@ class Class_CodifThesaurus extends Storm_Model_Abstract { protected $_default_attribute_values = ['libelle_facette' => '', 'id_thesaurus' =>null, 'id_origine' => null, - 'rules' => null]; + 'rules' => null, + 'code' => null]; public function getListeSuggestion($recherche, $mode, $limite_resultat, $theme) { return $this->getLoader()->suggestFrom($recherche, $mode, $limite_resultat, $theme); diff --git a/library/Class/CriteresRecherche.php b/library/Class/CriteresRecherche.php index b39daf297f13df7ab2df0f286549ae5e43f22cea..f735b5ae7e25ad5fcf4a8ec138780db0a3214503 100644 --- a/library/Class/CriteresRecherche.php +++ b/library/Class/CriteresRecherche.php @@ -232,6 +232,7 @@ class Class_CriteresRecherche { } + public function getMultiFacets() { return array_filter(array_merge(explode('-', $this->getParam('multifacets','')), $this->selectionToArray(Class_CodifGenre::CODE_FACETTE, @@ -519,10 +520,16 @@ class Class_CriteresRecherche { $visitor->visitExpression($expression,$this->getPertinence(),$this->getTri()); $type_recherche = $this->getTypeRecherche(); - $text_inputs = ['titres', 'auteurs', 'matieres', 'dewey', 'collection']; + + $text_inputs = array_merge(['titres', + 'auteurs', + 'matieres', + 'dewey', + 'collection']); + foreach($text_inputs as $name) { - $operateur = $this->getParam('operateur_'.$name); - if ($value = $this->getParam('rech_'.$name)) + $operateur = $this->getParam('operateur_' . $name); + if ($value = $this->getParam('rech_' . $name)) $visitor->visitTextInput($name, $operateur, $type_recherche, $value,$this->getPertinence()); } diff --git a/library/ZendAfi/View/Helper/CosmoFacets.php b/library/ZendAfi/View/Helper/CosmoFacets.php index 8d1b10a33239f74ec175231d6a202e40c9497d8b..351d21879d8e37520d4d2d7d470beafc86f4ba3b 100644 --- a/library/ZendAfi/View/Helper/CosmoFacets.php +++ b/library/ZendAfi/View/Helper/CosmoFacets.php @@ -48,13 +48,15 @@ class ZendAfi_View_Helper_CosmoFacets extends ZendAfi_View_Helper_CosmoEmplaceme return $this->view ->tag( 'table', - $this->_getTitle() - . $this->_getLabel() - . $this->_getHelp() - . $this->_getRules() - . $this->_getDisplay() - . $this->_getActions(), - ['class' => 'form', 'cellspacing' => 0, 'cellpadding' => 5]); + $this->_getTitle() + . $this->_helpCode() + . $this->_getCode() + . $this->_getLabel() + . $this->_getHelp() + . $this->_getRules() + . $this->_getDisplay() + . $this->_getActions(), + ['class' => 'form', 'cellspacing' => 0, 'cellpadding' => 5]); } @@ -74,6 +76,26 @@ class ZendAfi_View_Helper_CosmoFacets extends ZendAfi_View_Helper_CosmoEmplaceme } + protected function _helpCode() { + return '<tr> + <td class="form_first" align="center" colspan="2"> + <div class="commentaire">Critère de recherche: rech_H'. + $this->model->getCode().'</div> + </td> + </tr>'; + } + + + protected function _getCode() { + return + $this->view->tag( + 'tr', + $this->view->tag('td', 'Code', [ + 'class' => 'form_first', 'align' => 'right', 'width' => '35%']) . + $this->view->tag('td', $this->view->formText('code', $this->model->getCode(), ['size' => 43, 'disabled' => 'disabled']), ['class' => 'form_first'])); + } + + protected function _getHelp() { return '<tr> <td class="form_first" align="center" colspan="2"> diff --git a/tests/scenarios/SearchResult/SearchResultTest.php b/tests/scenarios/SearchResult/SearchResultTest.php index a490198ab1f8ea058fb797b873313b610d915329..afeaef31af280b4fe37cd123e9d72e9e2e3078f6 100644 --- a/tests/scenarios/SearchResult/SearchResultTest.php +++ b/tests/scenarios/SearchResult/SearchResultTest.php @@ -88,6 +88,8 @@ class SearchResultHeaderTest extends AbstractControllerTestCase { } + + class SearhResultFilterDomainsFromProfilTest extends AbstractControllerTestCase { protected $_storm_default_to_volatile = true; @@ -137,7 +139,6 @@ class SearhResultFilterDomainsFromProfilTest extends AbstractControllerTestCase public function linkToDomainYouthsOrAdultsShouldBeDisplayInFacet() { $this->assertXPathContentContains('//div[@class="criteres_recherche"]', 'Domaine: Youths OU Adults', $this->_response->getBody()); } - } @@ -232,4 +233,43 @@ class SearchResultFilterFromProfilOnDomainTest extends AbstractControllerTestCas public function facetShouldNotDisplyFilteredDocTypeBook() { $this->assertNotXpath('//li[@class="facette"]//input[@name="multifacet_T1"]'); } +} + + + + +class SearchResultWithDynamicFacetTest extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + + public function setUp() { + parent::setUp(); + + $this->fixture('Class_CodifThesaurus', + ['id' => 3, + 'libelle' => 'Document', + 'libelle_facette' => 'Document', + 'id_thesaurus' => 'DOCU', + 'id_origine' => null, + 'code' => 'DOCU', + 'rules' => '{"label":" 99$t "}']); + + $this->fixture('Class_CodifThesaurus', + ['id' => 4, + 'libelle' => 'SIFI', + 'libelle_facette' => 'Science fiction', + 'id_thesaurus' => 'DOCU0001', + 'id_origine' => null, + 'code' => 'DOCU', + 'rules' => '{"label":" 99$t "}']); + + + } + + + /** @test */ + public function shouldRedirectToSearchWithFacetHDOCU() { + $this->dispatch('/opac/recherche/simple/rech_HDOCU/SIFI', true); + $this->assertRedirectTo('/recherche/simple/multifacets/HDOCU0001'); + } } \ No newline at end of file