Пример #1
0
 private function getDefaultDateAndPeriod($defaultDate = null)
 {
     $defaultPeriod = $this->getDefaultPeriodWithoutValidation($defaultDate);
     if (!$defaultDate) {
         $defaultDate = $this->getDefaultDateWithoutValidation();
     }
     $periodValidator = new PeriodValidator();
     if (!$periodValidator->isPeriodAllowedForUI($defaultPeriod)) {
         $defaultDate = $this->getSystemDefaultDate();
         $defaultPeriod = $this->getSystemDefaultPeriod();
     }
     return array($defaultDate, $defaultPeriod);
 }
Пример #2
0
 /**
  * @return array
  */
 public static function getPeriodsEnabledForAPI()
 {
     $periodValidator = new PeriodValidator();
     return $periodValidator->getPeriodsAllowedForAPI();
 }
Пример #3
0
 /**
  * Sets general period variables on a view, including:
  *
  * - **displayUniqueVisitors** - Whether unique visitors should be displayed for the current
  *                               period.
  * - **period** - The value of the **period** query parameter.
  * - **otherPeriods** - `array('day', 'week', 'month', 'year', 'range')`
  * - **periodsNames** - List of available periods mapped to their singular and plural translations.
  *
  * @param View $view
  * @throws Exception if the current period is invalid.
  * @api
  */
 public static function setPeriodVariablesView($view)
 {
     if (isset($view->period)) {
         return;
     }
     $periodValidator = new PeriodValidator();
     $currentPeriod = Common::getRequestVar('period');
     $view->displayUniqueVisitors = SettingsPiwik::isUniqueVisitorsEnabled($currentPeriod);
     $availablePeriods = $periodValidator->getPeriodsAllowedForUI();
     if (!$periodValidator->isPeriodAllowedForUI($currentPeriod)) {
         throw new Exception("Period must be one of: " . implode(", ", $availablePeriods));
     }
     $found = array_search($currentPeriod, $availablePeriods);
     unset($availablePeriods[$found]);
     $view->period = $currentPeriod;
     $view->otherPeriods = $availablePeriods;
     $view->periodsNames = self::getEnabledPeriodsNames();
 }