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

« back to all changes in this revision

Viewing changes to course/report/stats/graph.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: 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 $
2
2
 
3
3
    require_once('../../../config.php');
4
4
    require_once($CFG->dirroot.'/lib/statslib.php');
21
21
        }
22
22
    }
23
23
 
24
 
    require_login();
 
24
    require_login($course);
25
25
    $context = get_context_instance(CONTEXT_COURSE, $course->id);
26
 
    
27
 
    if (!has_capability('moodle/site:viewreports', $context)) {
28
 
        error('You need do not have the required permission to view reports for this course');
 
26
 
 
27
    if (!$course->showreports or $USER->id != $userid) {
 
28
        require_capability('coursereport/stats:view', $context);
29
29
    }
30
30
 
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;
62
62
 
63
 
    $c = array_keys($graph->colour);
64
 
 
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);
74
72
            }
75
73
        }
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);
81
79
        }
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);
85
83
        }
86
84
        $graph->y_tick_labels = false;
 
85
 
87
86
    } else {
88
87
        $data = array();
89
88
        $times = array();
90
89
        $roles = array();
91
90
        $missedlines = array();
 
91
        $rolenames = get_all_roles();
 
92
        foreach ($rolenames as $r) {
 
93
            $rolenames[$r->id] = $r->name;
 
94
        }
 
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)) {
96
100
            }
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];
 
104
                }
 
105
            } else {
 
106
                if (!array_key_exists($stat->roleid,$roles)) {
 
107
                    $roles[$stat->roleid] = get_string('all');
100
108
                }
101
109
            }
102
110
            if (!array_key_exists($stat->timeend,$times)) {
110
118
                }
111
119
            }
112
120
        }
113
 
        foreach ($data as $role => $stuff) {
114
 
            ksort($data[$role]);
115
 
        }
116
 
        $nonzeroroleid = 0;
117
 
        foreach (array_keys($data) as $roleid) {
118
 
            if ($roleid == 0) {
119
 
                continue;
 
121
 
 
122
        $roleid = 0;
 
123
        krsort($roles); // the same sorting as in table bellow graph
 
124
 
 
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');
 
126
        $colorindex = 0;
 
127
 
 
128
        foreach ($roles as $roleid=>$rname) {
 
129
            ksort($data[$roleid]);
 
130
            $graph->y_order[] = $roleid+1;
 
131
            if ($roleid) {
 
132
                $color = $colors[$colorindex++];
 
133
                $colorindex = $colorindex % count($colors);
 
134
            } else {
 
135
                $color = 'black';
120
136
            }
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);
124
138
        }
125
 
        foreach (array_keys($data[$nonzeroroleid]) as $time) {
 
139
        foreach (array_keys($data[$roleid]) as $time) {
126
140
            $graph->x_data[] = $times[$time];
127
141
        }
128
142
        foreach ($data as $roleid => $t) {
129
 
            if ($roleid == 0) {
130
 
                continue;
131
 
            }
132
143
            foreach ($t as $time => $data) {
133
 
                $graph->y_data[$roleid][] = $data;
 
144
                $graph->y_data[$roleid+1][] = $data;
134
145
            }
135
146
        }
136
147
    }