diff --git a/VERSIONS_HOTLINE/84158 b/VERSIONS_HOTLINE/84158 new file mode 100644 index 0000000000000000000000000000000000000000..d01d7598ab2312cfac3d8066ccf535f5802e614b --- /dev/null +++ b/VERSIONS_HOTLINE/84158 @@ -0,0 +1,2 @@ + - ticket #84158 : Boite agenda : correction de l'affichage des articles avec des jours récurrents sélectionnés. + \ No newline at end of file diff --git a/library/Class/Article.php b/library/Class/Article.php index 802e1d56f88e99a342963ac078005998010fe7b4..b1d6011b76ce4d2cc28d59516227165ac37af410 100644 --- a/library/Class/Article.php +++ b/library/Class/Article.php @@ -368,12 +368,16 @@ class ArticleLoader extends Storm_Model_Loader { ->_orderAndLimit() ->_getSelect(); + $articles = Class_Article::getLoader()->findAll($select); - $articles = $this->_sortArticles( - $this->_filterByDay($this->_event_date, - $this->_filterByCustomFields( - Class_Article::getLoader()->findAll($select), - $this->_custom_fields))); + if ($this->_custom_fields) + $articles = $this->_filterByCustomFields($articles, + $this->_custom_fields); + + if ((new ZendAfi_Validate_DateFormat)->isValid($this->_event_date)) + $articles = $this->_filterByDay($this->_event_date, $articles); + + $articles = $this->_sortArticles($articles); if ( ($this->_sort_order == 'Selection') diff --git a/library/Class/TimeSource.php b/library/Class/TimeSource.php index 4ec2964607c8917bec6f096ec05eecb077b95f24..0be9b3aaec29da3663a65c715463c84e7c359b6d 100644 --- a/library/Class/TimeSource.php +++ b/library/Class/TimeSource.php @@ -99,8 +99,8 @@ class Class_TimeSource { return (int)($this->hoursFrom($time) / 24); } + public function hoursFrom($time) { return (int)(($this->time() - $time) / 3660); } - } \ No newline at end of file diff --git a/library/ZendAfi/Validate/DateFormat.php b/library/ZendAfi/Validate/DateFormat.php new file mode 100644 index 0000000000000000000000000000000000000000..d5ddd78099090838f2787a465ce89d8a435c4e2f --- /dev/null +++ b/library/ZendAfi/Validate/DateFormat.php @@ -0,0 +1,32 @@ +<?php +/** + * Copyright (c) 2012-2018, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class ZendAfi_Validate_DateFormat extends Zend_Validate_Abstract { + + public function isValid($string, $format = 'Y-m-d') { + if (!$string) + return false; + + $date = DateTime::createFromFormat($format, $string); + return $date && ($date->format($format) === $string); + } +} \ No newline at end of file diff --git a/tests/library/Class/ArticleLoaderTest.php b/tests/library/Class/ArticleLoaderTest.php index 4ebb6445c88bd68dc5586ef875ac28943fde6572..215bd719044b73a7596c29f7fae54c807356a840 100644 --- a/tests/library/Class/ArticleLoaderTest.php +++ b/tests/library/Class/ArticleLoaderTest.php @@ -715,7 +715,11 @@ class ArticleLoaderFilterByDayTest extends ArticleLoaderGetArticlesByPreferences $this->assertEquals([18, 55, 57], $this->_getArticlesId(['event_date' => '2011-09-04'])); } -} -?> + /** @test */ + public function withMonthShouldGetAllArticles() { + $this->assertEquals([23, 18, 55, 57], + $this->_getArticlesId(['event_date' => '2011-09'])); + } +}