mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
Merge branch 'MDL-36380-23' of git://github.com/FMCorz/moodle into MOODLE_23_STABLE
This commit is contained in:
commit
48f3a2495b
1 changed files with 49 additions and 11 deletions
|
@ -1368,6 +1368,18 @@ function stats_get_report_options($courseid,$mode) {
|
||||||
return $reportoptions;
|
return $reportoptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fix missing entries in the statistics.
|
||||||
|
*
|
||||||
|
* This creates a dummy stat when nothing happened during a day/week/month.
|
||||||
|
*
|
||||||
|
* @param array $stats array of statistics.
|
||||||
|
* @param int $timeafter unused.
|
||||||
|
* @param string $timestr type of statistics to generate (dayly, weekly, monthly).
|
||||||
|
* @param boolean $line2
|
||||||
|
* @param boolean $line3
|
||||||
|
* @return array of fixed statistics.
|
||||||
|
*/
|
||||||
function stats_fix_zeros($stats,$timeafter,$timestr,$line2=true,$line3=false) {
|
function stats_fix_zeros($stats,$timeafter,$timestr,$line2=true,$line3=false) {
|
||||||
|
|
||||||
if (empty($stats)) {
|
if (empty($stats)) {
|
||||||
|
@ -1375,23 +1387,37 @@ function stats_fix_zeros($stats,$timeafter,$timestr,$line2=true,$line3=false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$timestr = str_replace('user_','',$timestr); // just in case.
|
$timestr = str_replace('user_','',$timestr); // just in case.
|
||||||
$fun = 'stats_get_base_'.$timestr;
|
|
||||||
|
|
||||||
|
// Gets the current user base time.
|
||||||
|
$fun = 'stats_get_base_'.$timestr;
|
||||||
$now = $fun();
|
$now = $fun();
|
||||||
|
|
||||||
$times = array();
|
// Extract the ending time of the statistics.
|
||||||
// add something to timeafter since it is our absolute base
|
|
||||||
$actualtimes = array();
|
$actualtimes = array();
|
||||||
foreach ($stats as $statid=>$s) {
|
$actualtimeshour = null;
|
||||||
//normalize the times in stats - those might have been created in different timezone, DST etc.
|
foreach ($stats as $statid => $s) {
|
||||||
$s->timeend = $fun($s->timeend + 60*60*5);
|
// Normalise the month date to the 1st if for any reason it's set to later. But we ignore
|
||||||
|
// anything above or equal to 29 because sometimes we get the end of the month. Also, we will
|
||||||
|
// set the hours of the result to all of them, that way we prevent DST differences.
|
||||||
|
if ($timestr == 'monthly') {
|
||||||
|
$day = date('d', $s->timeend);
|
||||||
|
if (date('d', $s->timeend) > 1 && date('d', $s->timeend) < 29) {
|
||||||
|
$day = 1;
|
||||||
|
}
|
||||||
|
if (is_null($actualtimeshour)) {
|
||||||
|
$actualtimeshour = date('H', $s->timeend);
|
||||||
|
}
|
||||||
|
$s->timeend = mktime($actualtimeshour, 0, 0, date('m', $s->timeend), $day, date('Y', $s->timeend));
|
||||||
|
}
|
||||||
$stats[$statid] = $s;
|
$stats[$statid] = $s;
|
||||||
|
|
||||||
$actualtimes[] = $s->timeend;
|
$actualtimes[] = $s->timeend;
|
||||||
}
|
}
|
||||||
|
|
||||||
$timeafter = array_pop(array_values($actualtimes));
|
$actualtimesvalues = array_values($actualtimes);
|
||||||
|
$timeafter = array_pop($actualtimesvalues);
|
||||||
|
|
||||||
|
// Generate a base timestamp for each possible month/week/day.
|
||||||
|
$times = array();
|
||||||
while ($timeafter < $now) {
|
while ($timeafter < $now) {
|
||||||
$times[] = $timeafter;
|
$times[] = $timeafter;
|
||||||
if ($timestr == 'daily') {
|
if ($timestr == 'daily') {
|
||||||
|
@ -1399,12 +1425,25 @@ function stats_fix_zeros($stats,$timeafter,$timestr,$line2=true,$line3=false) {
|
||||||
} else if ($timestr == 'weekly') {
|
} else if ($timestr == 'weekly') {
|
||||||
$timeafter = stats_get_next_week_start($timeafter);
|
$timeafter = stats_get_next_week_start($timeafter);
|
||||||
} else if ($timestr == 'monthly') {
|
} else if ($timestr == 'monthly') {
|
||||||
$timeafter = stats_get_next_month_start($timeafter);
|
// We can't just simply +1 month because the 31st Jan + 1 month = 2nd of March.
|
||||||
|
$year = date('Y', $timeafter);
|
||||||
|
$month = date('m', $timeafter);
|
||||||
|
$day = date('d', $timeafter);
|
||||||
|
$dayofnextmonth = $day;
|
||||||
|
if ($day >= 29) {
|
||||||
|
$daysinmonth = date('n', mktime(0, 0, 0, $month+1, 1, $year));
|
||||||
|
if ($day > $daysinmonth) {
|
||||||
|
$dayofnextmonth = $daysinmonth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$timeafter = mktime($actualtimeshour, 0, 0, $month+1, $dayofnextmonth, $year);
|
||||||
} else {
|
} else {
|
||||||
return $stats; // this will put us in a never ending loop.
|
// This will put us in a never ending loop.
|
||||||
|
return $stats;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add the base timestamp to the statistics if not present.
|
||||||
foreach ($times as $count => $time) {
|
foreach ($times as $count => $time) {
|
||||||
if (!in_array($time,$actualtimes) && $count != count($times) -1) {
|
if (!in_array($time,$actualtimes) && $count != count($times) -1) {
|
||||||
$newobj = new StdClass;
|
$newobj = new StdClass;
|
||||||
|
@ -1425,7 +1464,6 @@ function stats_fix_zeros($stats,$timeafter,$timestr,$line2=true,$line3=false) {
|
||||||
|
|
||||||
usort($stats,"stats_compare_times");
|
usort($stats,"stats_compare_times");
|
||||||
return $stats;
|
return $stats;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to sort arrays by $obj->timeend
|
// helper function to sort arrays by $obj->timeend
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue