diff --git a/application/modules/opac/controllers/BibController.php b/application/modules/opac/controllers/BibController.php index daa0f69013203058788287f9af0756dacdf9f959..2214620b3c580e07e84ab7a5ed18dfd183f24df7 100644 --- a/application/modules/opac/controllers/BibController.php +++ b/application/modules/opac/controllers/BibController.php @@ -240,65 +240,14 @@ class BibController extends ZendAfi_Controller_Action { $settings = Class_Profil::getCurrentProfil() ->getBoitesDivision($id_division)[$id_module]; - if(!Class_Users::isCurrentUserCanAccesBackend()) + if(!Class_Users::isCurrentUserCanAccesBackend() || !$this->_getParam('default_filters')) return $settings; - $new_settings = $this->_addFiltersToDefault($this->_deleteFiltersFromDefault($settings)); + $settings['preferences']['default_filters'] = $this->_getSelectedFilters(); + Class_Profil::getCurrentProfil() + ->updateModuleConfigAccueil($id_module, $settings) + ->save(); - if (array_values($settings['preferences']['default_filters']) - != array_values($new_settings['preferences']['default_filters'])) - Class_Profil::getCurrentProfil() - ->updateModuleConfigAccueil($id_module, $new_settings) - ->save(); - - return $new_settings; - } - - - protected function _addFiltersToDefault($settings) { - return $this->_updateDefaultFilters($settings, - Class_Systeme_ModulesAccueil_Library::ADD_DEFAULT_PREFIX, - function($filters_to_save, $saved_filters) - { - return $filters_to_save + $saved_filters; - }); - } - - - protected function _deleteFiltersFromDefault($settings) { - return $this->_updateDefaultFilters($settings, - Class_Systeme_ModulesAccueil_Library::DELETE_DEFAULT_PREFIX, - function($filters_to_delete, $saved_filters) - { - return array_filter($saved_filters, - function($filter) use ($filters_to_delete) - { - foreach($filters_to_delete as $key => $value) - return !($value == $filter); - }); - }); - } - - - protected function _updateDefaultFilters($settings, $prefix, $callback) { - $filter_keys = (new Class_Systeme_ModulesAccueil_Library())->getStaticFiltersKeys(); - $add_keys = array_map(function($key) use ($prefix) - { - return $prefix . $key; - }, - $filter_keys); - - $filters = []; - - foreach($this->_helper->selectedFilters($add_keys) as $key => $value) - $filters[str_replace($prefix, '', $key)] = $value; - - if(!$filters) - return $settings; - - $settings['preferences']['default_filters'] = call_user_func_array($callback, - [$filters, - $settings['preferences']['default_filters']]); return $settings; } diff --git a/library/Class/FilterSettings.php b/library/Class/FilterSettings.php index 4f9e269d3e6ef0db59803a8861c7166429bab02f..e97fb0aabb7def64fd274bcfcec3cbb1a79100c7 100644 --- a/library/Class/FilterSettings.php +++ b/library/Class/FilterSettings.php @@ -73,7 +73,7 @@ class Class_FilterSettings extends Class_Entity { public function getActiveFilters() { if($this->getUseDefaultFilters()) - return $this->getSelectedFilters() + $this->getDefaultFilters(); + return $this->getDefaultFilters(); return $this->getSelectedFilters(); } diff --git a/library/Class/Systeme/ModulesAccueil/Library.php b/library/Class/Systeme/ModulesAccueil/Library.php index 233725c243600c5edcf918a21f091089fae68c2d..38c75dc8450d13bc09f7342efe0f29e8153beb30 100644 --- a/library/Class/Systeme/ModulesAccueil/Library.php +++ b/library/Class/Systeme/ModulesAccueil/Library.php @@ -45,11 +45,6 @@ class Class_Systeme_ModulesAccueil_Library extends Class_Systeme_ModulesAccueil_ const POSITION_LEFT = 'left'; const POSITION_RIGHT = 'right'; - const DEFAULT_PREFIX = 'default_'; - - const ADD_DEFAULT_PREFIX = 'add_default_'; - const DELETE_DEFAULT_PREFIX = 'delete_default_'; - /** @var string */ protected $_group = Class_Systeme_ModulesAccueil::GROUP_SITE; diff --git a/library/ZendAfi/View/Helper/Accueil/Library.php b/library/ZendAfi/View/Helper/Accueil/Library.php index 4497cc35842f3f8c0b4564b9a356ab9888025efd..03568046b3fc13fe24c8eda0b1c23770461ad472 100644 --- a/library/ZendAfi/View/Helper/Accueil/Library.php +++ b/library/ZendAfi/View/Helper/Accueil/Library.php @@ -41,6 +41,22 @@ class ZendAfi_View_Helper_Accueil_Library extends ZendAfi_View_Helper_Accueil_Ba } + protected function _addToDefaultFiltersLink() { + if(!Class_Users::isCurrentUserCanAccesBackend()) + return ''; + return $this->view->tagAnchor($this->view->url(array_merge( + $this->_getBaseUrl(), + ['default_filters' => 1, + 'render' => null])), + Class_Admin_Skin::current() + ->renderMenuIconOn('moderation', + $this->view, + ['title' => $this->view->_('Enregistrer comme filtres par défaut')]), + ['class' => 'default_filters']); + + } + + public function getContent() { $nb_aff = $this->preferences['nb_aff'] ? $this->preferences['nb_aff'] @@ -72,7 +88,7 @@ class ZendAfi_View_Helper_Accueil_Library extends ZendAfi_View_Helper_Accueil_Ba $pagination == Class_Systeme_ModulesAccueil_Library::PAGINATION_BOTH) $content .= $this->_getPaginator($libraries, $nb_aff, $this->page); - return $content; + return $this->_addToDefaultFiltersLink() . $content; } @@ -230,6 +246,7 @@ class ZendAfi_View_Helper_Accueil_Library extends ZendAfi_View_Helper_Accueil_Ba return array_merge(['controller' => 'bib', 'action' => 'widget-page', + 'default_filters' => null, 'id_module' => $this->getIdModule(), 'id_division' => $this->division], $filters); diff --git a/library/ZendAfi/View/Helper/Filters/Strategy/Abstract.php b/library/ZendAfi/View/Helper/Filters/Strategy/Abstract.php index db58018dfc228f2490ef77a387ec049721cfb817..47df489dbbd3ae61695ddb9bd5a843355520554c 100644 --- a/library/ZendAfi/View/Helper/Filters/Strategy/Abstract.php +++ b/library/ZendAfi/View/Helper/Filters/Strategy/Abstract.php @@ -92,14 +92,6 @@ abstract class ZendAfi_View_Helper_Filters_Strategy_Abstract extends ZendAfi_Vie } - protected function _isDefaultKey($value) { - if(!isset($this->_settings->getDefaultFilters()[$this->_getFilterKey()])) - return false; - - return $this->_settings->getDefaultFilters()[$this->_getFilterKey()] == [$value]; - } - - protected function _getCustomFieldId() { return $this->_filter_elements->getCustomFieldId(); } diff --git a/library/ZendAfi/View/Helper/Filters/Strategy/Checkbox.php b/library/ZendAfi/View/Helper/Filters/Strategy/Checkbox.php index 07d536a08020c1fb06bcb669795ec4cf546f3ec5..1db9da876289bcb91b193f505fb94c0cbc7f7c09 100644 --- a/library/ZendAfi/View/Helper/Filters/Strategy/Checkbox.php +++ b/library/ZendAfi/View/Helper/Filters/Strategy/Checkbox.php @@ -55,7 +55,6 @@ class ZendAfi_View_Helper_Filters_Strategy_Checkbox extends ZendAfi_View_Helper_ ['type' => 'checkbox', 'name' => $label, 'value' => $label, - 'data-url' => $url])) - . $this->_setDefaultValue($label, $label, $url_params)); + 'data-url' => $url]))); } } diff --git a/library/ZendAfi/View/Helper/Filters/Strategy/Elements.php b/library/ZendAfi/View/Helper/Filters/Strategy/Elements.php index 9020c4a2c82f206edca8163481ca3d330b44bc52..87845f426715029d8ed011017b7595e7e5f6fc34 100644 --- a/library/ZendAfi/View/Helper/Filters/Strategy/Elements.php +++ b/library/ZendAfi/View/Helper/Filters/Strategy/Elements.php @@ -60,38 +60,6 @@ abstract class ZendAfi_View_Helper_Filters_Strategy_Elements extends ZendAfi_Vie } - protected function _setDefaultValue($value, $label, $url_params) { - if(!$value) - return ''; - - if(!Class_Users::isCurrentUserCanAccesBackend()) - return ''; - - $checked = $this->_isDefaultKey($value) - ? ['checked' => 'checked'] - : []; - - $key = $checked - ? Class_Systeme_ModulesAccueil_Library::DELETE_DEFAULT_PREFIX . $this->_getFilterKey() - : Class_Systeme_ModulesAccueil_Library::ADD_DEFAULT_PREFIX . $this->_getFilterKey(); - - $url_params = array_merge($url_params, - [$key => $value]); - - $url = $this->view->url($url_params, null, true); - - $saved_label = $key . '_' . $label; - return $this->view->tag('input', - '', - array_merge( - ['type' => 'checkbox', - 'name' => $saved_label, - 'title' => $this->view->_('Appliquer le filtre %s par défaut', $label), - 'data-url' => $url], - $checked)); - } - - public abstract function renderFilterItems($elements); protected abstract function _renderFilterItem($value, $label, $selected); } diff --git a/library/ZendAfi/View/Helper/Filters/Strategy/Facet.php b/library/ZendAfi/View/Helper/Filters/Strategy/Facet.php index e0b27a9eaef2bda535dd0232b6618ac7ae6ecf9e..cd67f505c17c17b410eeb5ff9a0eaf88849d8a64 100644 --- a/library/ZendAfi/View/Helper/Filters/Strategy/Facet.php +++ b/library/ZendAfi/View/Helper/Filters/Strategy/Facet.php @@ -48,8 +48,7 @@ class ZendAfi_View_Helper_Filters_Strategy_Facet extends ZendAfi_View_Helper_Fil $url = $this->view->url($url_params, null, true); return $this->_tag('li', - $this->view->tagAnchor($url, $label) - . $this->_setDefaultValue($value, $label, $url_params), + $this->view->tagAnchor($url, $label), $selected ? ['class' => 'selected'] : []); } } \ No newline at end of file diff --git a/public/admin/js/onload_utils.js b/public/admin/js/onload_utils.js index 78cd808688a4fe6f3990e0c0aa88d285b049cb64..d2ef3bd4f457bf595f4530d7d0a738549435fe87 100644 --- a/public/admin/js/onload_utils.js +++ b/public/admin/js/onload_utils.js @@ -75,6 +75,7 @@ var autoHideShowConfigurationModule = function() { autoHideShowTagOnParentHover('a[class^="edit_"]', 'div.boite'); autoHideShowTagOnParentHover('.select_kiosque_form', 'div.boite'); autoHideShowTagOnParentHover('.newsadd', 'div.boite'); + autoHideShowTagOnParentHover('.default_filters', 'div.boite'); } diff --git a/public/opac/css/global.css b/public/opac/css/global.css index 3a8d02811ef2bb73d7fc93cf168dbc40495e6e10..c81a896e63b298d602c55768d1d24d199c8d7641 100644 --- a/public/opac/css/global.css +++ b/public/opac/css/global.css @@ -36,7 +36,8 @@ a { /* Boites bannière*/ .configuration_module, -.configuration_module + .newsadd { +.configuration_module + .newsadd, +.configuration_module + .default_filters { z-index: 1000; position: relative; height: 0px; @@ -44,7 +45,8 @@ a { cursor:pointer; } -.configuration_module + .newsadd { +.configuration_module + .newsadd, +.configuration_module + .default_filters { margin-right:60px; } diff --git a/public/opac/js/renderFilters/ajaxifyFilters.js b/public/opac/js/renderFilters/ajaxifyFilters.js index 0527ab6b88374481e699db56abfe63b61afd6a3d..8a642a431ea0f2ee17a5effb8b9da25532dd1726 100644 --- a/public/opac/js/renderFilters/ajaxifyFilters.js +++ b/public/opac/js/renderFilters/ajaxifyFilters.js @@ -45,7 +45,7 @@ }; - var links = widget.find(".filters a"); + var links = widget.find(".filters a, a.default_filters"); links.click(function(event) { refresh($(this), event, 'href'); }); diff --git a/tests/application/modules/opac/controllers/BibControllerTest.php b/tests/application/modules/opac/controllers/BibControllerTest.php index 48bbc4629e19138eec17bee77130d950dffbdca7..cbc776635e989e728a02086b4d1c3737b325a792 100644 --- a/tests/application/modules/opac/controllers/BibControllerTest.php +++ b/tests/application/modules/opac/controllers/BibControllerTest.php @@ -1725,7 +1725,7 @@ class BibControllerSelectionOrderDisplayAndFiltersTest extends BibControllerWidg /** @test */ public function customfieldServiceShouldContainsValueRestaurationAddToDefault() { - $this->assertXPath('//li//input[@type="checkbox"][@value="Restauration"][@checked][following-sibling::input[contains(@data-url, "/add_default_custom_field_7/Restauration")]]', $this->_response->getBody()); + $this->assertXPath('//li//input[@type="checkbox"][@value="Restauration"][@checked]'); } } @@ -1917,7 +1917,7 @@ class BibControllerDefaultFiltersTest extends BibControllerWidgetPageTestCase { public function setUp() { parent::setUp(); - $this->dispatch('/bib/widget-page/id_module/1/id_division/2/page/1/add_default_opening/opened', true); + $this->dispatch('/bib/widget-page/id_module/1/id_division/2/page/1/opening/opened/default_filters/1', true); } @@ -1929,8 +1929,8 @@ class BibControllerDefaultFiltersTest extends BibControllerWidgetPageTestCase { /** @test */ - public function openedShouldBeChecked() { - $this->assertXPath('//ul/li/input[contains(@data-url, "delete_default_opening/opened")][@checked]'); + public function linkToSaveDefaultFilterShouldContainsOpening() { + $this->assertXPath('//a[contains(@href, "/bib/widget-page/id_module/1/id_division/2/page/1/opening/opened/default_filters/1")][@class="default_filters"]'); } } @@ -1940,7 +1940,7 @@ class BibControllerAddDefaultCustomFieldsFiltersTest extends BibControllerWidget public function setUp() { parent::setUp(); - $this->dispatch('/bib/widget-page/id_module/1/id_division/2/page/1/add_default_custom_field_7/Restauration', true); + $this->dispatch('/bib/widget-page/id_module/1/id_division/2/page/1/custom_field_7/Restauration/default_filters/1', true); } @@ -1949,12 +1949,6 @@ class BibControllerAddDefaultCustomFieldsFiltersTest extends BibControllerWidget $this->assertEquals(['Restauration'], Class_Profil::getCurrentProfil() ->getBoitesDivision(2)[1]['preferences']['default_filters']['7']); } - - - /** @test */ - public function restaurationShouldBeChecked() { - $this->assertXPath('//ul/li/input[contains(@data-url, "delete_default_custom_field_7/Restauration")][@checked]'); - } } @@ -1978,8 +1972,8 @@ class BibControllerWithDefaultFiltersTest extends BibControllerWidgetPageTestCas /** @test */ - public function openedShouldBeChecked() { - $this->assertXPathContentContains('//ul/li/a[following-sibling::input[@checked]]', 'Ouvert aujourd\'hui'); + public function openedShouldNotBeSelected() { + $this->assertXPathContentContains('//ul/li[not(@class="selected")]/a', 'Ouvert aujourd\'hui'); } } @@ -2000,13 +1994,13 @@ class BibControllerDeleteDefaultFiltersTest extends BibControllerWidgetPageTestC ]) ->save(); - $this->dispatch('/bib/widget-page/id_module/1/id_division/2/page/1/delete_default_opening/opened', true); + $this->dispatch('/bib/widget-page/id_module/1/id_division/2/page/1/default_filters/1', true); } /** @test */ - public function openedShouldNotBeChecked() { - $this->assertXPath('//ul/li[not(@class="selected")]/a[text()="Ouvert aujourd\'hui"][following-sibling::input[not(@checked)]]'); + public function openedShouldBeSelected() { + $this->assertXPath('//ul/li[not(@class="selected")]/a[text()="Ouvert aujourd\'hui"]'); } @@ -2014,6 +2008,12 @@ class BibControllerDeleteDefaultFiltersTest extends BibControllerWidgetPageTestC public function openedShouldHaveBeenRemovedFromSettings() { $this->assertEmpty(Class_Profil::getCurrentProfil()->getBoitesDivision(2)[1]['preferences']['default_filters']); } + + + /** @test */ + public function linkToSaveDefaultFilterShouldNotContainsOpening() { + $this->assertXPath('//a[contains(@href, "/bib/widget-page/id_module/1/id_division/2/page/1/default_filters/1")][@class="default_filters"]'); + } }