Permalink
Browse files

lots of fixes to stats, more to come

  • Loading branch information...
1 parent c1ddeca commit 0f259f63d950fecf255c0f95a85a42a350e05c50 mjollnir_ committed Sep 23, 2006
@@ -9,6 +9,7 @@
$time = required_param('time', PARAM_INT);
$mode = required_param('mode', PARAM_INT);
$userid = optional_param('userid', 0, PARAM_INT);
+ $roleid = optional_param('roleid',0,PARAM_INT);
if (!$course = get_record("course","id",$courseid)) {
error("That's an invalid course id");
@@ -35,14 +36,18 @@
$param->table = 'user_'.$param->table;
}
- $sql = 'SELECT timeend,'.$param->fields.' FROM '.$CFG->prefix.'stats_'.$param->table.' WHERE '
- . (($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ')
- . ((!empty($userid)) ? ' userid = '.$userid.' AND ' : '')
+ $sql = 'SELECT '.((empty($param->fieldscomplete)) ? 'id,roleid,timeend,' : '').$param->fields
+ .' 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';
-
+ .$param->extras
+ .' ORDER BY timeend DESC';
+
+error_log($sql);
+
$stats = get_records_sql($sql);
$stats = stats_fix_zeros($stats,$param->timeafter,$param->table,(!empty($param->line2)),(!empty($param->line3)));
@@ -57,26 +62,55 @@
$graph->parameter['title'] = false; // moodle will do a nicer job.
$graph->y_tick_labels = null;
- foreach ($stats as $stat) {
- $graph->x_data[] = userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone);
- $graph->y_data['line1'][] = $stat->line1;
- if (isset($stat->line2)) {
- $graph->y_data['line2'][] = $stat->line2;
+ $c = array_keys($graph->colour);
+
+ if (empty($param->crosstab)) {
+ foreach ($stats as $stat) {
+ $graph->x_data[] = userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone);
+ $graph->y_data['line1'][] = $stat->line1;
+ if (isset($stat->line2)) {
+ $graph->y_data['line2'][] = $stat->line2;
+ }
+ if (isset($stat->line3)) {
+ $graph->y_data['line3'][] = $stat->line3;
+ }
}
- if (isset($stat->line3)) {
- $graph->y_data['line3'][] = $stat->line3;
+ $graph->y_order = array('line1','line2');
+ if (!empty($param->line3)) {
+ $graph->y_order[] = 'line3';
+ }
+ $graph->y_format['line1'] = array('colour' => $c[1],'line' => 'line','legend' => $param->line1);
+ if (!empty($param->line2)) {
+ $graph->y_format['line2'] = array('colour' => $c[2],'line' => 'line','legend' => $param->line2);
+ }
+ if (!empty($param->line3)) {
+ $graph->y_format['line3'] = array('colour' => $c[3],'line' => 'line','legend' => $param->line3);
+ }
+ } else {
+ $times = array();
+ $roles = 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 (!array_key_exists($stat->timeend,$times)) {
+ $times[$stat->timeend] = userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone);
+ }
+ }
+
+ foreach (array_keys($data) as $roleid) {
+ $graph->y_order[] = $roleid;
+ $graph->y_format[$roleid] = array('colour' => $c[$roleid], 'line' => 'line','legend' => $roles[$roleid]);
+ }
+ foreach (array_keys($data[$roleid]) as $time) {
+ $graph->x_data[] = $times[$time];
+ }
+ foreach ($data as $roleid => $t) {
+ foreach ($t as $time => $data) {
+ $graph->y_data[$roleid][] = $data;
+ }
}
- }
- $graph->y_order = array('line1','line2');
- if (!empty($param->line3)) {
- $graph->y_order[] = 'line3';
- }
- $graph->y_format['line1'] = array('colour' => 'blue','line' => 'line','legend' => $param->line1);
- if (!empty($param->line2)) {
- $graph->y_format['line2'] = array('colour' => 'red','line' => 'line','legend' => $param->line2);
- }
- if (!empty($param->line3)) {
- $graph->y_format['line3'] = array('colour' => 'black','line' => 'line','legend' => $param->line3);
}
$graph->draw_stack();
@@ -14,6 +14,11 @@
$mode = optional_param('mode', STATS_MODE_GENERAL, PARAM_INT);
$userid = optional_param('userid', 0, PARAM_INT);
+ if ($report > 50) {
+ $roleid = substr($report,1);
+ $report = 5;
+ }
+
if ($report == STATS_REPORT_USER_LOGINS) {
$courseid = SITEID; //override
}
@@ -10,13 +10,13 @@
function report_stats_mode_menu($course, $mode, $time) {
global $CFG;
-
+ /*
$reportoptions = stats_get_report_options($course->id, $mode);
$timeoptions = report_stats_timeoptions($mode);
-
if (empty($timeoptions)) {
error(get_string('nostatstodisplay'), $CFG->wwwroot.'/course/view.php?id='.$course->id);
}
+ */
$options = array();
$options[STATS_MODE_GENERAL] = get_string('statsmodegeneral');
@@ -1,7 +1,5 @@
<?php
- // all queries on teacher table will break (i mean already broken)
-
$courses = get_courses('all','c.shortname','c.id,c.shortname,c.fullname');
$courseoptions = array();
@@ -19,6 +17,10 @@
$reportoptions = stats_get_report_options($course->id, $mode);
$timeoptions = report_stats_timeoptions($mode);
+ if (empty($timeoptions)) {
+ error(get_string('nostatstodisplay'), $CFG->wwwroot.'/course/view.php?id='.$course->id);
+ }
+
$table->width = '*';
if ($mode == STATS_MODE_DETAILED) {
@@ -76,13 +78,13 @@
$table->align = array('left','left','left','left','left','left','left','left');
$table->data[] = array(get_string('course'),choose_from_menu($courseoptions,'course',$course->id,'','','',true),
get_string('users'),choose_from_menu($users,'userid',$userid,'','','',true),
- get_string('statsreporttype'),choose_from_menu($reportoptions,'report',$report,'','','',true),
+ get_string('statsreporttype'),choose_from_menu($reportoptions,'report',($report == 5) ? $report.$roleid : $report,'','','',true),
get_string('statstimeperiod'),choose_from_menu($timeoptions,'time',$time,'','','',true),
'<input type="submit" value="'.get_string('view').'" />') ;
} else {
$table->align = array('left','left','left','left','left','left','left');
$table->data[] = array(get_string('course'),choose_from_menu($courseoptions,'course',$course->id,'','','',true),
- get_string('statsreporttype'),choose_from_menu($reportoptions,'report',$report,'','','',true),
+ get_string('statsreporttype'),choose_from_menu($reportoptions,'report',($report == 5) ? $report.$roleid : $report,'','','',true),
get_string('statstimeperiod'),choose_from_menu($timeoptions,'time',$time,'','','',true),
'<input type="submit" value="'.get_string('view').'" />') ;
}
@@ -96,55 +98,99 @@
error("This type of report is only available for the site course");
}
$param = stats_get_parameters($time,$report,$course->id,$mode);
+
if ($mode == STATS_MODE_DETAILED) {
$param->table = 'user_'.$param->table;
}
- $sql = 'SELECT timeend,'.$param->fields.' FROM '.$CFG->prefix.'stats_'.$param->table.' WHERE '
+ $sql = 'SELECT '.((empty($param->fieldscomplete)) ? 'id,roleid,timeend,' : '').$param->fields
+ .' 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';
-
$stats = get_records_sql($sql);
if (empty($stats)) {
error(get_string('statsnodata'.((!empty($user)) ? 'user' : '')),$CFG->wwwroot.'/stats/index.php?course='.$course->id.'&mode='.$mode.'&time='.$time);
}
-
+
$stats = stats_fix_zeros($stats,$param->timeafter,$param->table,(!empty($param->line2)));
- print_heading($course->shortname.' - '.get_string('statsreport'.$report).((!empty($user)) ? ' '.get_string('statsreportforuser').' ' .fullname($user,true) : ''));
+ print_heading($course->shortname.' - '.get_string('statsreport'.$report)
+ .((!empty($user)) ? ' '.get_string('statsreportforuser').' ' .fullname($user,true) : '')
+ .((!empty($roleid)) ? ' '.get_field('role','name','id',$roleid) : ''));
+
if (empty($CFG->gdversion)) {
echo "(".get_string("gdneed").")";
} else {
if ($mode == STATS_MODE_DETAILED) {
echo '<center><img src="'.$CFG->wwwroot.'/course/report/stats/graph.php?mode='.$mode.'&course='.$course->id.'&time='.$time.'&report='.$report.'&userid='.$userid.'" /></center>';
} else {
- echo '<center><img src="'.$CFG->wwwroot.'/course/report/stats/graph.php?mode='.$mode.'&course='.$course->id.'&time='.$time.'&report='.$report.'" /></center>';
+ echo '<center><img src="'.$CFG->wwwroot.'/course/report/stats/graph.php?mode='.$mode.'&course='.$course->id.'&time='.$time.'&report='.$report.'&roleid='.$roleid.'" /></center>';
}
}
- $table = new object();
+ $table = new StdClass;
$table->align = array('left','center','center','center');
$param->table = str_replace('user_','',$param->table);
- $table->head = array(get_string('periodending','moodle',$param->table),$param->line1);
- if (!empty($param->line2)) {
- $table->head[] = $param->line2;
+ $table->head = array(get_string('periodending','moodle',$param->table));
+ if (empty($param->crosstab)) {
+ $table->head[] = $param->line1;
+ if (!empty($param->line2)) {
+ $table->head[] = $param->line2;
+ }
}
- $table->head[] = get_string('logs');
-
+ $lasttime = null; // used for crosstab
+ $lastrecord = null;
+ $lastlink = null;
+ $headerdone = false;
+
foreach ($stats as $stat) {
- $a = array(userdate($stat->timeend-(60*60*24),get_string('strftimedate'),$CFG->timezone),$stat->line1);
- if (isset($stat->line2)) {
- $a[] = $stat->line2;
- }
- if (empty($CFG->loglifetime) || ($stat->timeend-(60*60*24)) >= (time()-60*60*24*$CFG->loglifetime)) {
- $a[] = '<a href="'.$CFG->wwwroot.'/course/report/log/index.php?id='.$course->id.'&chooselog=1&showusers=1&showcourses=1&user='.$userid.'&date='.usergetmidnight($stat->timeend-(60*60*24)).'">'.get_string('course').' ' .get_string('logs').'</a>&nbsp;';
+ if (empty($param->crosstab)) {
+ $a = array(userdate($stat->timeend-(60*60*24),get_string('strftimedate'),$CFG->timezone),$stat->line1);
+ if (isset($stat->line2)) {
+ $a[] = $stat->line2;
+ }
+ if (empty($CFG->loglifetime) || ($stat->timeend-(60*60*24)) >= (time()-60*60*24*$CFG->loglifetime)) {
+ $a[] = '<a href="'.$CFG->wwwroot.'/course/report/log/index.php?id='.
+ $course->id.'&chooselog=1&showusers=1&showcourses=1&user='
+ .$userid.'&date='.usergetmidnight($stat->timeend-(60*60*24)).'">'
+ .get_string('course').' ' .get_string('logs').'</a>&nbsp;';
+ }
+ $table->data[] = $a;
+ } else {
+ if ($stat->timeend == $lasttime) {
+ $lastrecord[] = $stat->line1;
+ if (empty($headerdone)) {
+ $table->head[] = get_field('role','name','id',$stat->roleid);
+ }
+ } else {
+ if (!empty($lastrecord)) { // we won't have one if this is the first time round...
+ $lastrecord[] = $lastlink;
+ $table->data[] = $lastrecord;
+ $headerdone = true;
+ } else {
+ $table->head[] = get_field('role','name','id',$stat->roleid);
+ }
+ $lastrecord = array(userdate($stat->timeend-(60*60*24),get_string('strftimedate'),$CFG->timezone),$stat->line1);
+ 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='
+ .$course->id.'&chooselog=1&showusers=1&showcourses=1&user='.$userid
+ .'&date='.usergetmidnight($stat->timeend-(60*60*24)).'">'
+ .get_string('course').' ' .get_string('logs').'</a>&nbsp;';
+ }
+ $lasttime = $stat->timeend;
+ }
}
- $table->data[] = $a;
+ }
+ $table->head[] = get_string('logs');
+ if (!empty($lastrecord)) {
+ $lastrecord[] = $lastlink;
+ $table->data[] = $lastrecord;
}
print_table($table);
}
@@ -1220,18 +1220,18 @@
$string['statsnodata'] = 'There is no available data for that combination of course and time period.';
$string['statsnodatauser'] = 'There is no available data for that combination of course, user and time period.';
$string['statsoff'] = 'Statistics is not currently enabled';
+$string['statsreads'] = 'Views';
+$string['statswrites'] = 'Posts';
$string['statsreportlogins'] = 'Logins';
-$string['statsreportreads'] = 'Views (teacher and student)';
-$string['statsreportwrites'] = 'Posts (teacher and student)';
-$string['statsreportactivity'] = 'All activity (teacher and student)';
-$string['statsreportstudentactivity'] = 'All student activity (views and posts)';
-$string['statsreportteacheractivity'] = 'All teacher activity (views and posts)';
+$string['statsreportreads'] = 'Views (all roles)';
+$string['statsreportwrites'] = 'Posts (all roles)';
+$string['statsreportactivity'] = 'All activity (all roles)';
+$string['statsreportactivitybyrole'] = 'All activity (views and posts)';
$string['statsreport1'] = 'Logins';
-$string['statsreport2'] = 'Views (teacher and student)';
-$string['statsreport3'] = 'Posts (teacher and student)';
-$string['statsreport4'] = 'All activity (teacher and student)';
-$string['statsreport5'] = 'All student activity (views and posts)';
-$string['statsreport6'] = 'All teacher activity (views and posts)';
+$string['statsreport2'] = 'Views (all roles)';
+$string['statsreport3'] = 'Posts (all roles)';
+$string['statsreport4'] = 'All activity (all roles)';
+$string['statsreport5'] = 'All activity (views and posts)';
$string['statsreport7'] = 'User activity (views and posts)';
$string['statsreport8'] = 'All User activity';
$string['statsreport9'] = 'Logins (site course)';
Oops, something went wrong.

0 comments on commit 0f259f6

Please sign in to comment.