Commit cc39bab7 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #75068 redirect action when dynamic filters and display code on cosmogramme dynamic filter page

parent c02e7e37
...@@ -87,6 +87,15 @@ class RechercheController extends ZendAfi_Controller_Action { ...@@ -87,6 +87,15 @@ class RechercheController extends ZendAfi_Controller_Action {
unset($params['q']); 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()) { if ($multifacets = $this->_extractMultifacetsPost()) {
$url = $this->newCriteresRecherches($params) $url = $this->newCriteresRecherches($params)
->getUrlWithMultifacetsUpdate($multifacets); ->getUrlWithMultifacetsUpdate($multifacets);
...@@ -156,6 +165,25 @@ class RechercheController extends ZendAfi_Controller_Action { ...@@ -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() { protected function _extractMultifacetsPost() {
if (!$this->_request->isPost()) if (!$this->_request->isPost())
return; return;
......
...@@ -415,19 +415,7 @@ class CodifThesaurusLoader extends Storm_Model_Loader { ...@@ -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() { public function getDynamicCodes() {
xdebug_break();
$dynamic_facets = Class_CodifThesaurus::findAllBy(['rules not' => null, $dynamic_facets = Class_CodifThesaurus::findAllBy(['rules not' => null,
'code not' => null, 'code not' => null,
'id_thesaurus not' => null]); 'id_thesaurus not' => null]);
......
...@@ -128,8 +128,7 @@ class Class_CriteresRecherche { ...@@ -128,8 +128,7 @@ class Class_CriteresRecherche {
'fil', 'fil',
'bib_select', 'bib_select',
'serie', 'serie',
'from'], 'from']);
Class_CodifThesaurus::getSearchParams());
} }
...@@ -226,8 +225,6 @@ class Class_CriteresRecherche { ...@@ -226,8 +225,6 @@ class Class_CriteresRecherche {
$facettes = explode('-', $this->getParam('facettes', '')); $facettes = explode('-', $this->getParam('facettes', ''));
$facettes[] = $this->getParam('facette', ''); $facettes[] = $this->getParam('facette', '');
$facettes = $this->_getFacetsForDynamicParams($facettes);
return array_unique(array_filter($facettes, return array_unique(array_filter($facettes,
[$this->getValidateFacette(), [$this->getValidateFacette(),
'isValid'] 'isValid']
...@@ -235,19 +232,6 @@ class Class_CriteresRecherche { ...@@ -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() { public function getMultiFacets() {
return array_filter(array_merge(explode('-', $this->getParam('multifacets','')), return array_filter(array_merge(explode('-', $this->getParam('multifacets','')),
...@@ -590,7 +574,7 @@ class Class_CriteresRecherche { ...@@ -590,7 +574,7 @@ class Class_CriteresRecherche {
$visitor->visitSearchUrl($this->getUrlCriteresWithFacettes()); $visitor->visitSearchUrl($this->getUrlCriteresWithFacettes());
$this->visitByRechercheType($visitor); $this->visitByRechercheType($visitor);
xdebug_break();
$facettes = $this->getFacettes(); $facettes = $this->getFacettes();
foreach($facettes as $facette) foreach($facettes as $facette)
$visitor->visitFacette($facette); $visitor->visitFacette($facette);
......
...@@ -48,13 +48,15 @@ class ZendAfi_View_Helper_CosmoFacets extends ZendAfi_View_Helper_CosmoEmplaceme ...@@ -48,13 +48,15 @@ class ZendAfi_View_Helper_CosmoFacets extends ZendAfi_View_Helper_CosmoEmplaceme
return $this->view return $this->view
->tag( ->tag(
'table', 'table',
$this->_getTitle() $this->_getTitle()
. $this->_getLabel() . $this->_helpCode()
. $this->_getHelp() . $this->_getCode()
. $this->_getRules() . $this->_getLabel()
. $this->_getDisplay() . $this->_getHelp()
. $this->_getActions(), . $this->_getRules()
['class' => 'form', 'cellspacing' => 0, 'cellpadding' => 5]); . $this->_getDisplay()
. $this->_getActions(),
['class' => 'form', 'cellspacing' => 0, 'cellpadding' => 5]);
} }
...@@ -74,6 +76,26 @@ class ZendAfi_View_Helper_CosmoFacets extends ZendAfi_View_Helper_CosmoEmplaceme ...@@ -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() { protected function _getHelp() {
return '<tr> return '<tr>
<td class="form_first" align="center" colspan="2"> <td class="form_first" align="center" colspan="2">
......
...@@ -244,6 +244,7 @@ class SearchResultWithDynamicFacetTest extends AbstractControllerTestCase { ...@@ -244,6 +244,7 @@ class SearchResultWithDynamicFacetTest extends AbstractControllerTestCase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->fixture('Class_CodifThesaurus', $this->fixture('Class_CodifThesaurus',
['id' => 3, ['id' => 3,
'libelle' => 'Document', 'libelle' => 'Document',
...@@ -262,22 +263,15 @@ class SearchResultWithDynamicFacetTest extends AbstractControllerTestCase { ...@@ -262,22 +263,15 @@ class SearchResultWithDynamicFacetTest extends AbstractControllerTestCase {
'code' => 'DOCU', 'code' => 'DOCU',
'rules' => '{"label":" 99$t "}']); '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 */ /** @test */
public function shouldReturnSearchResult() { public function shouldRedirectToSearchWithFacetHDOCU() {
$this->assertXPath('//div'); $this->dispatch('/opac/recherche/simple/rech_HDOCU/SIFI', true);
$this->assertRedirectTo('/recherche/simple/multifacets/HDOCU0001');
} }
} }
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment