2 include '../../../../config.php';
3 include $CFG->dirroot
."/lib/graphlib.php";
4 include $CFG->dirroot
."/mod/quiz/report/reportlib.php";
5 function graph_get_new_colour(){
6 static $colourindex = 0;
7 $colours = array('red', 'green', 'yellow', 'orange', 'purple', 'black', 'maroon', 'blue', 'ltgreen', 'navy', 'ltred', 'ltltgreen', 'ltltorange', 'olive', 'gray', 'ltltred', 'ltorange', 'lime', 'ltblue', 'ltltblue');
8 $colour = $colours[$colourindex];
10 if ($colourindex > (count($colours)-1)){
15 define('QUIZ_REPORT_MAX_PARTICIPANTS_TO_SHOW_ALL_GROUPS', 500);
16 $quizid = required_param('id', PARAM_INT
);
18 $quiz = get_record('quiz', 'id', $quizid);
19 $course = get_record('course', 'id', $quiz->course
);
20 require_login($course);
21 $cm = get_coursemodule_from_instance('quiz', $quizid);
22 if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used
23 $groups = groups_get_activity_allowed_groups($cm);
27 $modcontext = get_context_instance(CONTEXT_MODULE
, $cm->id
);
28 require_capability('mod/quiz:viewreports', $modcontext);
30 $line = new graph(800,600);
31 $line->parameter
['title'] = '';
32 $line->parameter
['y_label_left'] = $course->students
;
33 $line->parameter
['x_label'] = get_string('grade');
34 $line->parameter
['y_label_angle'] = 90;
35 $line->parameter
['x_label_angle'] = 0;
36 $line->parameter
['x_axis_angle'] = 60;
38 //following two lines seem to silence notice warnings from graphlib.php
39 $line->y_tick_labels
= null;
40 $line->offset_relation
= null;
42 $line->parameter
['bar_size'] = 1; // will make size > 1 to get overlap effect when showing groups
43 $line->parameter
['bar_spacing'] = 10; // don't forget to increase spacing so that graph doesn't become one big block of colour
45 //pick a sensible number of bands depending on quiz maximum grade.
46 $bands = $quiz->grade
;
47 while ($bands >= 20 ||
$bands < 10){
50 } else if ($bands >= 20) {
55 } else if ($bands < 10){
60 $bandwidth = $quiz->grade
/ $bands;
61 $bands = ceil($bands);
62 $bandlabels = array();
63 for ($i=0;$i < $quiz->grade
;$i +
= $bandwidth){
64 $label = number_format($i, $quiz->decimalpoints
).' - ';
65 if ($quiz->grade
> $i+
$bandwidth){
66 $label .= number_format($i+
$bandwidth, $quiz->decimalpoints
);
68 $label .= number_format($quiz->grade
, $quiz->decimalpoints
);
70 $bandlabels[] = $label;
72 $line->x_data
= $bandlabels;
74 $line->y_format
['allusers'] =
75 array('colour' => graph_get_new_colour(), 'bar' => 'fill', 'shadow_offset' => 1, 'legend' => get_string('allparticipants'));
76 $line->y_data
['allusers'] = quiz_report_grade_bands($bandwidth, $bands, $quizid);
77 if (array_sum($line->y_data
['allusers'])>QUIZ_REPORT_MAX_PARTICIPANTS_TO_SHOW_ALL_GROUPS ||
80 if ($currentgroup = groups_get_activity_group($cm)){
81 $groups = array($currentgroup=>'');
83 $groups = false;//all participants mode
87 $line->y_order
= array('allusers');
89 foreach (array_keys($groups) as $group){
90 $useridingroup = get_users_by_capability($modcontext, 'mod/quiz:attempt','','','','',$group,'',false);
92 $useridingrouplist = join(',',array_keys($useridingroup));
93 $groupdata = quiz_report_grade_bands($bandwidth, $bands, $quizid, $useridingrouplist);
95 $line->parameter
['bar_size'] = 1.2;
96 $line->y_data
['groupusers'.$group] = $groupdata;
97 //only turn on legends if there is more than one set of bars
98 $line->parameter
['legend'] = 'outside-top';
99 $line->parameter
['legend_border'] = 'black';
100 $line->parameter
['legend_offset'] = 4;
101 $line->y_format
['groupusers'.$group] =
102 array('colour' => graph_get_new_colour(), 'bar' => 'fill', 'shadow_offset' => 1, 'legend' => groups_get_group_name($group));
103 $line->y_order
[] ='groupusers'.$group;
112 $line->parameter
['y_min_left'] = 0; // start at 0
113 $line->parameter
['y_max_left'] = max($line->y_data
['allusers']);
114 $line->parameter
['y_decimal_left'] = 0; // 2 decimal places for y axis.
117 //pick a sensible number of gridlines depending on max value on graph.
118 $gridlines = max($line->y_data
['allusers']);
119 while ($gridlines >= 10){
120 if ($gridlines >= 50){
121 $gridlines = $gridlines /5;
123 $gridlines = $gridlines /2;
127 $line->parameter
['y_axis_gridlines'] = $gridlines+
1;