Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authordiosmosis <benaka@piwik.pro>2015-09-23 10:27:54 +0300
committerdiosmosis <benaka@piwik.pro>2015-10-12 21:05:36 +0300
commit05c7dbdf51981a0eb69a601653434c49233cea0d (patch)
treecba8457b121f1b693dd0868ff3a52e923dfbc501 /core
parent51d7e6a653b63d083c75770c19746180cb8f0c93 (diff)
Move subperiod calculation from invalidate archive command to Range period class + add unit tests.
Diffstat (limited to 'core')
-rw-r--r--core/Period.php5
-rw-r--r--core/Period/Range.php46
2 files changed, 50 insertions, 1 deletions
diff --git a/core/Period.php b/core/Period.php
index 6ee9e4c752..1f2681448d 100644
--- a/core/Period.php
+++ b/core/Period.php
@@ -9,6 +9,7 @@
namespace Piwik;
use Piwik\Container\StaticContainer;
+use Piwik\Period\Factory;
use Piwik\Period\Range;
use Piwik\Translation\Translator;
@@ -282,6 +283,10 @@ abstract class Period
* Returns the label of the period type that is one size smaller than this one, or null if
* it's the smallest.
*
+ * Range periods and other such 'period collections' are not considered as separte from
+ * the value type of the collection. So a range period will return the result of the
+ * subperiod's `getImmediateChildPeriodLabel()` method.
+ *
* @ignore
* @return string|null
*/
diff --git a/core/Period/Range.php b/core/Period/Range.php
index 9b33cbebca..80102ecc1b 100644
--- a/core/Period/Range.php
+++ b/core/Period/Range.php
@@ -516,6 +516,50 @@ class Range extends Period
public function getImmediateChildPeriodLabel()
{
- return 'day'; // ranges are made up of a collection of days
+ $subperiods = $this->getSubperiods();
+ return reset($subperiods)->getImmediateChildPeriodLabel();
+ }
+
+ /**
+ * Returns all child periods that exist within this periods entire date range.
+ *
+ * @param bool $cascade If `true`, will cascade downwards over all period types that
+ * are smaller than this one. For example, month periods
+ * will cascade to week and day periods and year periods
+ * will cascade to month, week and day periods.
+ *
+ * The method will return periods that are outside the range
+ * of this period if cascading and a child period for the start/end
+ * date encompasses dates outside the range. For example,
+ * cascading on a month will return the week period for the 1st of
+ * the month. The week period might include days before the 1st.
+ * When cascading further, those days will be included the result.
+ * @return Period[]
+ * @ignore
+ */
+ public function getAllOverlappingChildPeriods($cascade = false)
+ {
+ $result = array();
+
+ $subperiods = $this->getSubperiods();
+ foreach ($subperiods as $subperiod) {
+ $result[] = $subperiod;
+ }
+
+ if (!$cascade) {
+ return $result;
+ }
+
+ $childPeriodType = $this->getImmediateChildPeriodLabel();
+ if (empty($childPeriodType)) {
+ return $result;
+ }
+
+ $startDate = reset($subperiods)->getDateStart()->toString();
+ $endDate = end($subperiods)->getDateEnd()->toString();
+
+ $childPeriods = Factory::build($childPeriodType, $startDate . ',' . $endDate);
+
+ return array_merge($subperiods, $childPeriods->getAllOverlappingChildPeriods($cascade));
}
}