From c02e7e3715be3bf1fd154d1feeaf4e98b0b37483 Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Tue, 29 May 2018 15:54:02 +0200 Subject: [PATCH] dev #75068 explo --- FEATURES/75068 | 10 ++++ VERSIONS_WIP/75068 | 1 + library/Class/CodifThesaurus.php | 24 +++++++++ library/Class/CriteresRecherche.php | 33 ++++++++++-- .../SearchResult/SearchResultTest.php | 50 ++++++++++++++++++- 5 files changed, 112 insertions(+), 6 deletions(-) create mode 100644 FEATURES/75068 create mode 100644 VERSIONS_WIP/75068 diff --git a/FEATURES/75068 b/FEATURES/75068 new file mode 100644 index 00000000000..5b11f3f64b7 --- /dev/null +++ b/FEATURES/75068 @@ -0,0 +1,10 @@ + '75068' => + ['Label' => $this->_('[MINSOC] XSLT - étape 4 : gestion des rebonds '), + 'Desc' => '', + 'Image' => '', + 'Video' => '', + 'Category' => '', + 'Right' => function($feature_description, $user) {return true;}, + 'Wiki' => '', + 'Test' => '', + 'Date' => '2018-05-29'], \ No newline at end of file diff --git a/VERSIONS_WIP/75068 b/VERSIONS_WIP/75068 new file mode 100644 index 00000000000..2d42d9855e9 --- /dev/null +++ b/VERSIONS_WIP/75068 @@ -0,0 +1 @@ + - ticket #75068 : [MINSOC] XSLT - étape 4 : gestion des rebonds \ No newline at end of file diff --git a/library/Class/CodifThesaurus.php b/library/Class/CodifThesaurus.php index 3869cdba287..ce065e0b4f9 100644 --- a/library/Class/CodifThesaurus.php +++ b/library/Class/CodifThesaurus.php @@ -413,6 +413,30 @@ class CodifThesaurusLoader extends Storm_Model_Loader { protected function _like($field, $clause) { return $field . ' like \''. $clause . '\''; } + + + 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]); + $params = []; + foreach($dynamic_facets as $facet) + $params [] = $facet->getCode(); + + return array_unique($params); + } } diff --git a/library/Class/CriteresRecherche.php b/library/Class/CriteresRecherche.php index b39daf297f1..99850aeb6c1 100644 --- a/library/Class/CriteresRecherche.php +++ b/library/Class/CriteresRecherche.php @@ -128,7 +128,8 @@ class Class_CriteresRecherche { 'fil', 'bib_select', 'serie', - 'from']); + 'from'], + Class_CodifThesaurus::getSearchParams()); } @@ -225,6 +226,8 @@ 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'] @@ -232,6 +235,20 @@ 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','')), $this->selectionToArray(Class_CodifGenre::CODE_FACETTE, @@ -519,10 +536,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()); } @@ -567,7 +590,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/tests/scenarios/SearchResult/SearchResultTest.php b/tests/scenarios/SearchResult/SearchResultTest.php index a490198ab1f..fa5ee695214 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,51 @@ 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 "}']); + + $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'); + } } \ No newline at end of file -- GitLab