diff options
author | mattpiwik <matthieu.aubry@gmail.com> | 2010-04-09 13:18:01 +0400 |
---|---|---|
committer | mattpiwik <matthieu.aubry@gmail.com> | 2010-04-09 13:18:01 +0400 |
commit | c062be74ba7341f15cf824566e1de739b09f880c (patch) | |
tree | 1bb1d005d8ad3af1043a46f266f0249d3914b958 /plugins | |
parent | f058d9e291770c47841eca6c6e845e04e39f9b28 (diff) |
Refs #56
* Calendar for a given website will show dates relative to this websites's timezone
* API results now display relative to website's timezone
* MultiSites will convert "today" and "yesterday" to Piwik default timezone
* MultiSites calendar min and max date are the min and max date based on website's timezones. For example, the max date might be tomorrow in UTC if some websites are set to UTC+12
git-svn-id: http://dev.piwik.org/svn/trunk@2067 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/CoreHome/Controller.php | 10 | ||||
-rw-r--r-- | plugins/MultiSites/Controller.php | 76 | ||||
-rw-r--r-- | plugins/MultiSites/templates/index.tpl | 2 | ||||
-rw-r--r-- | plugins/SitesManager/templates/SitesManager.tpl | 4 |
4 files changed, 65 insertions, 27 deletions
diff --git a/plugins/CoreHome/Controller.php b/plugins/CoreHome/Controller.php index 0abc5f919c..853e65d4e3 100644 --- a/plugins/CoreHome/Controller.php +++ b/plugins/CoreHome/Controller.php @@ -62,14 +62,18 @@ class Piwik_CoreHome_Controller extends Piwik_Controller protected function setDateTodayIfWebsiteCreatedToday() { $date = Piwik_Common::getRequestVar('date', false); - $date = Piwik_Date::factory($date); - if($date->isToday()) { + if($date == 'today') + { return; } $websiteId = Piwik_Common::getRequestVar('idSite', false); if ($websiteId) { $website = new Piwik_Site($websiteId); - if( $website->getCreationDate()->isToday() ) { + $datetimeCreationDate = $this->site->getCreationDate()->getDatetime(); + $creationDateLocalTimezone = Piwik_Date::factory($datetimeCreationDate, $website->getTimezone())->toString('Y-m-d'); + $todayLocalTimezone = Piwik_Date::factory('now', $website->getTimezone())->toString('Y-m-d'); + if( $creationDateLocalTimezone == $todayLocalTimezone ) + { Piwik::redirectToModule( 'CoreHome', 'index', array( 'date' => 'today', 'idSite' => $websiteId, diff --git a/plugins/MultiSites/Controller.php b/plugins/MultiSites/Controller.php index 5daa6fc16b..83690354c5 100644 --- a/plugins/MultiSites/Controller.php +++ b/plugins/MultiSites/Controller.php @@ -35,27 +35,30 @@ class Piwik_MultiSites_Controller extends Piwik_Controller public function getSitesInfo() { - $view = new Piwik_View("MultiSites/templates/index.tpl"); + // overwrites the default Date set in the parent controller + // Instead of the default current website's local date, + // we set "today" or "yesterday" based on the default Piwik timezone + $piwikDefaultTimezone = Piwik_SitesManager_API::getInstance()->getDefaultTimezone(); + $date = Piwik_Common::getRequestVar('date', 'today'); + $date = $this->getDateParameterInTimezone($date, $piwikDefaultTimezone); + $this->setDate($date); + $mySites = Piwik_SitesManager_API::getInstance()->getSitesWithAtLeastViewAccess(); - - $params = $this->getGraphParamsModified(); $this->dateToStr = $params['date']; $ids = 'all'; $this->period = Piwik_Common::getRequestVar('period', 'day'); - $this->date = Piwik_Common::getRequestVar('date', 'today'); - - $lastDate = date('Y-m-d',strtotime("-1 ".$this->period, strtotime($this->date))); + $lastDate = date('Y-m-d',strtotime("-1 ".$this->period, strtotime($this->strDate))); - $visits = Piwik_VisitsSummary_API::getInstance()->getVisits($ids, $this->period, $this->date); + $visits = Piwik_VisitsSummary_API::getInstance()->getVisits($ids, $this->period, $this->strDate); $lastVisits = Piwik_VisitsSummary_API::getInstance()->getVisits($ids, $this->period, $lastDate); - $actions = Piwik_VisitsSummary_API::getInstance()->getActions($ids, $this->period, $this->date); + $actions = Piwik_VisitsSummary_API::getInstance()->getActions($ids, $this->period, $this->strDate); $lastActions = Piwik_VisitsSummary_API::getInstance()->getActions($ids, $this->period, $lastDate); - $uniqueUsers = Piwik_VisitsSummary_API::getInstance()->getUniqueVisitors($ids, $this->period, $this->date); + $uniqueUsers = Piwik_VisitsSummary_API::getInstance()->getUniqueVisitors($ids, $this->period, $this->strDate); $lastUniqueUsers = Piwik_VisitsSummary_API::getInstance()->getUniqueVisitors($ids, $this->period, $lastDate); $visitsSummary = $this->getSummary($lastVisits, $visits, $mySites, "visits"); @@ -80,12 +83,14 @@ class Piwik_MultiSites_Controller extends Piwik_Controller $site['visitsSummaryValue'] = $visitsSummary[$idSite]; $site['actionsSummaryValue'] = $actionsSummary[$idSite]; $site['uniqueSummaryValue'] = $uniqueSummary[$idSite]; + } - + + $view = new Piwik_View("MultiSites/templates/index.tpl"); $view->mySites = $mySites; $view->evolutionBy = $this->evolutionBy; $view->period = $this->period; - $view->date = $this->date; + $view->date = $this->strDate; $view->page = $this->page; $view->limit = $this->limit; $view->orderBy = $this->orderBy; @@ -93,25 +98,56 @@ class Piwik_MultiSites_Controller extends Piwik_Controller $view->dateToStr = $this->dateToStr; $view->autoRefreshTodayReport = false; - // if the current date is today (or yesterday, in case the website is set to UTC-12), we refresh the page every 5min - if(in_array($this->date, array('today', date('Y-m-d'), 'yesterday', Piwik_Date::factory('yesterday')->toString('Y-m-d')))) + // if the current date is today, or yesterday, + // in case the website is set to UTC-12), or today in UTC+14, we refresh the page every 5min + if(in_array($this->strDate, array( 'today', date('Y-m-d'), + 'yesterday', Piwik_Date::factory('yesterday')->toString('Y-m-d'), + Piwik_Date::factory('now', 'UTC+14')->toString('Y-m-d')))) { $view->autoRefreshTodayReport = true; } $this->setGeneralVariablesView($view); + $this->setMinMaxDateAcrossWebsites($mySites, $view); - $minTimestamp = Zend_Registry::get('access')->getSitesMinDate(); - if(!empty($minTimestamp)) - { - $minDate = Piwik_Date::factory($minTimestamp); - $this->setMinDateView($minDate, $view); - } echo $view->render(); } + /** + * The Multisites reports displays the first calendar date as the earliest day available for all websites. + * Also, today is the later "today" available across all timezones. + * @param $mySites + * @param $view + * @return void + */ + private function setMinMaxDateAcrossWebsites($mySites, $view) + { + $minDate = null; + $maxDate = Piwik_Date::now(); + foreach($mySites as &$site) + { + // look for 'now' in the website's timezone + $timezone = $site['timezone']; + $date = Piwik_Date::factory('now', $timezone); + if($date->isLater($maxDate)) + { + $maxDate = clone $date; + } + + // look for the absolute minimum date + $creationDate = $site['ts_created']; + $date = Piwik_Date::factory($creationDate, $timezone); + if(is_null($minDate) + || $date->isEarlier($minDate)) + { + $minDate = clone $date; + } + } + $this->setMinDateView($minDate, $view); + $this->setMaxDateView($maxDate, $view); + } + private function getSummary($lastVisits, $currentVisits, $mySites, $type) { - $currentVisitsArray = $currentVisits->getArray(); $lastVisitsArray = $lastVisits->getArray(); $summaryArray = array(); diff --git a/plugins/MultiSites/templates/index.tpl b/plugins/MultiSites/templates/index.tpl index 550b2df1f3..b23487a9c3 100644 --- a/plugins/MultiSites/templates/index.tpl +++ b/plugins/MultiSites/templates/index.tpl @@ -1,6 +1,5 @@ <img src="plugins/MultiSites/images/arrow_desc.gif" style="display: none" /> <img src="plugins/MultiSites/images/arrow_asc.gif" style="display: none" /> - {assign var=showSitesSelection value=false} {assign var=showPeriodSelection value=true} {include file="CoreHome/templates/header.tpl"} @@ -13,7 +12,6 @@ <div id="multisites" style="margin: auto"> <div id="main"> {include file="MultiSites/templates/row.tpl" assign="row"} - <script type="text/javascript"> var allSites = new Array(); var params = new Array(); diff --git a/plugins/SitesManager/templates/SitesManager.tpl b/plugins/SitesManager/templates/SitesManager.tpl index 858f634a1d..533044f4b4 100644 --- a/plugins/SitesManager/templates/SitesManager.tpl +++ b/plugins/SitesManager/templates/SitesManager.tpl @@ -128,8 +128,6 @@ vertical-align:middle; <a name='globalSettings'></a> <h2>{'SitesManager_GlobalWebsitesSettings'|translate}</h2> <br/> - {ajaxErrorDiv id=ajaxErrorGlobalSettings} - {ajaxLoadingDiv id=ajaxLoadingGlobalSettings} <table style='width:600px' class="adminTable adminTableNoBorder" > <tr><td colspan="2"> @@ -175,6 +173,8 @@ vertical-align:middle; </td></tr> </table> <span style='margin-left:20px'><input type="submit" class="submit" id='globalSettingsSubmit' value="{'General_Save'|translate}" /></span> + {ajaxErrorDiv id=ajaxErrorGlobalSettings} + {ajaxLoadingDiv id=ajaxLoadingGlobalSettings} {/if} <br /><br /><br /><br /> |