diff --git a/VERSIONS_HOTLINE/94066 b/VERSIONS_HOTLINE/94066 new file mode 100644 index 0000000000000000000000000000000000000000..f1da4653656a181e51d876d5a2a17647371b1a81 --- /dev/null +++ b/VERSIONS_HOTLINE/94066 @@ -0,0 +1 @@ + - ticket #94066 : Filtres de l'agenda : Ajout de l'élément "Tous" sur le filtre "Mois" pour déselectionner le critère lorsque la configuration d'affichage est mise à "Afficher le calendrier" = "non" \ No newline at end of file diff --git a/library/Class/Calendar.php b/library/Class/Calendar.php index 44ad270138d544bf8bff964d4dbd36b5dd51ca70..65d307f047add2334d7a564cf65b6972e3833192 100644 --- a/library/Class/Calendar.php +++ b/library/Class/Calendar.php @@ -291,6 +291,11 @@ class Class_Calendar { } + public function isDisplayNoCalendar() { + return 0 == $this->preferences['display_calendar']; + } + + public function getActiveFilters() { if (empty($filters = $this->getEnabledFilters())) return []; diff --git a/library/ZendAfi/View/Helper/Filters/Element.php b/library/ZendAfi/View/Helper/Filters/Element.php index 81e91c9da3b8c18791a3eb8fdc119d2935a17a74..551df2ad2e2915c6f16d7357725c6594fec90141 100644 --- a/library/ZendAfi/View/Helper/Filters/Element.php +++ b/library/ZendAfi/View/Helper/Filters/Element.php @@ -83,6 +83,17 @@ abstract class ZendAfi_View_Helper_Filters_Element extends ZendAfi_View_Helper_B } + /** + * @param Class_FilterSettings $settings + * @param callable $callback + * + * Take a chance to decide whether to render any value item or not + */ + public function renderAnyValueItem($settings, $callback) { + return call_user_func($callback); + } + + protected function _getFilterStrategy() { return ZendAfi_View_Helper_Filters_Strategy_Abstract::newFor($this); } diff --git a/library/ZendAfi/View/Helper/Filters/Element/Date.php b/library/ZendAfi/View/Helper/Filters/Element/Date.php index d29e5a7222f81fedcce91b1aa2c3dbf2061c5142..343f333e489146d683daad2723aef5f4d2515c89 100644 --- a/library/ZendAfi/View/Helper/Filters/Element/Date.php +++ b/library/ZendAfi/View/Helper/Filters/Element/Date.php @@ -26,8 +26,10 @@ class ZendAfi_View_Helper_Filters_Element_Date extends ZendAfi_View_Helper_Filte } - protected function _renderAnyValueItem($base_url, $selected) { - return ''; + public function renderAnyValueItem($settings, $callback) { + return ($calendar = $settings->getCalendar()) && $calendar->isDisplayNoCalendar() + ? parent::renderAnyValueItem($settings, $callback) + : ''; } diff --git a/library/ZendAfi/View/Helper/Filters/Strategy/Elements.php b/library/ZendAfi/View/Helper/Filters/Strategy/Elements.php index 87845f426715029d8ed011017b7595e7e5f6fc34..c5aad13dc27fac08f93013254bd8bb1893062da0 100644 --- a/library/ZendAfi/View/Helper/Filters/Strategy/Elements.php +++ b/library/ZendAfi/View/Helper/Filters/Strategy/Elements.php @@ -20,7 +20,8 @@ */ -abstract class ZendAfi_View_Helper_Filters_Strategy_Elements extends ZendAfi_View_Helper_Filters_Strategy_Abstract { +abstract class ZendAfi_View_Helper_Filters_Strategy_Elements + extends ZendAfi_View_Helper_Filters_Strategy_Abstract { protected function _shouldRender() { diff --git a/library/ZendAfi/View/Helper/Filters/Strategy/Facet.php b/library/ZendAfi/View/Helper/Filters/Strategy/Facet.php index f6fcc2343fc3f8323acfbb0cdd3881d403214be7..c3a19bf8953512258daf0a3320a916c39800d999 100644 --- a/library/ZendAfi/View/Helper/Filters/Strategy/Facet.php +++ b/library/ZendAfi/View/Helper/Filters/Strategy/Facet.php @@ -20,7 +20,8 @@ */ -class ZendAfi_View_Helper_Filters_Strategy_Facet extends ZendAfi_View_Helper_Filters_Strategy_Elements { +class ZendAfi_View_Helper_Filters_Strategy_Facet + extends ZendAfi_View_Helper_Filters_Strategy_Elements { public function renderFilterItems($elements) { $html = $this->_renderAnyValueItem(!$this->_isActive()); @@ -32,10 +33,12 @@ class ZendAfi_View_Helper_Filters_Strategy_Facet extends ZendAfi_View_Helper_Fil protected function _renderAnyValueItem($selected) { - if ($this->_getCustomFieldId() == 'date') - return ''; - - return $this->_renderFilterItem(null, $this->_('Tous'), $selected); + return $this->_filter_elements + ->renderAnyValueItem($this->_settings, + function () use($selected) + { + return $this->_renderFilterItem(null, $this->_('Tous'), $selected); + }); } diff --git a/tests/application/modules/opac/controllers/CmsControllerCalendarActionTest.php b/tests/application/modules/opac/controllers/CmsControllerCalendarActionTest.php index eb14bcff09501969ad7c17764e3146fe9dcd57f7..f8a9a6c14c378aa70da2e874ac4957715e1bec5b 100644 --- a/tests/application/modules/opac/controllers/CmsControllerCalendarActionTest.php +++ b/tests/application/modules/opac/controllers/CmsControllerCalendarActionTest.php @@ -276,7 +276,8 @@ class CmsControllerCalendarActionWithMultipleFiltersTest extends CmsControllerCa } -abstract class CmsControllerCalendarActionWithFiltersTestCase extends CmsControllerCalendarActionTestCase { +abstract class CmsControllerCalendarActionWithFiltersTestCase + extends CmsControllerCalendarActionTestCase { protected $_opac4, $_date, @@ -309,7 +310,8 @@ abstract class CmsControllerCalendarActionWithFiltersTestCase extends CmsControl -class CmsControllerCalendarActionWithFiltersDateTest extends CmsControllerCalendarActionWithFiltersTestCase { +class CmsControllerCalendarActionWithFiltersDateTest + extends CmsControllerCalendarActionWithFiltersTestCase { public function setUp() { parent::setUp(); @@ -348,6 +350,15 @@ class CmsControllerCalendarActionWithFiltersDateTest extends CmsControllerCalen } + /** @test */ + public function calendarFilterOnMonthShouldNotContainsLinkToResetDate() { + $expected = '/custom_field_2/opac'; + $this->assertNotXPathContentContains('//li[@data-id="date"]//a["' . $expected. '"=substring(@href, string-length(@href)-' . (strlen($expected)-1) .')]', + 'Tous', + $this->_response->getBody()); + } + + /** @test **/ public function calendarWithCustomFieldFiltersShouldBuildPreferencesForGetArticlesByPreferences() { $this->assertXPathContentContains('//a[@class="calendar_event_title"]', @@ -424,11 +435,13 @@ class CmsControllerCalendarActionWithFiltersDateTest extends CmsControllerCalen $this->assertXPath('//a[@class="calendar_title_month_clickable"][contains(@href,"/day/2014-06")][contains(@href, "/date/2014-06")]'); } + /** @test */ public function linkCurrentMonthContainsDayParameter() { $this->assertXPath('//a[@class="calendar_title_month_clickable"][contains(@href,"/day/2014-07")][contains(@href,"/cms/calendar")]'); } + /** @test */ public function linkInsideCalendarShouldContainsDayButNoDateParameters() { $this->assertXPath('//a[contains(@class,"day_clickable")][contains(@href,"/day/2014-07-17")][not(contains(@href, "/date/"))]', @@ -438,6 +451,44 @@ class CmsControllerCalendarActionWithFiltersDateTest extends CmsControllerCalen +class CmsControllerCalendarActionWithFiltersDateAndNoCalendarTest + extends CmsControllerCalendarActionWithFiltersTestCase { + public function setUp() { + parent::setUp(); + + Class_Article::getLoader() + ->whenCalled('getArticlesByPreferences') + ->with(array_merge($this->_common_preferences, ['event_date' => '2014-07'])) + ->answers([$this->_opac4]) + + ->whenCalled('getArticlesByPreferences') + ->with(array_merge($this->_common_preferences, ['event_date' => '', + 'event_start_after' => '2014-07', + 'event_end_after' => '', + 'limit' => 3])) + ->answers([]) + ->beStrict(); + + $profil = Class_Profil::find(3); + $cfg_accueil = $profil->getCfgAccueilAsArray(); + $cfg_accueil['modules'][1]['preferences']['display_calendar'] = '0'; + $profil->setCfgAccueil($cfg_accueil)->assertSave(); + + $this->dispatch('/cms/calendar/id_profil/3/id_module/1/date/2014-07/custom_field_2/opac/render/ajax', true); + } + + + /** @test */ + public function calendarFilterOnMonthShouldContainsLinkToResetDate() { + $expected = '/custom_field_2/opac'; + $this->assertXPathContentContains('//li[@data-id="date"]//a["' . $expected. '"=substring(@href, string-length(@href)-' . (strlen($expected)-1) .')]', + 'Tous', + $this->_response->getBody()); + } +} + + + class CmsControllerCalendarActionWithFiltersDayTest extends CmsControllerCalendarActionWithFiltersTestCase { public function setUp() { diff --git a/tests/library/ZendAfi/View/Helper/Accueil/CalendarTest.php b/tests/library/ZendAfi/View/Helper/Accueil/CalendarTest.php index 3a5e2cf2e35245824292ac89439b1fe9811b979b..0a1cbbc0c33da03d404bf934809517a025be5870 100644 --- a/tests/library/ZendAfi/View/Helper/Accueil/CalendarTest.php +++ b/tests/library/ZendAfi/View/Helper/Accueil/CalendarTest.php @@ -950,9 +950,9 @@ abstract class CalendarHelperDisplayModeTestCase extends CalendarViewHelperTestC 'categorie' => '', 'contenu' => 'toto' ]); - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Article') - ->whenCalled('getArticlesByPreferences') - ->answers([$this->_article_bokeh]); + $this->onLoaderOfModel('Class_Article') + ->whenCalled('getArticlesByPreferences') + ->answers([$this->_article_bokeh]); $params = ['type_module' => 'CALENDAR', 'division' => 2, @@ -1127,14 +1127,16 @@ class CalendarHelperWithFiltersTest extends CalendarHelperDisplayModeTestCase { /** @test */ public function dateFilterShouldContainsAllMonths() { $this->assertXPathCount($this->html, - '//ul[contains(@class, "filters")]/li[@class="date"]/ul/li', 12, $this->html); + '//ul[contains(@class, "filters")]/li[@class="date"]/ul/li', + 13, + $this->html); } /** @test */ public function dateFilterShouldContainsJuillet() { $this->assertXPathContentContains($this->html, - '//ul[contains(@class, "filters")]/li[@class="date"]//li[1]/a[contains(@href, "date/2014-07")]', 'Juillet', $this->html); + '//ul[contains(@class, "filters")]/li[@class="date"]//li[2]/a[contains(@href, "date/2014-07")]', 'Juillet', $this->html); } @@ -1142,7 +1144,7 @@ class CalendarHelperWithFiltersTest extends CalendarHelperDisplayModeTestCase { /** @test */ public function dateFilterShouldContainsJuin() { $this->assertXPathContentContains($this->html, - '//ul[contains(@class, "filters")]/li[@class="date"]//li[12]/a[contains(@href, "date/2015-06")]', 'Juin'); + '//ul[contains(@class, "filters")]/li[@class="date"]//li[13]/a[contains(@href, "date/2015-06")]', 'Juin'); }