diff --git a/application/modules/opac/controllers/BibController.php b/application/modules/opac/controllers/BibController.php index ca19b70e3c29f99934453bec95b9e00976a20129..d5d764f1dbf42e7d615a167a6a0dccefce852207 100644 --- a/application/modules/opac/controllers/BibController.php +++ b/application/modules/opac/controllers/BibController.php @@ -220,11 +220,12 @@ class BibController extends ZendAfi_Controller_Action { $id_division = (int)$this->_getParam('id_division'); $page = (int)$this->_getParam('page'); + $default_filters = $this->_getDefaultFilters(); + $helper = (new ZendAfi_View_Helper_Accueil_Library($id_module, Class_Profil::getCurrentProfil() ->getBoitesDivision($id_division)[$id_module])) ->setView($this->view) ->setPage($page) - ->setDefaultFilters($this->_getDefaultFilters()) ->setSelectedFilters($this->_getSelectedFilters()); $this->view->lib_helper = $helper; @@ -272,15 +273,14 @@ class BibController extends ZendAfi_Controller_Action { if(!isset($module_params['preferences']['default_filters'])) $module_params['preferences']['default_filters'] = []; - $module_params['preferences']['default_filters'] = array_merge($module_params['preferences']['default_filters'], - $defaults_to_save); + $module_params['preferences']['default_filters'] = $defaults_to_save + $module_params['preferences']['default_filters']; + Class_Profil::getCurrentProfil() ->updateModuleConfigAccueil($id_module, $module_params) ->save(); } if($defaults_to_delete && Class_Users::isCurrentUserCanAccesBackend()) { - if(!isset($module_params['preferences']['default_filters'])) continue; diff --git a/library/Class/FilterSettings.php b/library/Class/FilterSettings.php index 4ade064f66dbe140fea106a1066c0059792e747e..4f9e269d3e6ef0db59803a8861c7166429bab02f 100644 --- a/library/Class/FilterSettings.php +++ b/library/Class/FilterSettings.php @@ -72,14 +72,10 @@ class Class_FilterSettings extends Class_Entity { public function getActiveFilters() { - if(!$default_filters = $this->getDefaultFilters()) - return $this->getSelectedFilters(); + if($this->getUseDefaultFilters()) + return $this->getSelectedFilters() + $this->getDefaultFilters(); - if(!$selected_filters = $this->getSelectedFilters()) - return $default_filters; - - return array_merge($default_filters, - $selected_filters); + return $this->getSelectedFilters(); } } ?> \ No newline at end of file diff --git a/library/Class/Systeme/ModulesAccueil/Library.php b/library/Class/Systeme/ModulesAccueil/Library.php index ad7322dc8b567df3291c88c2958d29ea8b05e9e2..775477375bba3a55960f129e2544c2e8f2468b73 100644 --- a/library/Class/Systeme/ModulesAccueil/Library.php +++ b/library/Class/Systeme/ModulesAccueil/Library.php @@ -143,7 +143,6 @@ class Class_Systeme_ModulesAccueil_Library extends Class_Systeme_ModulesAccueil_ protected function _getCustomFields() { $custom_fields = Class_CustomField_Model::getModel('Bib')->getFields(); $custom_fields_list = []; - foreach ($custom_fields as $field) $custom_fields_list['custom_field_' . $field->getId()] = $field->getLabel(); diff --git a/library/ZendAfi/View/Helper/Accueil/Library.php b/library/ZendAfi/View/Helper/Accueil/Library.php index ee1100cf16cfdc45e4f70c9845cf2da2e54ddaf2..4497cc35842f3f8c0b4564b9a356ab9888025efd 100644 --- a/library/ZendAfi/View/Helper/Accueil/Library.php +++ b/library/ZendAfi/View/Helper/Accueil/Library.php @@ -25,6 +25,7 @@ class ZendAfi_View_Helper_Accueil_Library extends ZendAfi_View_Helper_Accueil_Ba $_filters, $_selected_filters = [], $_default_filters = [], + $_use_default_filters = true, $_filter_settings; @@ -35,10 +36,6 @@ class ZendAfi_View_Helper_Accueil_Library extends ZendAfi_View_Helper_Accueil_Ba public function getHtml() { $this->titre = $this->preferences['titre']; - - if(!$this->_default_filters && isset($this->preferences['default_filters'])) - $this->_default_filters = $this->preferences['default_filters']; - $this->contenu = $this->getContent(); return $this->getHtmlArray(); } @@ -53,9 +50,12 @@ class ZendAfi_View_Helper_Accueil_Library extends ZendAfi_View_Helper_Accueil_Ba ? $this->preferences['pagination'] : $this->_getDefaultPreference('pagination'); - $libraries = $this->_filterLibraries($this->_loadLibraries()); - $content = $this->_renderFilters(); + if(isset($this->preferences['default_filters'])) + $this->_default_filters = $this->preferences['default_filters']; + $libraries = $this->_loadLibraries(); + $content = $this->_renderFilters(); + $libraries = $this->_filterLibraries($libraries); $content .= $this->preferences['osm_map'] ? $this->view->librariesMap(Class_Bib::filterByCoordinates($libraries), '#boite_' . $this->getIdModule(), @@ -78,6 +78,7 @@ class ZendAfi_View_Helper_Accueil_Library extends ZendAfi_View_Helper_Accueil_Ba public function setSelectedFilters($filters) { $this->_selected_filters = $filters; + $this->_use_default_filters = false; return $this; } @@ -204,6 +205,7 @@ class ZendAfi_View_Helper_Accueil_Library extends ZendAfi_View_Helper_Accueil_Ba ->setFilters($this->_filters) ->setSelectedFilters($this->_selected_filters) ->setDefaultFilters($this->_default_filters) + ->setUseDefaultFilters($this->_use_default_filters) ->setModelLabel('Bib') ->setUrlParams($this->_getBaseUrl()) ->setFiltersDisplayMode($this->preferences['filters_display_modes']) @@ -235,8 +237,9 @@ class ZendAfi_View_Helper_Accueil_Library extends ZendAfi_View_Helper_Accueil_Ba protected function _getActiveFilters() { - return array_merge($this->_default_filters, - $this->_selected_filters); + if(!$this->_filter_settings) + return []; + return $this->_filter_settings->getActiveFilters(); } diff --git a/library/ZendAfi/View/Helper/Filters/Strategy/Facet.php b/library/ZendAfi/View/Helper/Filters/Strategy/Facet.php index da574a53fe336a3cf64b730bfec3ea542bd08cb3..1c907707f6df20a7b15e7df658a510b25ed3a492 100644 --- a/library/ZendAfi/View/Helper/Filters/Strategy/Facet.php +++ b/library/ZendAfi/View/Helper/Filters/Strategy/Facet.php @@ -39,7 +39,7 @@ class ZendAfi_View_Helper_Filters_Strategy_Facet extends ZendAfi_View_Helper_Fil if ($this->_getCustomFieldId() == 'date') return ''; - return $this->_renderFilterItem('all', $this->_('Tous'), $selected); + return $this->_renderFilterItem(null, $this->_('Tous'), $selected); } @@ -55,7 +55,7 @@ class ZendAfi_View_Helper_Filters_Strategy_Facet extends ZendAfi_View_Helper_Fil protected function _setDefaultValue($value, $label) { - if(!$value || $value == 'all') + if(!$value) return ''; if(!Class_Users::isCurrentUserCanAccesBackend()) diff --git a/tests/application/modules/opac/controllers/BibControllerTest.php b/tests/application/modules/opac/controllers/BibControllerTest.php index 3330b992ff3a23a64c5a760ca409e88dd3912649..9d5f775b41c4191f08ee77b6aec0b8846a1ca8c9 100644 --- a/tests/application/modules/opac/controllers/BibControllerTest.php +++ b/tests/application/modules/opac/controllers/BibControllerTest.php @@ -1922,15 +1922,9 @@ class BibControllerDefaultFiltersTest extends BibControllerWidgetPageTestCase { } - /** @test */ - public function openedShouldBeSelected() { - $this->assertXPathContentContains('//ul/li[@class="selected"]/a', 'Ouvert aujourd\'hui', $this->_response->getBody()); - } - - /** @test */ public function openedShouldBeChecked() { - $this->assertXPath('//ul/li[@class="selected"]/input[contains(@data-url, "delete_default_opening/opened")][@checked]', $this->_response->getBody()); + $this->assertXPath('//ul/li/input[contains(@data-url, "delete_default_opening/opened")][@checked]'); } } @@ -1955,8 +1949,8 @@ class BibControllerWithDefaultFiltersTest extends BibControllerWidgetPageTestCas /** @test */ - public function openedShouldBeSelected() { - $this->assertXPathContentContains('//ul/li[@class="selected"]/a', 'Ouvert aujourd\'hui'); + public function openedShouldBeChecked() { + $this->assertXPathContentContains('//ul/li/a[following-sibling::input[@checked]]', 'Ouvert aujourd\'hui'); } } @@ -1981,8 +1975,8 @@ class BibControllerDeleteDefaultFiltersTest extends BibControllerWidgetPageTestC /** @test */ - public function openedShouldBeSelected() { - $this->assertXPathContentContains('//ul/li[not(@class="selected")]/a', 'Ouvert aujourd\'hui'); + public function openedShouldNotBeChecked() { + $this->assertXPath('//ul/li[not(@class="selected")]/a[text()="Ouvert aujourd\'hui"][following-sibling::input[not(@checked)]]'); } } @@ -2008,7 +2002,7 @@ class BibControllerWithDefaultFiltersAllFacetsSelectedTest extends BibController /** @test */ - public function openedShouldBeSelected() { + public function openedShouldNotBeSelected() { $this->assertXPathContentContains('//ul/li[not(@class="selected")]/a', 'Ouvert aujourd\'hui'); }