Commit 4101a2fd authored by Ghislain Loas's avatar Ghislain Loas

Merge branch 'dev#75068_minsoc_xslt_etape_4_gestion_des_rebonds' into 'master'

Dev#75068 minsoc xslt etape 4 gestion des rebonds

See merge request afi/opacce!2680
parents ed10f348 e1dbaafe
- ticket #75068 : Facettes dynamiques : filtrer le résultat de recherche à partir du libellé d'une facette dynamique
\ No newline at end of file
......@@ -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;
......
......@@ -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);
......
......@@ -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());
}
......
......@@ -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">
......
......@@ -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
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