diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/ScheduledReports/Controller.php | 6 | ||||
-rw-r--r-- | plugins/ScheduledReports/Tasks.php | 4 | ||||
-rw-r--r-- | plugins/ScheduledReports/javascripts/pdf.js | 15 | ||||
-rw-r--r-- | plugins/ScheduledReports/lang/en.json | 1 | ||||
-rw-r--r-- | plugins/ScheduledReports/stylesheets/scheduledreports.less | 3 | ||||
-rw-r--r-- | plugins/ScheduledReports/templates/_addReport.twig | 15 | ||||
-rw-r--r-- | plugins/ScheduledReports/templates/index.twig | 1 | ||||
-rw-r--r-- | plugins/ScheduledReports/tests/Integration/ApiTest.php | 17 |
8 files changed, 46 insertions, 16 deletions
diff --git a/plugins/ScheduledReports/Controller.php b/plugins/ScheduledReports/Controller.php index 3192a3cfc4..7316f6283d 100644 --- a/plugins/ScheduledReports/Controller.php +++ b/plugins/ScheduledReports/Controller.php @@ -26,7 +26,11 @@ class Controller extends \Piwik\Plugin\Controller $view = new View('@ScheduledReports/index'); $this->setGeneralVariablesView($view); - $view->countWebsites = count(APISitesManager::getInstance()->getSitesIdWithAtLeastViewAccess()); + $siteTimezone = $this->site->getTimezone(); + $dateTimeZone = new \DateTimeZone($siteTimezone); + + $view->timeZoneDifference = $dateTimeZone->getOffset(new \DateTime()) / 3600; + $view->countWebsites = count(APISitesManager::getInstance()->getSitesIdWithAtLeastViewAccess()); // get report types $reportTypes = API::getReportTypes(); diff --git a/plugins/ScheduledReports/Tasks.php b/plugins/ScheduledReports/Tasks.php index be61e0d793..44a13e1b57 100644 --- a/plugins/ScheduledReports/Tasks.php +++ b/plugins/ScheduledReports/Tasks.php @@ -18,11 +18,9 @@ class Tasks extends \Piwik\Plugin\Tasks foreach (API::getInstance()->getReports() as $report) { if (!$report['deleted'] && $report['period'] != Schedule::PERIOD_NEVER) { - $timezone = Site::getTimezoneFor($report['idsite']); - $schedule = Schedule::getScheduledTimeForPeriod($report['period']); $schedule->setHour($report['hour']); - $schedule->setTimezone($timezone); + $schedule->setTimezone('UTC'); // saved hour is UTC always $this->custom(API::getInstance(), 'sendReport', $report['idreport'], $schedule); } diff --git a/plugins/ScheduledReports/javascripts/pdf.js b/plugins/ScheduledReports/javascripts/pdf.js index 2b86809517..5ddff3654f 100644 --- a/plugins/ScheduledReports/javascripts/pdf.js +++ b/plugins/ScheduledReports/javascripts/pdf.js @@ -9,6 +9,10 @@ var getReportParametersFunctions = Object(); var updateReportParametersFunctions = Object(); var resetReportParametersFunctions = Object(); +function adjustHourToTimezone(hour, difference) { + return (24 + parseInt(hour) + difference) % 24; +} + function formSetEditReport(idReport) { var report = { 'type': ReportPlugin.defaultReportType, @@ -29,11 +33,16 @@ function formSetEditReport(idReport) { toggleReportType(report.type); + var hour = adjustHourToTimezone(report.hour, timeZoneDifference); + $('#report_description').html(report.description); $('#report_segment').find('option[value=' + report.idsegment + ']').prop('selected', 'selected'); $('#report_type').find('option[value=' + report.type + ']').prop('selected', 'selected'); $('#report_period').find('option[value=' + report.period + ']').prop('selected', 'selected'); - $('#report_hour').val(report.hour); + $('#report_hour').val(hour).bind('change', function() { + $('#hour_utc').text(adjustHourToTimezone($(this).val(), -timeZoneDifference)); + }); + $('#hour_utc').text(report.hour); $('[name=report_format].' + report.type + ' option[value=' + report.format + ']').prop('selected', 'selected'); $('select[name=report_type]').change( toggleDisplayOptionsByFormat ); @@ -122,10 +131,12 @@ function initManagePdf() { apiParameters.parameters = getReportParametersFunctions[apiParameters.reportType](); + var hour = adjustHourToTimezone($('#report_hour').val(), -timeZoneDifference); + var ajaxHandler = new ajaxHelper(); ajaxHandler.addParams(apiParameters, 'POST'); ajaxHandler.addParams({period: $('#report_period').find('option:selected').val()}, 'GET'); - ajaxHandler.addParams({hour: $('#report_hour').val()}, 'GET'); + ajaxHandler.addParams({hour: hour}, 'GET'); ajaxHandler.redirectOnSuccess(); ajaxHandler.setLoadingElement(); if (idReport) { diff --git a/plugins/ScheduledReports/lang/en.json b/plugins/ScheduledReports/lang/en.json index a1ef702c9a..60f0254a0d 100644 --- a/plugins/ScheduledReports/lang/en.json +++ b/plugins/ScheduledReports/lang/en.json @@ -29,6 +29,7 @@ "PluginDescription": "Create custom reports and schedule them to be emailed daily, weekly or monthly to one or several people. Several report formats are supported (html, pdf, csv, images).", "ReportFormat": "Report Format", "ReportHour": "Send report at %s o'clock", + "ReportHourWithUTC": "Send report at %1$s o'clock (%2$s o'clock UTC)", "ReportIncludeNWebsites": "The report will include main metrics for all websites that have at least one visit (from the %s websites currently available).", "ReportSent": "Report sent", "ReportsIncluded": "Statistics included", diff --git a/plugins/ScheduledReports/stylesheets/scheduledreports.less b/plugins/ScheduledReports/stylesheets/scheduledreports.less index 871b89da3c..27d2d1557d 100644 --- a/plugins/ScheduledReports/stylesheets/scheduledreports.less +++ b/plugins/ScheduledReports/stylesheets/scheduledreports.less @@ -7,5 +7,6 @@ #report_hour { height: 0.9em; padding: 0 0 0 5px; - width: 35px; + width: 45px; + background-position: 25px center; } diff --git a/plugins/ScheduledReports/templates/_addReport.twig b/plugins/ScheduledReports/templates/_addReport.twig index 24f97ad19f..7ed8a0c588 100644 --- a/plugins/ScheduledReports/templates/_addReport.twig +++ b/plugins/ScheduledReports/templates/_addReport.twig @@ -59,7 +59,20 @@ <br/> {{ 'ScheduledReports_MonthlyScheduleHelp'|translate }} <br/> - {{ 'ScheduledReports_ReportHour'|translate('<input type="text" id="report_hour" class="inp" size="2">')|raw }} + + {% set hourInput %} + <select id="report_hour"> + {% for i in 0..23 %} + <option value="{{ i }}">{{ i }}</option> + {% endfor %} + </select> + {% endset %} + + {% if timeZoneDifference != 0 %} + {{ 'ScheduledReports_ReportHourWithUTC'|translate(hourInput, '<span id="hour_utc"></span>')|raw }} + {% else %} + {{ 'ScheduledReports_ReportHour'|translate(hourInput)|raw }} + {% endif %} </div> </td> </tr> diff --git a/plugins/ScheduledReports/templates/index.twig b/plugins/ScheduledReports/templates/index.twig index 542fab8e70..b98ee70fc5 100644 --- a/plugins/ScheduledReports/templates/index.twig +++ b/plugins/ScheduledReports/templates/index.twig @@ -32,6 +32,7 @@ </div> <script type="text/javascript"> + var timeZoneDifference = {{ timeZoneDifference }}; var ReportPlugin = {}; ReportPlugin.defaultPeriod = '{{ defaultPeriod }}'; ReportPlugin.defaultHour = '{{ defaultHour }}'; diff --git a/plugins/ScheduledReports/tests/Integration/ApiTest.php b/plugins/ScheduledReports/tests/Integration/ApiTest.php index e2d242581f..07d851a694 100644 --- a/plugins/ScheduledReports/tests/Integration/ApiTest.php +++ b/plugins/ScheduledReports/tests/Integration/ApiTest.php @@ -371,21 +371,22 @@ class ApiTest extends IntegrationTestCase )); // expected tasks + // NOTE: scheduled reports are always saved with UTC, to avoid daylight saving issues $scheduleTask1 = Schedule::factory('daily'); - $scheduleTask1->setHour(0); // paris is UTC-1, period ends at 23h UTC - $scheduleTask1->setTimezone('Europe/Paris'); + $scheduleTask1->setHour(0); + $scheduleTask1->setTimezone('UTC'); $scheduleTask2 = new Monthly(); - $scheduleTask2->setHour(0); // site is UTC-6.5, period ends at 6h30 UTC, smallest resolution is hour - $scheduleTask2->setTimezone('UTC-6.5'); + $scheduleTask2->setHour(0); + $scheduleTask2->setTimezone('UTC'); $scheduleTask3 = new Monthly(); - $scheduleTask3->setHour(8); // paris is UTC-1, configured to be sent at 8h - $scheduleTask3->setTimezone('Europe/Paris'); + $scheduleTask3->setHour(8); + $scheduleTask3->setTimezone('UTC'); $scheduleTask4 = new Monthly(); - $scheduleTask4->setHour(8); // site is UTC-6.5, configured to be sent at 8h - $scheduleTask4->setTimezone('UTC-6.5'); + $scheduleTask4->setHour(8); + $scheduleTask4->setTimezone('UTC'); $expectedTasks = array( new Task(APIScheduledReports::getInstance(), 'sendReport', 1, $scheduleTask1), |