diff --git a/application/modules/admin/controllers/BibController.php b/application/modules/admin/controllers/BibController.php index 1e842e8bfdd17f1e5d3512c11c9a253c034d6a03..79620939b48f179b91475611cd2085712b471626 100644 --- a/application/modules/admin/controllers/BibController.php +++ b/application/modules/admin/controllers/BibController.php @@ -430,4 +430,33 @@ class Admin_BibController extends ZendAfi_Controller_Action { return $user->hasRightsForLibrary($id); } + + + public function saveDefaultsAction() { + if(!$id_module = (int)$this->_getParam('id_module')) + return $this->_redirectWithMessage($this->_('Configuration introuvable')); + + if(!$id_division = (int)$this->_getParam('id_division')) + return $this->_redirectWithMessage($this->_('Division introuvable')); + + $profil = Class_Profil::getCurrentProfil(); + $settings = $profil + ->getBoitesDivision($id_division)[$id_module]; + + $settings['preferences']['default_filters'] = $this->_helper + ->selectedFilters((new Class_Systeme_ModulesAccueil_Library()) + ->getStaticFiltersKeys()); + + $profil + ->updateModuleConfigAccueil($id_module, $settings) + ->save(); + + $this->_redirectWithMessage($this->_('Les filtres par défaut ont été sauvegardés.')); + } + + + protected function _redirectWithMessage($message) { + $this->_helper->notify($message); + $this->_redirectToReferer(); + } } diff --git a/application/modules/opac/controllers/BibController.php b/application/modules/opac/controllers/BibController.php index 2214620b3c580e07e84ab7a5ed18dfd183f24df7..59c05a84a2bb92d19169778c6bc108fe5e5f8a4a 100644 --- a/application/modules/opac/controllers/BibController.php +++ b/application/modules/opac/controllers/BibController.php @@ -221,7 +221,8 @@ class BibController extends ZendAfi_Controller_Action { $page = (int)$this->_getParam('page'); $helper = (new ZendAfi_View_Helper_Accueil_Library($id_module, - $this->_getSettingsFor($id_division, $id_module))) + Class_Profil::getCurrentProfil() + ->getLocalModuleAccueilConfig($id_module))) ->setView($this->view) ->setPage($page) ->setSelectedFilters($this->_getSelectedFilters()); @@ -236,22 +237,6 @@ class BibController extends ZendAfi_Controller_Action { } - protected function _getSettingsFor($id_division, $id_module) { - $settings = Class_Profil::getCurrentProfil() - ->getBoitesDivision($id_division)[$id_module]; - - if(!Class_Users::isCurrentUserCanAccesBackend() || !$this->_getParam('default_filters')) - return $settings; - - $settings['preferences']['default_filters'] = $this->_getSelectedFilters(); - Class_Profil::getCurrentProfil() - ->updateModuleConfigAccueil($id_module, $settings) - ->save(); - - return $settings; - } - - public function mapAction() { $this->view->titre = $this->_('Carte des bibliothèques'); $this->view->libraries = Class_Bib::findAllWithCoordinates(); diff --git a/library/ZendAfi/View/Helper/Accueil/Library.php b/library/ZendAfi/View/Helper/Accueil/Library.php index e60c77814d823b92032110944e44727af0a3f47e..738d2067ab05fa1b9623f181854d72fb94928555 100644 --- a/library/ZendAfi/View/Helper/Accueil/Library.php +++ b/library/ZendAfi/View/Helper/Accueil/Library.php @@ -67,10 +67,10 @@ class ZendAfi_View_Helper_Accueil_Library extends ZendAfi_View_Helper_Accueil_Ba return ''; return $this->view - ->tagAnchor($this->view->url(array_merge( - $this->_getBaseUrl(), - ['default_filters' => 1, - 'render' => null])), + ->tagAnchor($this->view->url(array_merge($this->_getBaseUrl(), + ['module' => 'admin', + 'controller' => 'bib', + 'action' => 'save-defaults'])), Class_Admin_Skin::current() ->renderMenuIconOn('moderation', $this->view, @@ -261,7 +261,6 @@ 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/ModuleAbstract.php b/library/ZendAfi/View/Helper/ModuleAbstract.php index 5fe8d39f4cd693c4ed612353a9667883c7ac5769..bbbd105adab7b6ffaf31c42c0e86905f7aae8398 100644 --- a/library/ZendAfi/View/Helper/ModuleAbstract.php +++ b/library/ZendAfi/View/Helper/ModuleAbstract.php @@ -28,7 +28,7 @@ abstract class ZendAfi_View_Helper_ModuleAbstract extends ZendAfi_View_Helper_Ba * @param int $id_module * @param array $params */ - public function __construct($id_module,$params) { + public function __construct($id_module, $params) { parent::__construct(); $this->id_module = $id_module; $this->preferences = array_merge($params['preferences'], diff --git a/public/opac/js/renderFilters/ajaxifyFilters.js b/public/opac/js/renderFilters/ajaxifyFilters.js index d51e73ff13a35fa5ed4dddd0a40216ccf4626ed6..d7699ac1912e8c14781b402d84be279dbbd17bea 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, a.default_filters, a[href*='/bib/widget-page']"); + var links = widget.find(".filters a"); links.click(function(event) { refresh($(this), event, 'href'); }); diff --git a/tests/application/modules/admin/controllers/BibControllerTest.php b/tests/application/modules/admin/controllers/BibControllerTest.php index 21427faa7355427822a5de33b144f8a914bf4729..3458b46bb2723f88f1b54e7c17494c5d2c82669d 100644 --- a/tests/application/modules/admin/controllers/BibControllerTest.php +++ b/tests/application/modules/admin/controllers/BibControllerTest.php @@ -328,12 +328,12 @@ class BibControllerWithAdminBibEditAnnecyTest extends BibControllerWithAdminBibT 'libelle' => 'Cran-Gevrier']); $this->custom_field = $this->fixture('Class_CustomField', - ['id' => 7, - 'label' => 'Options', - 'options_list' => 'Wifi;Projection;Restauration', - 'priority' => 3, - 'field_type' => Class_CustomField_Meta::MULTI_CHECKBOX, - 'model' => 'Bib']); + ['id' => 7, + 'label' => 'Options', + 'options_list' => 'Wifi;Projection;Restauration', + 'priority' => 3, + 'field_type' => Class_CustomField_Meta::MULTI_CHECKBOX, + 'model' => 'Bib']); $this->bib_annecy->assertSave(); $this->bib_annecy->setCustomField('Options', ['Wifi','Restauration']); @@ -653,7 +653,7 @@ class BibControllerAnnecyPostWithDuplicateRewriteUrlTest extends BibControllerWi } - /** @test */ + /** @test */ public function withSameRewriteUrlAsProfilLibraryShouldDisplayError() { $this->fixture('Class_Profil', ['id' => 34, @@ -916,12 +916,12 @@ class BibControllerJSONTest extends BibControllerTestCase { /** @test */ function withBibThreeShouldRenderCranJSON() { $this->dispatch('admin/bib/articles/id_bib/3'); - $expectedJSON = <<<JSON + $expectedJSON = ' [ {"id":3,"label": "Cran-Gévrier","categories": [{"id":3,"label": "News","categories": [],"items": [{"id":42,"label":"Vive les vacances !"}]}],"items": []}, {"id":0,"label": "Portail","categories": [{"id":9,"label": "Infos","categories": [],"items": [{"id":123,"label":"Reseau en route"}]}],"items": []} ] -JSON; +'; $this->assertJsonStringEqualsJsonString($expectedJSON, $this->_response->getBody(), $this->_response->getBody()); @@ -930,7 +930,7 @@ JSON; /** @test */ function withNoBibShouldRenderAllArticles() { $this->dispatch('admin/bib/articles/categories_only/0'); - $expectedJSON = <<<JSON + $expectedJSON = ' [{"id":0, "label": "Portail", "categories": [{"id":9, @@ -957,7 +957,7 @@ JSON; "label":"Vive les vacances !" } ]}], "items": []}] -JSON; +'; $this->assertJsonStringEqualsJsonString($expectedJSON, $this->_response->getBody()); } @@ -1273,15 +1273,15 @@ class BibControllerLocalisatonDeleteTest extends BibControllerTestCase { ->answers(true) ->whenCalled('getcwd') ->answers('path'); -; + ; Class_Localisation::setFileSystem($file_system); $location = $this->fixture('Class_Localisation', - ['id' => 9, - 'libelle' => 'Arts', - 'description' => 'Coin des arts.', - 'bib' => $this->bib_annecy, - 'image' => 'bib_2_localisation_9.jpg']); + ['id' => 9, + 'libelle' => 'Arts', + 'description' => 'Coin des arts.', + 'bib' => $this->bib_annecy, + 'image' => 'bib_2_localisation_9.jpg']); @@ -1571,8 +1571,8 @@ abstract class BibControllerPermissionsTestCase extends BibControllerTestCase { parent::setUp(); $this->setupPermissions(); $this->group = $this->fixture('Class_UserGroup', - ['id' => 324, - 'libelle' => 'Testing Permissions Group']); + ['id' => 324, + 'libelle' => 'Testing Permissions Group']); $this->group ->addRight(Class_UserGroup::RIGHT_USER_ACCES_ARTICLES) ->save(); @@ -1822,4 +1822,22 @@ class BibControllerDispatchIndexWithLibraryAdmin extends AbstractControllerTestC public function deleteActionShouldNotBePresent() { $this->assertNotXPath('//a[contains(@href, "admin/bib/delete/id/56")]'); } +} + + + + +class BibControllerWidgetDefaultsActionTest extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + $this->dispatch('/admin/bib/save-defaults', true); + } + + + /** @test */ + public function shouldRedirect() { + $this->assertRedirect(); + } } \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/BibControllerTest.php b/tests/application/modules/opac/controllers/BibControllerTest.php index 2aa06ea131d82221b597c1114315c3a3887dc5b9..dd27725f8c8854bbe3824ac7edf28896dfa39d38 100644 --- a/tests/application/modules/opac/controllers/BibControllerTest.php +++ b/tests/application/modules/opac/controllers/BibControllerTest.php @@ -2003,8 +2003,8 @@ class BibControllerWithDefaultFiltersTest extends BibControllerWidgetPageTestCas /** @test */ - public function openedShouldBeSelected() { - $this->assertXPathContentContains('//ul/li[@class="selected"]/a', 'Ouvert aujourd\'hui'); + public function openedShouldNotBeSelected() { + $this->assertXPathContentContains('//ul/li[not(@class="selected")]/a', 'Ouvert aujourd\'hui'); } }