Skip to content
Extraits de code Groupes Projets
Valider 4606f4da rédigé par Thomas Steur's avatar Thomas Steur
Parcourir les fichiers

refs #6811 make sure the endDate is valid when switching between websites

Imagine website is created on 2015-12-20, if current selected date
was eg 2015-04-18,2015-04-29 the startDate was automatically fixed
already to 2015-12-20,2015-04-29 but not the endDate. This is now
done and it will apply 2015-12-20,2015-12-20.
The code looks a bit more complex as there was another bug that
although it applied 2015-12-20,2015-12-20 it did still
display the date range for 2015-04-18,2015-04-29 in the UI in
the calendar which is wrong. Also I do now fix the date in case
period != range. So period=day&date=2015-04-29 would result in
period=day&date=2015-12-20
parent a9cb3fc9
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -580,43 +580,55 @@ abstract class Controller ...@@ -580,43 +580,55 @@ abstract class Controller
*/ */
protected function setGeneralVariablesView($view) protected function setGeneralVariablesView($view)
{ {
$view->date = $this->strDate;
$view->idSite = $this->idSite; $view->idSite = $this->idSite;
$this->checkSitePermission(); $this->checkSitePermission();
$this->setPeriodVariablesView($view); $this->setPeriodVariablesView($view);
$rawDate = Common::getRequestVar('date');
$periodStr = Common::getRequestVar('period');
if ($periodStr != 'range') {
$date = Date::factory($this->strDate);
$period = Period\Factory::build($periodStr, $date);
} else {
$period = new Range($periodStr, $rawDate, $this->site->getTimezone());
}
$view->rawDate = $rawDate;
$view->prettyDate = self::getCalendarPrettyDate($period);
$view->siteName = $this->site->getName(); $view->siteName = $this->site->getName();
$view->siteMainUrl = $this->site->getMainUrl(); $view->siteMainUrl = $this->site->getMainUrl();
$siteTimezone = $this->site->getTimezone();
$datetimeMinDate = $this->site->getCreationDate()->getDatetime(); $datetimeMinDate = $this->site->getCreationDate()->getDatetime();
$minDate = Date::factory($datetimeMinDate, $this->site->getTimezone()); $minDate = Date::factory($datetimeMinDate, $siteTimezone);
$this->setMinDateView($minDate, $view); $this->setMinDateView($minDate, $view);
$maxDate = Date::factory('now', $this->site->getTimezone()); $maxDate = Date::factory('now', $siteTimezone);
$this->setMaxDateView($maxDate, $view); $this->setMaxDateView($maxDate, $view);
$rawDate = Common::getRequestVar('date');
$periodStr = Common::getRequestVar('period');
if ($periodStr != 'range') {
$date = Date::factory($this->strDate);
$validDate = $this->getValidDate($date, $minDate, $maxDate);
$period = Period\Factory::build($periodStr, $validDate);
if ($date->toString() !== $validDate->toString()) {
// we to not always change date since it could convert a strDate "today" to "YYYY-MM-DD"
// only change $this->strDate if it was not valid before
$this->setDate($validDate);
}
} else {
$period = new Range($periodStr, $rawDate, $siteTimezone);
}
// Setting current period start & end dates, for pre-setting the calendar when "Date Range" is selected // Setting current period start & end dates, for pre-setting the calendar when "Date Range" is selected
$dateStart = $period->getDateStart(); $dateStart = $period->getDateStart();
if ($dateStart->isEarlier($minDate)) { $dateStart = $this->getValidDate($dateStart, $minDate, $maxDate);
$dateStart = $minDate;
} $dateEnd = $period->getDateEnd();
$dateEnd = $period->getDateEnd(); $dateEnd = $this->getValidDate($dateEnd, $minDate, $maxDate);
if ($dateEnd->isLater($maxDate)) {
$dateEnd = $maxDate; if ($periodStr == 'range') {
// make sure we actually display the correct calendar pretty date
$newRawDate = $dateStart->toString() . ',' . $dateEnd->toString();
$period = new Range($periodStr, $newRawDate, $siteTimezone);
} }
$view->date = $this->strDate;
$view->prettyDate = self::getCalendarPrettyDate($period);
$view->rawDate = $rawDate;
$view->startDate = $dateStart; $view->startDate = $dateStart;
$view->endDate = $dateEnd; $view->endDate = $dateEnd;
...@@ -635,6 +647,19 @@ abstract class Controller ...@@ -635,6 +647,19 @@ abstract class Controller
} }
} }
private function getValidDate(Date $date, Date $minDate, Date $maxDate)
{
if ($date->isEarlier($minDate)) {
$date = $minDate;
}
if ($date->isLater($maxDate)) {
$date = $maxDate;
}
return $date;
}
/** /**
* Assigns a set of generally useful variables to a {@link Piwik\View} instance. * Assigns a set of generally useful variables to a {@link Piwik\View} instance.
* *
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter