Permalink
Browse files

more fixing on reports

  • Loading branch information...
mjollnir_
mjollnir_ committed Sep 24, 2006
1 parent dcf9c14 commit 11887b6d5eb6c67d57d882cd6f0499c6a80474d2
Showing with 40 additions and 9 deletions.
  1. +18 −4 course/report/stats/graph.php
  2. +19 −5 course/report/stats/report.php
  3. +3 −0 lib/statslib.php
@@ -37,7 +37,7 @@
}
$sql = 'SELECT '.((empty($param->fieldscomplete)) ? 'id,roleid,timeend,' : '').$param->fields
- .' FROM '.$CFG->prefix.'stats_'.$param->table.' WHERE '
+ .' FROM '.$CFG->prefix.'stats_'.$param->table.'_tmp WHERE '
.(($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ')
.((!empty($userid)) ? ' userid = '.$userid.' AND ' : '')
.((!empty($roleid)) ? ' roleid = '.$roleid.' AND ' : '')
@@ -88,23 +88,37 @@
$data = array();
$times = array();
$roles = array();
+ $missedlines = array();
foreach ($stats as $stat) {
$data[$stat->roleid][$stat->timeend] = $stat->line1;
- if (!array_key_exists($stat->roleid,$roles)) {
- $roles[$stat->roleid] = get_field('role','name','id',$stat->roleid);
+ if (!empty($stat->zerofixed)) {
+ $missedlines[] = $stat->timeend;
+ }
+ if ($stat->roleid != 0) {
+ if (!array_key_exists($stat->roleid,$roles)) {
+ $roles[$stat->roleid] = get_field('role','name','id',$stat->roleid);
+ }
}
if (!array_key_exists($stat->timeend,$times)) {
$times[$stat->timeend] = userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone);
}
}
+ $nonzeroroleid = 0;
foreach (array_keys($data) as $roleid) {
+ if ($roleid == 0) {
+ continue;
+ }
$graph->y_order[] = $roleid;
$graph->y_format[$roleid] = array('colour' => $c[$roleid], 'line' => 'line','legend' => $roles[$roleid]);
+ $nonzeroroleid = $roleid;
}
- foreach (array_keys($data[$roleid]) as $time) {
+ foreach (array_keys($data[$nonzeroroleid]) as $time) {
$graph->x_data[] = $times[$time];
}
foreach ($data as $roleid => $t) {
+ if ($roleid == 0) {
+ continue;
+ }
foreach ($t as $time => $data) {
$graph->y_data[$roleid][] = $data;
}
@@ -41,7 +41,6 @@
WHERE u.id = ra.userid
AND ra.contextid '.get_related_contexts_string($context);
}
-
if (!$us = get_records_sql($sql)) {
error('Cannot enter detailed view: No users found for this course.');
}
@@ -103,15 +102,15 @@
$param->table = 'user_'.$param->table;
}
$sql = 'SELECT '.((empty($param->fieldscomplete)) ? 'id,roleid,timeend,' : '').$param->fields
- .' FROM '.$CFG->prefix.'stats_'.$param->table.' WHERE '
+ .' FROM '.$CFG->prefix.'stats_'.$param->table.'_tmp WHERE '
.(($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ')
.((!empty($userid)) ? ' userid = '.$userid.' AND ' : '')
.((!empty($roleid)) ? ' roleid = '.$roleid.' AND ' : '')
. ((!empty($param->stattype)) ? ' stattype = \''.$param->stattype.'\' AND ' : '')
.' timeend >= '.$param->timeafter
.' '.$param->extras
.' ORDER BY timeend DESC';
- error_log($sql);
+
$stats = get_records_sql($sql);
if (empty($stats)) {
@@ -163,16 +162,31 @@
$data = array();
$roles = array();
$times = array();
+ $missedlines = array();
foreach ($stats as $stat) {
+ if (!empty($stat->zerofixed)) {
+ $missedlines[] = $stat->timeend;
+ }
$data[$stat->timeend][$stat->roleid] = $stat->line1;
- if (!array_key_exists($stat->roleid,$roles)) {
- $roles[$stat->roleid] = get_field('role','name','id',$stat->roleid);
+ if ($stat->roleid != 0) {
+ if (!array_key_exists($stat->roleid,$roles)) {
+ $roles[$stat->roleid] = get_field('role','name','id',$stat->roleid);
+ }
}
if (!array_key_exists($stat->timeend,$times)) {
$times[$stat->timeend] = userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone);
}
}
foreach ($data as $time => $rolesdata) {
+ if (in_array($time,$missedlines)) {
+ $rolesdata = array();
+ foreach ($roles as $roleid => $guff) {
+ if ($roleid == 0 ) {
+ continue;
+ }
+ $rolesdata[$roleid] = 0;
+ }
+ }
krsort($rolesdata);
$row = array_merge(array($times[$time]),$rolesdata);
if (empty($CFG->loglifetime) || ($stat->timeend-(60*60*24)) >= (time()-60*60*24*$CFG->loglifetime)) {
View
@@ -963,6 +963,7 @@ function stats_fix_zeros($stats,$timeafter,$timestr,$line2=true,$line3=false) {
foreach ($stats as $s) {
$actualtimes[] = $s->timeend;
}
+
$timeafter = array_pop($actualtimes);
while ($timeafter < $now) {
@@ -983,13 +984,15 @@ function stats_fix_zeros($stats,$timeafter,$timestr,$line2=true,$line3=false) {
$newobj = new StdClass;
$newobj->timeend = $time;
$newobj->id = 0;
+ $newobj->roleid = 0;
$newobj->line1 = 0;
if (!empty($line2)) {
$newobj->line2 = 0;
}
if (!empty($line3)) {
$newobj->line3 = 0;
}
+ $newobj->zerofixed = true;
$stats[] = $newobj;
}
}

0 comments on commit 11887b6

Please sign in to comment.