diff options
author | mattab <matthieu.aubry@gmail.com> | 2013-06-13 03:52:49 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2013-06-16 12:11:03 +0400 |
commit | 6be9fb2002a0a7da79af55e3263f23c5addfa79c (patch) | |
tree | b867f08bc0bd2a042e9606146bedce18d85d8460 /core/Period.php | |
parent | d8f110aca03ff8c73811a141631f12a7a1ddc16f (diff) |
Continuing the great cleanup. It looks like archiveProcessor will have to go (and merge with Archive)
Moving Transitions logic from plugin class to API
Cleaning up some separation of concerns
NOTE: I'm breaking the Multisites API here, removing the _evolution. we should re-fix it...
Diffstat (limited to 'core/Period.php')
-rw-r--r-- | core/Period.php | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/core/Period.php b/core/Period.php index b004f1731a..b3cfa25f2a 100644 --- a/core/Period.php +++ b/core/Period.php @@ -84,6 +84,24 @@ abstract class Piwik_Period } } + + /** + * Indicate if $dateString and $period correspond to multiple periods + * + * @static + * @param $dateString + * @param $period + * @return boolean + */ + public static function isMultiplePeriod($dateString, $period) + { + return + is_string($dateString) + && (preg_match('/^(last|previous){1}([0-9]*)$/D', $dateString, $regs) + || Piwik_Period_Range::parseDateRange($dateString)) + && $period != 'range'; + } + /** * The advanced factory method is easier to use from the API than the factory * method above. It doesn't require an instance of Piwik_Date and works for @@ -97,14 +115,45 @@ abstract class Piwik_Period */ static public function advancedFactory($strPeriod, $strDate) { - if (Piwik_Archive::isMultiplePeriod($strDate, $strPeriod) || $strPeriod == 'range') { + if (Piwik_Period::isMultiplePeriod($strDate, $strPeriod) || $strPeriod == 'range') { return new Piwik_Period_Range($strPeriod, $strDate); } - return self::factory($strPeriod, Piwik_Date::factory($strDate)); + return Piwik_Period::factory($strPeriod, Piwik_Date::factory($strDate)); } /** + * Creates a period instance using a Piwik_Site instance and two strings describing + * the period & date. + * + * @param string $timezone + * @param string $period The period string: day, week, month, year, range + * @param string $strDate The date or date range string. + * @return Piwik_Period + */ + public static function makePeriodFromQueryParams($timezone, $period, $date) + { + if (empty($timezone)) { + $timezone = 'UTC'; + } + + if ($period == 'range') { + $oPeriod = new Piwik_Period_Range('range', $date, $timezone, Piwik_Date::factory('today', $timezone)); + } else { + if (!($date instanceof Piwik_Date)) { + if ($date == 'now' || $date == 'today') { + $date = date('Y-m-d', Piwik_Date::factory('now', $timezone)->getTimestamp()); + } elseif ($date == 'yesterday' || $date == 'yesterdaySameTime' ) { + $date = date('Y-m-d', Piwik_Date::factory('now', $timezone)->subDay(1)->getTimestamp()); + } + $date = Piwik_Date::factory( $date ); + } + $oPeriod = Piwik_Period::factory($period, $date); + } + return $oPeriod; + } + + /** * Returns the first day of the period * * @return Piwik_Date First day of the period |