1
<?php //$Id: graph.php,v 1.9.6.2 2007/04/11 23:59:11 mjollnir_ Exp $
1
<?php //$Id: graph.php,v 1.11.2.4 2008/11/30 12:05:04 skodak Exp $
3
3
require_once('../../../config.php');
4
4
require_once($CFG->dirroot.'/lib/statslib.php');
24
require_login($course);
25
25
$context = get_context_instance(CONTEXT_COURSE, $course->id);
27
if (!has_capability('moodle/site:viewreports', $context)) {
28
error('You need do not have the required permission to view reports for this course');
27
if (!$course->showreports or $USER->id != $userid) {
28
require_capability('coursereport/stats:view', $context);
31
31
stats_check_uptodate($course->id);
60
60
$graph->parameter['title'] = false; // moodle will do a nicer job.
61
61
$graph->y_tick_labels = null;
63
$c = array_keys($graph->colour);
65
63
if (empty($param->crosstab)) {
66
64
foreach ($stats as $stat) {
67
65
$graph->x_data[] = userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone);
76
74
$graph->y_order = array('line1');
77
$graph->y_format['line1'] = array('colour' => $c[1],'line' => 'line','legend' => $param->line1);
75
$graph->y_format['line1'] = array('colour' => 'blue','line' => 'line','legend' => $param->line1);
78
76
if (!empty($param->line2)) {
79
77
$graph->y_order[] = 'line2';
80
$graph->y_format['line2'] = array('colour' => $c[2],'line' => 'line','legend' => $param->line2);
78
$graph->y_format['line2'] = array('colour' => 'green','line' => 'line','legend' => $param->line2);
82
80
if (!empty($param->line3)) {
83
81
$graph->y_order[] = 'line3';
84
$graph->y_format['line3'] = array('colour' => $c[3],'line' => 'line','legend' => $param->line3);
82
$graph->y_format['line3'] = array('colour' => 'red','line' => 'line','legend' => $param->line3);
86
84
$graph->y_tick_labels = false;
91
90
$missedlines = array();
91
$rolenames = get_all_roles();
92
foreach ($rolenames as $r) {
93
$rolenames[$r->id] = $r->name;
95
$rolenames = role_fix_names($rolenames, get_context_instance(CONTEXT_COURSE, $course->id));
92
96
foreach ($stats as $stat) {
93
97
$data[$stat->roleid][$stat->timeend] = $stat->line1;
94
98
if (!empty($stat->zerofixed)) {
97
101
if ($stat->roleid != 0) {
98
102
if (!array_key_exists($stat->roleid,$roles)) {
99
$roles[$stat->roleid] = get_field('role','name','id',$stat->roleid);
103
$roles[$stat->roleid] = $rolenames[$stat->roleid];
106
if (!array_key_exists($stat->roleid,$roles)) {
107
$roles[$stat->roleid] = get_string('all');
102
110
if (!array_key_exists($stat->timeend,$times)) {
113
foreach ($data as $role => $stuff) {
117
foreach (array_keys($data) as $roleid) {
123
krsort($roles); // the same sorting as in table bellow graph
125
$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');
128
foreach ($roles as $roleid=>$rname) {
129
ksort($data[$roleid]);
130
$graph->y_order[] = $roleid+1;
132
$color = $colors[$colorindex++];
133
$colorindex = $colorindex % count($colors);
121
$graph->y_order[] = $roleid;
122
$graph->y_format[$roleid] = array('colour' => $c[$roleid], 'line' => 'line','legend' => $roles[$roleid]);
123
$nonzeroroleid = $roleid;
137
$graph->y_format[$roleid+1] = array('colour' => $color, 'line' => 'line','legend' => $rname);
125
foreach (array_keys($data[$nonzeroroleid]) as $time) {
139
foreach (array_keys($data[$roleid]) as $time) {
126
140
$graph->x_data[] = $times[$time];
128
142
foreach ($data as $roleid => $t) {
132
143
foreach ($t as $time => $data) {
133
$graph->y_data[$roleid][] = $data;
144
$graph->y_data[$roleid+1][] = $data;