Skip to content
Snippets Groups Projects
Commit 8d16723e authored by Thorben Laprell's avatar Thorben Laprell
Browse files

heatmap_start_on_week_start

parent 9a3d8246
No related branches found
No related tags found
No related merge requests found
...@@ -33,7 +33,7 @@ use context_course; ...@@ -33,7 +33,7 @@ use context_course;
class query_helper { class query_helper {
public static function query_heatmap(int $courseid): array { public static function query_heatmap(int $courseid, int $startOfWeek): array {
global $DB; global $DB;
$course = get_course($courseid); $course = get_course($courseid);
...@@ -41,6 +41,8 @@ class query_helper { ...@@ -41,6 +41,8 @@ class query_helper {
$startdate->setTimestamp($course->startdate); $startdate->setTimestamp($course->startdate);
$startdate->modify('Monday this week'); // Get start of week. $startdate->modify('Monday this week'); // Get start of week.
$mondaytimestamp = $startdate->getTimestamp(); $mondaytimestamp = $startdate->getTimestamp();
$calendarTimestamp = $mondaytimestamp + (86400 * ($startOfWeek - 1));
// TODO Implement Daylight saving offeset // TODO Implement Daylight saving offeset
// This does not work very well if daylight saving comes into play, then all old // This does not work very well if daylight saving comes into play, then all old
// dates will be shifted by 1 hour... // dates will be shifted by 1 hour...
...@@ -56,6 +58,6 @@ class query_helper { ...@@ -56,6 +58,6 @@ class query_helper {
ORDER BY heatpoint ORDER BY heatpoint
SQL; SQL;
return $DB->get_records_sql($query, [$mondaytimestamp, $courseid]); return $DB->get_records_sql($query, [$calendarTimestamp, $courseid]);
} }
} }
...@@ -31,6 +31,8 @@ use lareport_weekheatmap\query_helper; ...@@ -31,6 +31,8 @@ use lareport_weekheatmap\query_helper;
use local_learning_analytics\router; use local_learning_analytics\router;
use local_learning_analytics\settings; use local_learning_analytics\settings;
require_once('../../calendar/lib.php');
class lareport_weekheatmap extends report_base { class lareport_weekheatmap extends report_base {
public function run(array $params): array { public function run(array $params): array {
...@@ -43,7 +45,12 @@ class lareport_weekheatmap extends report_base { ...@@ -43,7 +45,12 @@ class lareport_weekheatmap extends report_base {
$xstrs = []; $xstrs = [];
$texts = []; $texts = [];
$days = array('sunday', 'saturday', 'friday', 'thursday', 'wednesday', 'tuesday', 'monday'); $startOfWeek = calendar_get_starting_weekday();
$days = array('saturday', 'friday', 'thursday', 'wednesday', 'tuesday', 'monday', 'sunday');
for($i=0; $i<$startOfWeek; $i++) {
$days = array($days[6], $days[0], $days[1], $days[2], $days[3], $days[4], $days[5]);
}
$ystrs = []; $ystrs = [];
foreach ($days as $day) { foreach ($days as $day) {
$ystrs[] = get_string($day, 'calendar'); $ystrs[] = get_string($day, 'calendar');
...@@ -57,7 +64,7 @@ class lareport_weekheatmap extends report_base { ...@@ -57,7 +64,7 @@ class lareport_weekheatmap extends report_base {
$maxvalue = 0; $maxvalue = 0;
$hitsstr = get_string('hits', 'lareport_weekheatmap'); $hitsstr = get_string('hits', 'lareport_weekheatmap');
$heatpoints = query_helper::query_heatmap($courseid); $heatpoints = query_helper::query_heatmap($courseid, $startOfWeek);
for ($d = 0; $d < 7; $d += 1) { for ($d = 0; $d < 7; $d += 1) {
// we need to start the plot at the bottom (sun -> sat -> fri -> ...) // we need to start the plot at the bottom (sun -> sat -> fri -> ...)
$startpos = (6 - $d) * 24; $startpos = (6 - $d) * 24;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment