Skip to content
Browse files

Revert "MDL-36380 stats: No more duplicated entries when viewing mont…

…hly stats"

This reverts commit 33b5464.
  • Loading branch information...
1 parent 349a6fd commit b1703e2951373aadf403b52992ceaec618dc8515 @danpoltawski danpoltawski committed Feb 20, 2013
Showing with 11 additions and 42 deletions.
  1. +11 −42 lib/statslib.php
View
53 lib/statslib.php
@@ -1442,75 +1442,43 @@ function stats_get_report_options($courseid,$mode) {
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) {
if (empty($stats)) {
return;
}
$timestr = str_replace('user_','',$timestr); // just in case.
-
- // Gets the current user base time.
$fun = 'stats_get_base_'.$timestr;
+
$now = $fun();
- // Extract the ending time of the statistics.
+ $times = array();
+ // add something to timeafter since it is our absolute base
$actualtimes = array();
- foreach ($stats as $statid => $s) {
- // 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.
- if ($timestr == 'monthly' && date('d', $s->timeend) > 1 && date('d', $s->timeend) < 29) {
- $s->timeend = mktime(date('H', $s->timeend), date('i', $s->timeend), date('s', $s->timeend),
- date('m', $s->timeend), 1, date('Y', $s->timeend));
- }
+ foreach ($stats as $statid=>$s) {
+ //normalize the times in stats - those might have been created in different timezone, DST etc.
+ $s->timeend = $fun($s->timeend + 60*60*5);
$stats[$statid] = $s;
+
$actualtimes[] = $s->timeend;
}
- $actualtimesvalues = array_values($actualtimes);
- $timeafter = array_pop($actualtimesvalues);
+ $timeafter = array_pop(array_values($actualtimes));
- // Generate a base timestamp for each possible month/week/day.
- $times = array();
while ($timeafter < $now) {
$times[] = $timeafter;
if ($timestr == 'daily') {
$timeafter = stats_get_next_day_start($timeafter);
} else if ($timestr == 'weekly') {
$timeafter = stats_get_next_week_start($timeafter);
} else if ($timestr == 'monthly') {
- // 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(date('H', $timeafter), date('i', $timeafter), date('s', $timeafter), $month+1,
- $dayofnextmonth, $year);
+ $timeafter = stats_get_next_month_start($timeafter);
} else {
- // This will put us in a never ending loop.
- return $stats;
+ return $stats; // this will put us in a never ending loop.
}
}
- // Add the base timestamp to the statistics if not present.
foreach ($times as $count => $time) {
if (!in_array($time,$actualtimes) && $count != count($times) -1) {
$newobj = new StdClass;
@@ -1531,6 +1499,7 @@ function stats_fix_zeros($stats,$timeafter,$timestr,$line2=true,$line3=false) {
usort($stats,"stats_compare_times");
return $stats;
+
}
// helper function to sort arrays by $obj->timeend

0 comments on commit b1703e2

Please sign in to comment.
Something went wrong with that request. Please try again.