diff options
author | mattab <matthieu.aubry@gmail.com> | 2014-05-02 05:31:49 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2014-05-02 05:31:49 +0400 |
commit | 77fa82f580764931504a28c91490f66633408c92 (patch) | |
tree | 0a330fecd48744f4b824a1f049e981a3197bc33f /core/Period | |
parent | ffdc6f0dfa908591897c0a15f6d2bd47b7fadc3c (diff) |
Fixes #5037 You can now configure periods that are available in the UI and API
; The list of periods that are available in the Piwik calendar
; Example use case: custom date range requests are processed in real time,
; so they may take a few minutes on very high traffic website: you may remove "range" below to disable this period
enabled_periods_UI = "day,week,month,year,range"
enabled_periods_API = "day,week,month,year,range"
Diffstat (limited to 'core/Period')
-rw-r--r-- | core/Period/Factory.php | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/core/Period/Factory.php b/core/Period/Factory.php index 7a909a182e..2494da0a50 100644 --- a/core/Period/Factory.php +++ b/core/Period/Factory.php @@ -28,15 +28,15 @@ class Factory */ static public function build($period, $date) { + self::checkPeriodIsEnabled($period); + if (is_string($date)) { if (Period::isMultiplePeriod($date, $period) || $period == 'range') { - self::checkPeriodIsEnabled('range'); return new Range($period, $date); } $date = Date::factory($date); } - self::checkPeriodIsEnabled($period); switch ($period) { case 'day': @@ -57,7 +57,7 @@ class Factory } } - private static function checkPeriodIsEnabled($period) + public static function checkPeriodIsEnabled($period) { if(!self::isPeriodEnabledForAPI($period)) { self::throwExceptionInvalidPeriod($period); @@ -70,7 +70,9 @@ class Factory */ private static function throwExceptionInvalidPeriod($strPeriod) { - $message = Piwik::translate('General_ExceptionInvalidPeriod', array($strPeriod, 'day, week, month, year, range')); + $periods = self::getPeriodsEnabledForAPI(); + $periods = implode(", ", $periods); + $message = Piwik::translate('General_ExceptionInvalidPeriod', array($strPeriod, $periods)); throw new Exception($message); } @@ -92,7 +94,8 @@ class Factory } if ($period == 'range') { - $oPeriod = new Period\Range('range', $date, $timezone, Date::factory('today', $timezone)); + self::checkPeriodIsEnabled('range'); + $oPeriod = new Range('range', $date, $timezone, Date::factory('today', $timezone)); } else { if (!($date instanceof Date)) { if ($date == 'now' || $date == 'today') { @@ -113,10 +116,18 @@ class Factory */ public static function isPeriodEnabledForAPI($period) { + $enabledPeriodsInAPI = self::getPeriodsEnabledForAPI(); + return in_array($period, $enabledPeriodsInAPI); + } + + /** + * @return array + */ + private static function getPeriodsEnabledForAPI() + { $enabledPeriodsInAPI = Config::getInstance()->General['enabled_periods_API']; $enabledPeriodsInAPI = explode(",", $enabledPeriodsInAPI); $enabledPeriodsInAPI = array_map('trim', $enabledPeriodsInAPI); - - return in_array($period, $enabledPeriodsInAPI); + return $enabledPeriodsInAPI; } }
\ No newline at end of file |