';
}
/**
* Fetch logs since the start of the courses and structure in series and labels to be sent to Chart API.
*
* @param stdClass $course the course object
* @param stdClass $user user object
* @param string $logreader the log reader where the logs are.
* @return array structured array to be sent to chart API, split in two indexes (series and labels).
*/
function report_log_userall_data($course, $user, $logreader) {
global $CFG;
$site = get_site();
$timenow = time();
$logs = [];
if ($course->id == $site->id) {
$courseselect = 0;
} else {
$courseselect = $course->id;
}
$maxseconds = REPORT_LOG_MAX_DISPLAY * 3600 * 24; // Seconds.
if ($timenow - $course->startdate > $maxseconds) {
$course->startdate = $timenow - $maxseconds;
}
if (!empty($CFG->loglifetime)) {
$maxseconds = $CFG->loglifetime * 3600 * 24; // Seconds.
if ($timenow - $course->startdate > $maxseconds) {
$course->startdate = $timenow - $maxseconds;
}
}
$timestart = $coursestart = usergetmidnight($course->startdate);
$i = 0;
$logs['series'][$i] = 0;
$logs['labels'][$i] = 0;
while ($timestart < $timenow) {
$timefinish = $timestart + 86400;
$logs['labels'][$i] = userdate($timestart, "%a %d %b");
$logs['series'][$i] = 0;
$i++;
$timestart = $timefinish;
}
$rawlogs = report_log_usercourse($user->id, $courseselect, $coursestart, $logreader);
foreach ($rawlogs as $rawlog) {
if (isset($logs['labels'][$rawlog->day])) {
$logs['series'][$rawlog->day] = $rawlog->num;
}
}
return $logs;
}
/**
* Fetch logs of the current day and structure in series and labels to be sent to Chart API.
*
* @param stdClass $course the course object
* @param stdClass $user user object
* @param int $date A time of a day (in GMT).
* @param string $logreader the log reader where the logs are.
* @return array $logs structured array to be sent to chart API, split in two indexes (series and labels).
*/
function report_log_usertoday_data($course, $user, $date, $logreader) {
$site = get_site();
$logs = [];
if ($course->id == $site->id) {
$courseselect = 0;
} else {
$courseselect = $course->id;
}
if ($date) {
$daystart = usergetmidnight($date);
} else {
$daystart = usergetmidnight(time());
}
for ($i = 0; $i <= 23; $i++) {
$hour = $daystart + $i * 3600;
$logs['series'][$i] = 0;
$logs['labels'][$i] = userdate($hour, "%H:00");
}
$rawlogs = report_log_userday($user->id, $courseselect, $daystart, $logreader);
foreach ($rawlogs as $rawlog) {
if (isset($logs['labels'][$rawlog->hour])) {
$logs['series'][$rawlog->hour] = $rawlog->num;
}
}
return $logs;
}