diff --git a/application/modules/opac/controllers/RechercheController.php b/application/modules/opac/controllers/RechercheController.php index d4e5ab71851d0e75fdd4b7f3c1da310f88bf5f95..de66e8fed332a9f8b022b15ce7174ef4e9f95e94 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[Class_CodifThesaurus::CODE_FACETTE . $instance->getIdThesaurus()] = 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 ce065e0b4f9100d012c4fcd482283e0b9d618c6a..a84d4bce83e5e91f6660845a3fc31620a37be2da 100644 --- a/library/Class/CodifThesaurus.php +++ b/library/Class/CodifThesaurus.php @@ -415,19 +415,7 @@ class CodifThesaurusLoader extends Storm_Model_Loader { } - public function getSearchParams() { - $params = []; - - foreach(static::getDynamicCodes() as $thesaurus) { - $params [] = 'rech_' . Class_CodifThesaurus::CODE_FACETTE. $thesaurus; - } - - return $params; - } - - public function getDynamicCodes() { - xdebug_break(); $dynamic_facets = Class_CodifThesaurus::findAllBy(['rules not' => null, 'code not' => null, 'id_thesaurus not' => null]); diff --git a/library/Class/CriteresRecherche.php b/library/Class/CriteresRecherche.php index 99850aeb6c1b877b0cf0d07980bec803b5608dfc..f735b5ae7e25ad5fcf4a8ec138780db0a3214503 100644 --- a/library/Class/CriteresRecherche.php +++ b/library/Class/CriteresRecherche.php @@ -128,8 +128,7 @@ class Class_CriteresRecherche { 'fil', 'bib_select', 'serie', - 'from'], - Class_CodifThesaurus::getSearchParams()); + 'from']); } @@ -226,8 +225,6 @@ class Class_CriteresRecherche { $facettes = explode('-', $this->getParam('facettes', '')); $facettes[] = $this->getParam('facette', ''); - $facettes = $this->_getFacetsForDynamicParams($facettes); - return array_unique(array_filter($facettes, [$this->getValidateFacette(), 'isValid'] @@ -235,19 +232,6 @@ class Class_CriteresRecherche { } - protected function _getFacetsForDynamicParams($facets) { - - foreach(Class_CodifThesaurus::getDynamicCodes() as $code) { - if (!$value = $this->getParam('rech_'.Class_CodifThesaurus::CODE_FACETTE.$code)) - continue; - $instance = Class_CodifThesaurus::findFirstBy(['code' => $code, - 'libelle' => $value]); - $facets[] = $instance ? Class_CodifThesaurus::CODE_FACETTE.$instance->getIdThesaurus() : ''; - } - - return array_filter($facets); - } - public function getMultiFacets() { return array_filter(array_merge(explode('-', $this->getParam('multifacets','')), @@ -590,7 +574,7 @@ class Class_CriteresRecherche { $visitor->visitSearchUrl($this->getUrlCriteresWithFacettes()); $this->visitByRechercheType($visitor); - xdebug_break(); + $facettes = $this->getFacettes(); foreach($facettes as $facette) $visitor->visitFacette($facette); 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 fa5ee695214b4260c28d83d6d3d02baa49e8d621..9535425fb09c380294d3bfa958836928f7e67448 100644 --- a/tests/scenarios/SearchResult/SearchResultTest.php +++ b/tests/scenarios/SearchResult/SearchResultTest.php @@ -244,6 +244,7 @@ class SearchResultWithDynamicFacetTest extends AbstractControllerTestCase { public function setUp() { parent::setUp(); + $this->fixture('Class_CodifThesaurus', ['id' => 3, 'libelle' => 'Document', @@ -262,22 +263,15 @@ class SearchResultWithDynamicFacetTest extends AbstractControllerTestCase { 'code' => 'DOCU', 'rules' => '{"label":" 99$t "}']); - $sql = $this->mock() - ->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices Where MATCH(facettes) AGAINST('+HDOCU0001' IN BOOLEAN MODE)", true, false) - ->answers([ - [1, 'HDOCU0001'] - ]) - ->beStrict(); - - Zend_Registry::set('sql', $sql); - $this->dispatch('/opac/recherche/simple/rech_HDOCU/SIFI', true); } /** @test */ - public function shouldReturnSearchResult() { - $this->assertXPath('//div'); + public function shouldRedirectToSearchWithFacetHDOCU() { + $this->dispatch('/opac/recherche/simple/rech_HDOCU/SIFI', true); + $this->assertRedirectTo('/recherche/simple/multifacets/HDOCU0001'); } + + } \ No newline at end of file