Commit cc39bab7 authored by Ghislain Loas's avatar Ghislain Loas

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 {
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;
......
......@@ -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]);
......
......@@ -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);
......
......@@ -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">
......
......@@ -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
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