diff options
author | Stefan Giehl <stefan@matomo.org> | 2020-04-22 11:08:39 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-22 11:08:39 +0300 |
commit | d3e8c0279e395a99949b0854c9b4e850fc4c06f9 (patch) | |
tree | 73e1fb2f320984864ccefcddcc4e0f4fd8fd4870 /plugins/Annotations/API.php | |
parent | 7c7c061fbebcb2ec936e5a45cea1d1cdaea31764 (diff) |
moves Annotations.getDateRangeForPeriod to plugin class (#15840)
Diffstat (limited to 'plugins/Annotations/API.php')
-rw-r--r-- | plugins/Annotations/API.php | 46 |
1 files changed, 2 insertions, 44 deletions
diff --git a/plugins/Annotations/API.php b/plugins/Annotations/API.php index a0d2d5b276..e76f5c3e5d 100644 --- a/plugins/Annotations/API.php +++ b/plugins/Annotations/API.php @@ -189,7 +189,7 @@ class API extends \Piwik\Plugin\API $annotations = new AnnotationList($idSite); // if date/period are supplied, determine start/end date for search - list($startDate, $endDate) = self::getDateRangeForPeriod($date, $period, $lastN); + list($startDate, $endDate) = Annotations::getDateRangeForPeriod($date, $period, $lastN); return $annotations->search($startDate, $endDate); } @@ -224,7 +224,7 @@ class API extends \Piwik\Plugin\API Piwik::checkUserHasViewAccess($idSite); // get start & end date for request. lastN is ignored if $period == 'range' - list($startDate, $endDate) = self::getDateRangeForPeriod($date, $period, $lastN); + list($startDate, $endDate) = Annotations::getDateRangeForPeriod($date, $period, $lastN); if ($period == 'range') { $period = 'day'; } @@ -302,48 +302,6 @@ class API extends \Piwik\Plugin\API } /** - * Returns start & end dates for the range described by a period and optional lastN - * argument. - * - * @param string|bool $date The start date of the period (or the date range of a range - * period). - * @param string $period The period type ('day', 'week', 'month', 'year' or 'range'). - * @param bool|int $lastN Whether to include the last N periods in the range or not. - * Ignored if period == range. - * - * @return Date[] array of Date objects or array(false, false) - * @ignore - */ - public static function getDateRangeForPeriod($date, $period, $lastN = false) - { - if ($date === false) { - return array(false, false); - } - - $isMultiplePeriod = Range::isMultiplePeriod($date, $period); - - // if the range is just a normal period (or the period is a range in which case lastN is ignored) - if ($period == 'range') { - $oPeriod = new Range('day', $date); - $startDate = $oPeriod->getDateStart(); - $endDate = $oPeriod->getDateEnd(); - } else if ($lastN == false && !$isMultiplePeriod) { - $oPeriod = Period\Factory::build($period, Date::factory($date)); - $startDate = $oPeriod->getDateStart(); - $endDate = $oPeriod->getDateEnd(); - } else { // if the range includes the last N periods or is a multiple period - if (!$isMultiplePeriod) { - list($date, $lastN) = EvolutionViz::getDateRangeAndLastN($period, $date, $lastN); - } - list($startDate, $endDate) = explode(',', $date); - - $startDate = Date::factory($startDate); - $endDate = Date::factory($endDate); - } - return array($startDate, $endDate); - } - - /** * Utility function, makes sure idSite string has only one site ID and throws if * otherwise. */ |