Beispiel #1
0
 protected function generate()
 {
     if ($this->subperiodsProcessed) {
         return;
     }
     parent::generate();
     $year = $this->date->get("Y");
     for ($i = 1; $i <= 12; $i++) {
         $this->addSubperiod(new Piwik_Period_Month(Piwik_Date::factory("{$year}-{$i}-01")));
     }
 }
Beispiel #2
0
 protected function generate()
 {
     if ($this->subperiodsProcessed) {
         return;
     }
     parent::generate();
     $date = $this->date;
     $startMonth = $date->setDay(1);
     $currentDay = clone $startMonth;
     while ($currentDay->compareMonth($startMonth) == 0) {
         $this->addSubperiod(new Piwik_Period_Day($currentDay));
         $currentDay = $currentDay->addDay(1);
     }
 }
Beispiel #3
0
 protected function generate()
 {
     if ($this->subperiodsProcessed) {
         return;
     }
     parent::generate();
     $date = $this->date;
     if ($date->toString('N') > 1) {
         $date = $date->subDay($date->toString('N') - 1);
     }
     $startWeek = $date;
     $currentDay = clone $startWeek;
     while ($currentDay->compareWeek($startWeek) == 0) {
         $this->addSubperiod(new Piwik_Period_Day($currentDay));
         $currentDay = $currentDay->addDay(1);
     }
 }
Beispiel #4
0
 protected function generate()
 {
     if ($this->subperiodsProcessed) {
         return;
     }
     parent::generate();
     if (preg_match('/(last|previous)([0-9]*)/', $this->strDate, $regs)) {
         $lastN = $regs[2];
         $lastOrPrevious = $regs[1];
         if (!is_null($this->defaultEndDate)) {
             $defaultEndDate = $this->defaultEndDate;
         } else {
             $defaultEndDate = Piwik_Date::today();
         }
         if ($lastOrPrevious == 'last') {
             $endDate = $defaultEndDate;
         } elseif ($lastOrPrevious == 'previous') {
             $endDate = $this->removePeriod($defaultEndDate, 1);
         }
         // last1 means only one result ; last2 means 2 results so we remove only 1 to the days/weeks/etc
         $lastN--;
         $lastN = abs($lastN);
         $lastN = $this->getMaxN($lastN);
         $startDate = $this->removePeriod($endDate, $lastN);
     } elseif (preg_match('/([0-9]{4}-[0-9]{1,2}-[0-9]{1,2}),([0-9]{4}-[0-9]{1,2}-[0-9]{1,2})/', $this->strDate, $regs)) {
         $strDateStart = $regs[1];
         $strDateEnd = $regs[2];
         $startDate = Piwik_Date::factory($strDateStart);
         $endDate = Piwik_Date::factory($strDateEnd);
     } else {
         throw new Exception("The date '{$this->strDate}' is not a date range. Should have the following format: 'lastN' or 'previousN' or 'YYYY-MM-DD,YYYY-MM-DD'.");
     }
     $endSubperiod = Piwik_Period::factory($this->strPeriod, $endDate);
     $arrayPeriods = array();
     $arrayPeriods[] = $endSubperiod;
     while ($endDate->isLater($startDate)) {
         $endDate = $this->removePeriod($endDate, 1);
         $subPeriod = Piwik_Period::factory($this->strPeriod, $endDate);
         $arrayPeriods[] = $subPeriod;
     }
     $arrayPeriods = array_reverse($arrayPeriods);
     foreach ($arrayPeriods as $period) {
         $this->addSubperiod($period);
     }
 }
Beispiel #5
0
 protected function generate()
 {
     if ($this->subperiodsProcessed) {
         return;
     }
     parent::generate();
     if (preg_match('/(last|previous)([0-9]*)/', $this->strDate, $regs)) {
         $lastN = $regs[2];
         $lastOrPrevious = $regs[1];
         if (!is_null($this->defaultEndDate)) {
             $defaultEndDate = $this->defaultEndDate;
         } else {
             $defaultEndDate = Piwik_Date::factory('now', $this->timezone);
         }
         $period = $this->strPeriod;
         if ($period == 'range') {
             $period = 'day';
         }
         if ($lastOrPrevious == 'last') {
             $endDate = $defaultEndDate;
         } elseif ($lastOrPrevious == 'previous') {
             $endDate = self::removePeriod($period, $defaultEndDate, 1);
         }
         // last1 means only one result ; last2 means 2 results so we remove only 1 to the days/weeks/etc
         $lastN--;
         $lastN = abs($lastN);
         $lastN = $this->getMaxN($lastN);
         $startDate = self::removePeriod($period, $endDate, $lastN);
     } elseif ($dateRange = Piwik_Period_Range::parseDateRange($this->strDate)) {
         $strDateStart = $dateRange[1];
         $strDateEnd = $dateRange[2];
         $startDate = Piwik_Date::factory($strDateStart);
         if ($strDateEnd == 'today') {
             $strDateEnd = 'now';
         } elseif ($strDateEnd == 'yesterday') {
             $strDateEnd = 'yesterdaySameTime';
         }
         // we set the timezone in the Date object only if the date is relative eg. 'today', 'yesterday', 'now'
         $timezone = null;
         if (strpos($strDateEnd, '-') === false) {
             $timezone = $this->timezone;
         }
         $endDate = Piwik_Date::factory($strDateEnd, $timezone);
     } else {
         throw new Exception(Piwik_TranslateException('General_ExceptionInvalidDateRange', array($this->strDate, ' \'lastN\', \'previousN\', \'YYYY-MM-DD,YYYY-MM-DD\'')));
     }
     if ($this->strPeriod != 'range') {
         $this->fillArraySubPeriods($startDate, $endDate, $this->strPeriod);
         return;
     }
     $this->processOptimalSubperiods($startDate, $endDate);
     // When period=range, we want End Date to be the actual specified end date,
     // rather than the end of the month / week / whatever is used for processing this range
     $this->endDate = $endDate;
 }