diff --git a/application/modules/admin/views/scripts/accueil/rechsimple.phtml b/application/modules/admin/views/scripts/accueil/rechsimple.phtml index 3f771c387766399a7ad5fcf35df460bea4c3b29e..4c490b05c35ef0e4a48af49d0e4ece34e244bb76 100644 --- a/application/modules/admin/views/scripts/accueil/rechsimple.phtml +++ b/application/modules/admin/views/scripts/accueil/rechsimple.phtml @@ -126,6 +126,19 @@ $ds->setValue($this->preferences['domain_ids']); echo $ds->render(); ?> + <table> + <tr> + <td class="droite"><?php echo $this->_('Mode de sélection') ?></td> + <td class="gauche"> + <?php + echo $this->formRadioButtons('domain_select_style', + $this->preferences['domain_select_style'], + [Class_Systeme_ModulesAccueil_RechercheSimple::DOMAIN_SELECT_SELECT => $this->_('Sélection dans une liste déroulante'), + Class_Systeme_ModulesAccueil_RechercheSimple::DOMAIN_SELECT_CHECKBOX => $this->_('Sélection multiple par cases à cocher')]); + ?> + </td> + </tr> + </table> </fieldset> <?php echo $this->formSubmit("Valider","Valider",array("class" => "bouton")) ?> </form> diff --git a/library/Class/Systeme/ModulesAccueil/RechercheSimple.php b/library/Class/Systeme/ModulesAccueil/RechercheSimple.php index beab0248ab3aae138189fa017f018c9cf79b8215..33ad55bf441ad4fe3850d7cc70c9babe78ec6602 100644 --- a/library/Class/Systeme/ModulesAccueil/RechercheSimple.php +++ b/library/Class/Systeme/ModulesAccueil/RechercheSimple.php @@ -19,6 +19,11 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Class_Systeme_ModulesAccueil_RechercheSimple extends Class_Systeme_ModulesAccueil_Null{ + + const + DOMAIN_SELECT_SELECT = 'select', + DOMAIN_SELECT_CHECKBOX = 'checkbox'; + /** @var string */ protected $_group = Class_Systeme_ModulesAccueil::GROUP_RECH; @@ -53,7 +58,8 @@ class Class_Systeme_ModulesAccueil_RechercheSimple extends Class_Systeme_Modules 'profil_redirect' => 0, //type de profil vers lequel basculer lors d'une recherche 'placeholder' => '', //message d'exemple dans le champ de recherche 'search_button' => '', //search button text value, - 'domain_ids' => '' // list of domains user can choose to restrict search + 'domain_ids' => '', // list of domains user can choose to restrict search + 'domain_select_style' => self::DOMAIN_SELECT_SELECT // type of domain selection (select / checkbox) ]; } ?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/TagRechercheSimple.php b/library/ZendAfi/View/Helper/TagRechercheSimple.php index 17f741d483575769ed1b605bca4802501288ba57..c9b00f60bf6760ae26856634023c8bced5fc4922 100644 --- a/library/ZendAfi/View/Helper/TagRechercheSimple.php +++ b/library/ZendAfi/View/Helper/TagRechercheSimple.php @@ -151,8 +151,19 @@ class ZendAfi_View_Helper_TagRechercheSimple extends Zend_View_Helper_HtmlElemen if (!$domain_ids) return ''; - $domains = Class_Catalogue::findAllBy(['id_catalogue' => $domain_ids, - 'order' => 'libelle']); + + if (!$domains = Class_Catalogue::findAllBy(['id_catalogue' => $domain_ids, + 'order' => 'libelle'])) + return ''; + + + return $this->preferences['domain_select_style'] == Class_Systeme_ModulesAccueil_RechercheSimple::DOMAIN_SELECT_CHECKBOX + ? $this->_renderDomainSelectAsCheckbox($domains) + : $this->_renderDomainSelectAsSelect($domains); + } + + + protected function _renderDomainSelectAsCheckbox($domains) { $domain_labels = []; foreach($domains as $domain) { if ($th = Class_CodifThesaurus::findThesaurusForCatalogue($domain->getId())) @@ -163,7 +174,6 @@ class ZendAfi_View_Helper_TagRechercheSimple extends Zend_View_Helper_HtmlElemen foreach($domain_labels as $id => $label) { $html .= $this->view->tag('li', - $this->view->formCheckbox('multifacet_H' . $id, null, []) @@ -178,6 +188,23 @@ class ZendAfi_View_Helper_TagRechercheSimple extends Zend_View_Helper_HtmlElemen } + protected function _renderDomainSelectAsSelect($domains) { + $domain_labels = [0 => $this->view->_('Partout')]; + foreach($domains as $domain) + $domain_labels[$domain->getId()] = $domain->getLibelle(); + + return $this->view->tag('label', + $this->view->_('Rechercher dans le domaine') + . + $this->view->formSelect( + 'id_catalogue', + 0, + [], + $domain_labels), + ['for' => 'id_catalogue']); + } + + public function renderInputTypeDoc() { return isset($this->preferences["type_doc"]) ? '<input type="hidden" name="type_doc" value="'.$this->preferences["type_doc"].'" />' diff --git a/tests/application/modules/admin/controllers/AccueilControllerTest.php b/tests/application/modules/admin/controllers/AccueilControllerTest.php index 3e54432e1eb52ddd5893040cae81ae9959f03bc8..2ae422d4462622af315b4886808ea19fb484d89d 100644 --- a/tests/application/modules/admin/controllers/AccueilControllerTest.php +++ b/tests/application/modules/admin/controllers/AccueilControllerTest.php @@ -955,14 +955,28 @@ class AccueilControllerRechSimpleConfigurationTest extends AccueilControllerRech $this->assertXPath('//input[@name="domain_ids"][@value="4"]'); } + /** @test */ public function domainSelectorScriptShouldBeLoaded() { $this->assertXPathContentContains('//script', '$.getJSON("/abonne/viewable-domains-json"'); } + + + /** @test */ + public function domainSelectorStyleShouldHaveRadioSelectChecked() { + $this->assertXPath('//input[@name="domain_select_style"][@type="radio"][@checked="checked"][@value="select"]'); + } + + + /** @test */ + public function domainSelectorStyleShouldHaveRadioCheckboxUnchecked() { + $this->assertXPath('//input[@name="domain_select_style"][@type="radio"][not(@checked)][@value="checkbox"]'); + } } + class AccueilControllerWidgetDomainConfigurationTest extends Admin_AbstractControllerTestCase { public function setup() { diff --git a/tests/library/ZendAfi/View/Helper/TagRechercheSimpleTest.php b/tests/library/ZendAfi/View/Helper/TagRechercheSimpleTest.php index ad2abe667a8b8cf04e3c9c67b95584da2c53086b..53e56ff98adcbe972c7dad7f64a9355d3a0de24f 100644 --- a/tests/library/ZendAfi/View/Helper/TagRechercheSimpleTest.php +++ b/tests/library/ZendAfi/View/Helper/TagRechercheSimpleTest.php @@ -82,60 +82,53 @@ class ZendAfi_View_Helper_TagRechercheSimpleDefaultTest extends ViewHelperTestCa /** @test */ - public function withDomainPreferencesMultifacetCheckboxShouldBePresent() { - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue') - ->whenCalled('saveThesaurus') - ->answers(null); + public function withDomainSelectInputShouldBePresent() { $this->fixture('Class_Catalogue', ['id' => 4, - 'libelle' => 'Adults']); + 'libelle' => 'Youths']); $this->fixture('Class_Catalogue', ['id' => 5, - 'libelle' => 'Youths']); - - $this->fixture('Class_CodifThesaurus', - ['id' => 4, - 'id_thesaurus' => 'CCCC0004', - 'id_origine' => 4, - 'code' => 'Catalogue', 'libelle' => 'Adults']); - $this->fixture('Class_CodifThesaurus', - ['id' => 5, - 'id_thesaurus' => 'CCCC0005', - 'id_origine' => 5, - 'code' => 'Catalogue', - 'libelle' => 'Youth']); - $this->_preferences['domain_ids'] = 'a-4-5-b 1-'; $html = $this->_helper->tagRechercheSimple($this->_preferences, 1); - $this->assertXPathCount($html, '//input[@type="checkbox"][contains(@name, "multifacet")]', - 2); + $this->assertXPathCount($html, '//select[@name="id_catalogue"]//option', + 3); return $html; } /** - * @depends withDomainPreferencesMultifacetCheckboxShouldBePresent + * @depends withDomainSelectInputShouldBePresent * @test */ - public function multifaceHCCCC0004ShouldBePresent($html) { + public function domainSelectFirstOptionShouldBeAll($html) { $this->assertXPathContentContains($html, - '//label[preceding-sibling::input[@name="multifacet_HCCCC0004"]]', - 'Adult'); + '//select[@name="id_catalogue"]/option[1][@value="0"][@selected="selected"]', + 'Partout'); } /** - * @depends withDomainPreferencesMultifacetCheckboxShouldBePresent + * @depends withDomainSelectInputShouldBePresent * @test */ - public function multifaceHCCCC0005ShouldBePresent($html) { + public function domainSelectSecondOptionShouldBeAdults($html) { $this->assertXPathContentContains($html, - '//label[preceding-sibling::input[@name="multifacet_HCCCC0005"]]', - 'Youth', - $html); + '//select[@name="id_catalogue"]/option[2][@value="5"]', + 'Adults'); + } + + + /** + * @depends withDomainSelectInputShouldBePresent + * @test + */ + public function domainSelectThirdOptionShouldBeYouths($html) { + $this->assertXPathContentContains($html, + '//select[@name="id_catalogue"]/option[3][@value="4"]', + 'Youths'); } } @@ -277,5 +270,64 @@ class ZendAfi_View_Helper_TagRechercheSimpleWithSessionParamsTest extends ViewHe $html = $this->_helper->tagRechercheSimple($this->_preferences, 1); $this->assertXPathContentContains($html, '//div//p/span/b', 'Africa, Europe'); } + + + /** @test */ + public function withDomainPreferencesMultifacetCheckboxShouldBePresent() { + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue') + ->whenCalled('saveThesaurus') + ->answers(null); + $this->fixture('Class_Catalogue', + ['id' => 4, + 'libelle' => 'Adults']); + + $this->fixture('Class_Catalogue', + ['id' => 5, + 'libelle' => 'Youths']); + + $this->fixture('Class_CodifThesaurus', + ['id' => 4, + 'id_thesaurus' => 'CCCC0004', + 'id_origine' => 4, + 'code' => 'Catalogue', + 'libelle' => 'Adults']); + + $this->fixture('Class_CodifThesaurus', + ['id' => 5, + 'id_thesaurus' => 'CCCC0005', + 'id_origine' => 5, + 'code' => 'Catalogue', + 'libelle' => 'Youth']); + + $this->_preferences['domain_ids'] = 'a-4-5-b 1-'; + $this->_preferences['domain_select_style'] = Class_Systeme_ModulesAccueil_RechercheSimple::DOMAIN_SELECT_CHECKBOX; + $html = $this->_helper->tagRechercheSimple($this->_preferences, 1); + $this->assertXPathCount($html, '//input[@type="checkbox"][contains(@name, "multifacet")]', + 2); + return $html; + } + + + /** + * @depends withDomainPreferencesMultifacetCheckboxShouldBePresent + * @test + */ + public function multifaceHCCCC0004ShouldBePresent($html) { + $this->assertXPathContentContains($html, + '//label[preceding-sibling::input[@name="multifacet_HCCCC0004"]]', + 'Adult'); + } + + + /** + * @depends withDomainPreferencesMultifacetCheckboxShouldBePresent + * @test + */ + public function multifaceHCCCC0005ShouldBePresent($html) { + $this->assertXPathContentContains($html, + '//label[preceding-sibling::input[@name="multifacet_HCCCC0005"]]', + 'Youth', + $html); + } } ?> \ No newline at end of file