~ubuntu-branches/ubuntu/jaunty/moodle/jaunty

« back to all changes in this revision

Viewing changes to mod/quiz/report/overview/overviewgraph.php

  • Committer: Bazaar Package Importer
  • Author(s): Jordan Mantha, Matt Oquist
  • Date: 2009-02-25 15:16:22 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20090225151622-0ekt1liwhv2obfza
Tags: 1.9.4.dfsg-0ubuntu1
* Merge with Debian git (Closes LP: #322961, #239481, #334611):
  - use Ubuntu's smarty lib directory for linking
  - use internal yui library 
  - add update-notifier support back in

[Matt Oquist]
  * renamed prerm script
  * significantly rewrote postinst and other maintainer scripts to improve
    user experience and package maintainability
    (Closes LP: #225662, #325450, #327843, #303078, #234609)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php  // $Id: overviewgraph.php,v 1.1.2.6 2009/01/14 07:03:14 tjhunt Exp $
 
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];
 
9
    $colourindex++;
 
10
    if ($colourindex > (count($colours)-1)){
 
11
        $colourindex =0;
 
12
    }
 
13
    return $colour;
 
14
}
 
15
define('QUIZ_REPORT_MAX_PARTICIPANTS_TO_SHOW_ALL_GROUPS', 500);
 
16
$quizid = required_param('id', PARAM_INT);
 
17
 
 
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);
 
24
} else {
 
25
    $groups = false;
 
26
}
 
27
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
 
28
require_capability('mod/quiz:viewreports', $modcontext);
 
29
 
 
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;
 
37
 
 
38
//following two lines seem to silence notice warnings from graphlib.php
 
39
$line->y_tick_labels = null;
 
40
$line->offset_relation = null;
 
41
 
 
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
 
44
 
 
45
//pick a sensible number of bands depending on quiz maximum grade.
 
46
$bands = $quiz->grade;
 
47
while ($bands >= 20 || $bands < 10){
 
48
    if ($bands >= 50){
 
49
        $bands = $bands /5;
 
50
    } else if ($bands >= 20) {
 
51
        $bands = $bands /2;
 
52
    }
 
53
    if ($bands < 4){
 
54
        $bands = $bands * 5;
 
55
    } else if ($bands < 10){
 
56
        $bands = $bands * 2;
 
57
    }
 
58
}
 
59
 
 
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);
 
67
    } else {
 
68
        $label .= number_format($quiz->grade, $quiz->decimalpoints);
 
69
    }
 
70
    $bandlabels[] = $label;
 
71
 
72
$line->x_data          = $bandlabels;
 
73
 
 
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 ||
 
78
        count($groups)>4){
 
79
    if ($groups){
 
80
        if ($currentgroup = groups_get_activity_group($cm)){
 
81
            $groups = array($currentgroup=>'');
 
82
        } else {
 
83
            $groups = false;//all participants mode
 
84
        }
 
85
    }
 
86
}
 
87
$line->y_order = array('allusers');
 
88
if ($groups){
 
89
    foreach (array_keys($groups) as $group){
 
90
        $useridingroup = get_users_by_capability($modcontext, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),'','','','',$group,'',false);
 
91
        if ($useridingroup){
 
92
            $useridingrouplist = join(',',array_keys($useridingroup));
 
93
            $groupdata = quiz_report_grade_bands($bandwidth, $bands, $quizid, $useridingrouplist);
 
94
            if ($groupdata){
 
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;
 
104
            }
 
105
        }
 
106
    }
 
107
}
 
108
 
 
109
 
 
110
 
 
111
 
 
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.
 
115
 
 
116
 
 
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;
 
122
    } else {
 
123
        $gridlines = $gridlines /2;
 
124
    }
 
125
}
 
126
 
 
127
$line->parameter['y_axis_gridlines'] = $gridlines+1; 
 
128
$line->draw();
 
129
 
 
130
?>