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 | |
parent | 7c7c061fbebcb2ec936e5a45cea1d1cdaea31764 (diff) |
moves Annotations.getDateRangeForPeriod to plugin class (#15840)
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Annotations/API.php | 46 | ||||
-rw-r--r-- | plugins/Annotations/Annotations.php | 46 | ||||
-rw-r--r-- | plugins/Annotations/Controller.php | 2 |
3 files changed, 49 insertions, 45 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. */ diff --git a/plugins/Annotations/Annotations.php b/plugins/Annotations/Annotations.php index 791a4939cd..a31a1d5063 100644 --- a/plugins/Annotations/Annotations.php +++ b/plugins/Annotations/Annotations.php @@ -8,6 +8,10 @@ */ namespace Piwik\Plugins\Annotations; +use Piwik\Date; +use Piwik\Period; +use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Evolution as EvolutionViz; + /** * Annotations plugins. Provides the ability to attach text notes to * dates for each sites. Notes can be viewed, modified, deleted or starred. @@ -47,4 +51,46 @@ class Annotations extends \Piwik\Plugin { $jsFiles[] = "plugins/Annotations/javascripts/annotations.js"; } + + + /** + * 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) + */ + public static function getDateRangeForPeriod($date, $period, $lastN = false) + { + if ($date === false) { + return array(false, false); + } + + $isMultiplePeriod = Period\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 Period\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); + } } diff --git a/plugins/Annotations/Controller.php b/plugins/Annotations/Controller.php index a7fac4d75c..012d85ea05 100644 --- a/plugins/Annotations/Controller.php +++ b/plugins/Annotations/Controller.php @@ -67,7 +67,7 @@ class Controller extends \Piwik\Plugin\Controller $view->period = $period; $view->lastN = $lastN; - list($startDate, $endDate) = API::getDateRangeForPeriod($date, $period, $lastN); + list($startDate, $endDate) = Annotations::getDateRangeForPeriod($date, $period, $lastN); $view->startDate = $startDate->toString(); $view->endDate = $endDate->toString(); |