fixing reports

This commit is contained in:
mjollnir_ 2006-09-23 12:10:42 +00:00
parent 0dd5bf422b
commit afc97d5349
3 changed files with 32 additions and 34 deletions

View File

@ -43,11 +43,9 @@
.((!empty($roleid)) ? ' roleid = '.$roleid.' AND ' : '') .((!empty($roleid)) ? ' roleid = '.$roleid.' AND ' : '')
. ((!empty($param->stattype)) ? ' stattype = \''.$param->stattype.'\' AND ' : '') . ((!empty($param->stattype)) ? ' stattype = \''.$param->stattype.'\' AND ' : '')
.' timeend >= '.$param->timeafter .' timeend >= '.$param->timeafter
.$param->extras .' '.$param->extras
.' ORDER BY timeend DESC'; .' ORDER BY timeend DESC';
error_log($sql);
$stats = get_records_sql($sql); $stats = get_records_sql($sql);
$stats = stats_fix_zeros($stats,$param->timeafter,$param->table,(!empty($param->line2)),(!empty($param->line3))); $stats = stats_fix_zeros($stats,$param->timeafter,$param->table,(!empty($param->line2)),(!empty($param->line3)));
@ -87,6 +85,7 @@ error_log($sql);
$graph->y_format['line3'] = array('colour' => $c[3],'line' => 'line','legend' => $param->line3); $graph->y_format['line3'] = array('colour' => $c[3],'line' => 'line','legend' => $param->line3);
} }
} else { } else {
$data = array();
$times = array(); $times = array();
$roles = array(); $roles = array();
foreach ($stats as $stat) { foreach ($stats as $stat) {
@ -98,7 +97,6 @@ error_log($sql);
$times[$stat->timeend] = userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone); $times[$stat->timeend] = userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone);
} }
} }
foreach (array_keys($data) as $roleid) { foreach (array_keys($data) as $roleid) {
$graph->y_order[] = $roleid; $graph->y_order[] = $roleid;
$graph->y_format[$roleid] = array('colour' => $c[$roleid], 'line' => 'line','legend' => $roles[$roleid]); $graph->y_format[$roleid] = array('colour' => $c[$roleid], 'line' => 'line','legend' => $roles[$roleid]);

View File

@ -13,6 +13,7 @@
$time = optional_param('time', 0, PARAM_INT); $time = optional_param('time', 0, PARAM_INT);
$mode = optional_param('mode', STATS_MODE_GENERAL, PARAM_INT); $mode = optional_param('mode', STATS_MODE_GENERAL, PARAM_INT);
$userid = optional_param('userid', 0, PARAM_INT); $userid = optional_param('userid', 0, PARAM_INT);
$roleid = 0;
if ($report > 50) { if ($report > 50) {
$roleid = substr($report,1); $roleid = substr($report,1);

View File

@ -109,8 +109,9 @@
.((!empty($roleid)) ? ' roleid = '.$roleid.' AND ' : '') .((!empty($roleid)) ? ' roleid = '.$roleid.' AND ' : '')
. ((!empty($param->stattype)) ? ' stattype = \''.$param->stattype.'\' AND ' : '') . ((!empty($param->stattype)) ? ' stattype = \''.$param->stattype.'\' AND ' : '')
.' timeend >= '.$param->timeafter .' timeend >= '.$param->timeafter
.$param->extras .' '.$param->extras
.' ORDER BY timeend DESC'; .' ORDER BY timeend DESC';
error_log($sql);
$stats = get_records_sql($sql); $stats = get_records_sql($sql);
if (empty($stats)) { if (empty($stats)) {
@ -144,13 +145,8 @@
$table->head[] = $param->line2; $table->head[] = $param->line2;
} }
} }
$lasttime = null; // used for crosstab
$lastrecord = null;
$lastlink = null;
$headerdone = false;
foreach ($stats as $stat) {
if (empty($param->crosstab)) { if (empty($param->crosstab)) {
foreach ($stats as $stat) {
$a = array(userdate($stat->timeend-(60*60*24),get_string('strftimedate'),$CFG->timezone),$stat->line1); $a = array(userdate($stat->timeend-(60*60*24),get_string('strftimedate'),$CFG->timezone),$stat->line1);
if (isset($stat->line2)) { if (isset($stat->line2)) {
$a[] = $stat->line2; $a[] = $stat->line2;
@ -162,30 +158,33 @@
.get_string('course').' ' .get_string('logs').'</a>&nbsp;'; .get_string('course').' ' .get_string('logs').'</a>&nbsp;';
} }
$table->data[] = $a; $table->data[] = $a;
} else {
if ($stat->timeend == $lasttime) {
$lastrecord[] = $stat->line1;
if (empty($headerdone)) {
$table->head[] = get_field('role','name','id',$stat->roleid);
} }
} else { } else {
if (!empty($lastrecord)) { // we won't have one if this is the first time round... $data = array();
$lastrecord[] = $lastlink; $roles = array();
$table->data[] = $lastrecord; $times = array();
$headerdone = true; foreach ($stats as $stat) {
} else { $data[$stat->timeend][$stat->roleid] = $stat->line1;
$table->head[] = get_field('role','name','id',$stat->roleid); if (!array_key_exists($stat->roleid,$roles)) {
$roles[$stat->roleid] = get_field('role','name','id',$stat->roleid);
} }
$lastrecord = array(userdate($stat->timeend-(60*60*24),get_string('strftimedate'),$CFG->timezone),$stat->line1); if (!array_key_exists($stat->timeend,$times)) {
$times[$stat->timeend] = userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone);
}
}
foreach ($data as $time => $rolesdata) {
krsort($rolesdata);
$row = array_merge(array($times[$time]),$rolesdata);
if (empty($CFG->loglifetime) || ($stat->timeend-(60*60*24)) >= (time()-60*60*24*$CFG->loglifetime)) { if (empty($CFG->loglifetime) || ($stat->timeend-(60*60*24)) >= (time()-60*60*24*$CFG->loglifetime)) {
$lastlink = '<a href="'.$CFG->wwwroot.'/course/report/log/index.php?id=' $row[] = '<a href="'.$CFG->wwwroot.'/course/report/log/index.php?id='
.$course->id.'&chooselog=1&showusers=1&showcourses=1&user='.$userid .$course->id.'&chooselog=1&showusers=1&showcourses=1&user='.$userid
.'&date='.usergetmidnight($stat->timeend-(60*60*24)).'">' .'&date='.usergetmidnight($time-(60*60*24)).'">'
.get_string('course').' ' .get_string('logs').'</a>&nbsp;'; .get_string('course').' ' .get_string('logs').'</a>&nbsp;';
} }
$lasttime = $stat->timeend; $table->data[] = $row;
}
} }
krsort($roles);
$table->head = array_merge($table->head,$roles);
} }
$table->head[] = get_string('logs'); $table->head[] = get_string('logs');
if (!empty($lastrecord)) { if (!empty($lastrecord)) {