2006-04-20 22:36:22 +00:00
|
|
|
<?php //$Id$
|
2005-09-01 04:14:31 +00:00
|
|
|
|
2006-04-20 22:36:22 +00:00
|
|
|
require_once('../../../config.php');
|
2005-09-01 04:14:31 +00:00
|
|
|
require_once($CFG->dirroot.'/lib/statslib.php');
|
|
|
|
require_once($CFG->dirroot.'/lib/graphlib.php');
|
|
|
|
|
2006-04-20 22:36:22 +00:00
|
|
|
$courseid = required_param('course', PARAM_INT);
|
|
|
|
$report = required_param('report', PARAM_INT);
|
|
|
|
$time = required_param('time', PARAM_INT);
|
|
|
|
$mode = required_param('mode', PARAM_INT);
|
|
|
|
$userid = optional_param('userid', 0, PARAM_INT);
|
2006-09-23 08:52:12 +00:00
|
|
|
$roleid = optional_param('roleid',0,PARAM_INT);
|
2005-09-01 04:14:31 +00:00
|
|
|
|
2008-05-31 14:35:58 +00:00
|
|
|
if (!$course = $DB->get_record("course", array("id"=>$courseid))) {
|
2008-05-13 06:15:20 +00:00
|
|
|
print_error("invalidcourseid");
|
2005-09-01 04:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($userid)) {
|
2008-05-31 14:35:58 +00:00
|
|
|
if (!$user = $DB->get_record('user', array('id'=>$userid))) {
|
2008-05-13 06:15:20 +00:00
|
|
|
print_error("nousers");
|
2005-09-01 04:14:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-29 14:22:10 +00:00
|
|
|
require_login($course);
|
2006-08-25 08:27:28 +00:00
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
2008-02-23 12:26:35 +00:00
|
|
|
|
2008-11-30 12:04:27 +00:00
|
|
|
if (!$course->showreports or $USER->id != $userid) {
|
|
|
|
require_capability('coursereport/stats:view', $context);
|
|
|
|
}
|
2005-09-01 04:14:31 +00:00
|
|
|
|
2005-09-28 06:07:40 +00:00
|
|
|
stats_check_uptodate($course->id);
|
|
|
|
|
2005-10-16 20:55:40 +00:00
|
|
|
$param = stats_get_parameters($time,$report,$course->id,$mode);
|
2005-09-01 04:14:31 +00:00
|
|
|
|
|
|
|
if (!empty($userid)) {
|
|
|
|
$param->table = 'user_'.$param->table;
|
|
|
|
}
|
|
|
|
|
2008-05-31 14:35:58 +00:00
|
|
|
// TODO: cleanup this ugly mess!
|
2006-09-23 08:52:12 +00:00
|
|
|
$sql = 'SELECT '.((empty($param->fieldscomplete)) ? 'id,roleid,timeend,' : '').$param->fields
|
2008-06-05 20:35:28 +00:00
|
|
|
.' FROM {stats_'.$param->table.'} WHERE '
|
2006-09-23 08:52:12 +00:00
|
|
|
.(($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ')
|
|
|
|
.((!empty($userid)) ? ' userid = '.$userid.' AND ' : '')
|
|
|
|
.((!empty($roleid)) ? ' roleid = '.$roleid.' AND ' : '')
|
2005-10-13 03:16:11 +00:00
|
|
|
. ((!empty($param->stattype)) ? ' stattype = \''.$param->stattype.'\' AND ' : '')
|
|
|
|
.' timeend >= '.$param->timeafter
|
2006-09-23 12:10:42 +00:00
|
|
|
.' '.$param->extras
|
2006-09-23 08:52:12 +00:00
|
|
|
.' ORDER BY timeend DESC';
|
|
|
|
|
2008-05-31 14:35:58 +00:00
|
|
|
$stats = $DB->get_records_sql($sql, $param->params);
|
2005-09-01 04:14:31 +00:00
|
|
|
|
|
|
|
$stats = stats_fix_zeros($stats,$param->timeafter,$param->table,(!empty($param->line2)),(!empty($param->line3)));
|
|
|
|
|
2005-10-16 20:55:40 +00:00
|
|
|
$stats = array_reverse($stats);
|
2005-09-01 04:14:31 +00:00
|
|
|
|
|
|
|
$graph = new graph(750,400);
|
|
|
|
|
|
|
|
$graph->parameter['legend'] = 'outside-right';
|
|
|
|
$graph->parameter['legend_size'] = 10;
|
|
|
|
$graph->parameter['x_axis_angle'] = 90;
|
|
|
|
$graph->parameter['title'] = false; // moodle will do a nicer job.
|
2006-04-20 22:36:22 +00:00
|
|
|
$graph->y_tick_labels = null;
|
2005-09-01 04:14:31 +00:00
|
|
|
|
2006-09-23 08:52:12 +00:00
|
|
|
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;
|
|
|
|
}
|
2005-09-01 04:14:31 +00:00
|
|
|
}
|
2007-02-28 00:32:39 +00:00
|
|
|
$graph->y_order = array('line1');
|
2008-02-16 18:33:50 +00:00
|
|
|
$graph->y_format['line1'] = array('colour' => 'blue','line' => 'line','legend' => $param->line1);
|
2006-09-23 08:52:12 +00:00
|
|
|
if (!empty($param->line2)) {
|
2007-02-28 00:32:39 +00:00
|
|
|
$graph->y_order[] = 'line2';
|
2008-02-23 12:26:35 +00:00
|
|
|
$graph->y_format['line2'] = array('colour' => 'green','line' => 'line','legend' => $param->line2);
|
2006-09-23 08:52:12 +00:00
|
|
|
}
|
|
|
|
if (!empty($param->line3)) {
|
2007-02-28 00:32:39 +00:00
|
|
|
$graph->y_order[] = 'line3';
|
2008-02-23 12:26:35 +00:00
|
|
|
$graph->y_format['line3'] = array('colour' => 'red','line' => 'line','legend' => $param->line3);
|
2006-09-23 08:52:12 +00:00
|
|
|
}
|
2007-02-28 00:32:39 +00:00
|
|
|
$graph->y_tick_labels = false;
|
2008-02-16 18:33:50 +00:00
|
|
|
|
2006-09-23 08:52:12 +00:00
|
|
|
} else {
|
2006-09-23 12:10:42 +00:00
|
|
|
$data = array();
|
2006-09-23 08:52:12 +00:00
|
|
|
$times = array();
|
|
|
|
$roles = array();
|
2006-09-24 03:15:52 +00:00
|
|
|
$missedlines = array();
|
2008-02-23 12:26:35 +00:00
|
|
|
$rolenames = get_all_roles();
|
|
|
|
foreach ($rolenames as $r) {
|
|
|
|
$rolenames[$r->id] = $r->name;
|
|
|
|
}
|
|
|
|
$rolenames = role_fix_names($rolenames, get_context_instance(CONTEXT_COURSE, $course->id));
|
2006-09-23 08:52:12 +00:00
|
|
|
foreach ($stats as $stat) {
|
|
|
|
$data[$stat->roleid][$stat->timeend] = $stat->line1;
|
2006-09-24 03:15:52 +00:00
|
|
|
if (!empty($stat->zerofixed)) {
|
|
|
|
$missedlines[] = $stat->timeend;
|
|
|
|
}
|
|
|
|
if ($stat->roleid != 0) {
|
|
|
|
if (!array_key_exists($stat->roleid,$roles)) {
|
2008-02-23 12:26:35 +00:00
|
|
|
$roles[$stat->roleid] = $rolenames[$stat->roleid];
|
2006-09-24 03:15:52 +00:00
|
|
|
}
|
2008-02-16 18:33:50 +00:00
|
|
|
} else {
|
|
|
|
if (!array_key_exists($stat->roleid,$roles)) {
|
|
|
|
$roles[$stat->roleid] = get_string('all');
|
|
|
|
}
|
2006-09-23 08:52:12 +00:00
|
|
|
}
|
|
|
|
if (!array_key_exists($stat->timeend,$times)) {
|
|
|
|
$times[$stat->timeend] = userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone);
|
|
|
|
}
|
|
|
|
}
|
2007-04-11 23:53:15 +00:00
|
|
|
foreach (array_keys($times) as $t) {
|
|
|
|
foreach ($data as $roleid => $stuff) {
|
|
|
|
if (!array_key_exists($t, $stuff)) {
|
|
|
|
$data[$roleid][$t] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-02-16 18:33:50 +00:00
|
|
|
|
|
|
|
$roleid = 0;
|
|
|
|
krsort($roles); // the same sorting as in table bellow graph
|
|
|
|
|
|
|
|
$colors = array('green', 'blue', 'red', 'purple', 'yellow', 'olive', 'navy', 'maroon', 'gray', 'ltred', 'ltltred', 'ltgreen', 'ltltgreen', 'orange', 'ltorange', 'ltltorange', 'lime', 'ltblue', 'ltltblue', 'fuchsia', 'aqua', 'grayF0', 'grayEE', 'grayDD', 'grayCC', 'gray33', 'gray66', 'gray99');
|
|
|
|
$colorindex = 0;
|
|
|
|
|
|
|
|
foreach ($roles as $roleid=>$rname) {
|
|
|
|
ksort($data[$roleid]);
|
|
|
|
$graph->y_order[] = $roleid+1;
|
|
|
|
if ($roleid) {
|
|
|
|
$color = $colors[$colorindex++];
|
|
|
|
$colorindex = $colorindex % count($colors);
|
|
|
|
} else {
|
|
|
|
$color = 'black';
|
2006-09-24 03:15:52 +00:00
|
|
|
}
|
2008-02-16 18:33:50 +00:00
|
|
|
$graph->y_format[$roleid+1] = array('colour' => $color, 'line' => 'line','legend' => $rname);
|
2006-09-23 08:52:12 +00:00
|
|
|
}
|
2008-02-16 18:33:50 +00:00
|
|
|
foreach (array_keys($data[$roleid]) as $time) {
|
2006-09-23 08:52:12 +00:00
|
|
|
$graph->x_data[] = $times[$time];
|
|
|
|
}
|
|
|
|
foreach ($data as $roleid => $t) {
|
|
|
|
foreach ($t as $time => $data) {
|
2008-02-16 18:33:50 +00:00
|
|
|
$graph->y_data[$roleid+1][] = $data;
|
2006-09-23 08:52:12 +00:00
|
|
|
}
|
2005-09-01 04:14:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$graph->draw_stack();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
?>
|