Merge branch 'w41_MDL-28980_m24_expirywarning' of git://github.com/skodak/moodle
[moodle.git] / report / courseoverview / reportsgraph.php
blobd1dff384926edf4236d184d3f0e97e6bec558d5c
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Graph
20 * @package report
21 * @subpackage courseoverview
22 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once('../../config.php');
27 require_once($CFG->dirroot.'/lib/statslib.php');
28 require_once($CFG->dirroot.'/lib/graphlib.php');
30 $report = required_param('report', PARAM_INT);
31 $time = required_param('time', PARAM_INT);
32 $numcourses = required_param('numcourses', PARAM_INT);
34 require_login();
36 require_capability('report/courseoverview:view', context_system::instance());
38 stats_check_uptodate();
40 $param = stats_get_parameters($time,$report,SITEID,STATS_MODE_RANKED);
42 if (!empty($param->sql)) {
43 $sql = $param->sql;
44 } else {
45 $sql = "SELECT courseid, $param->fields
46 FROM {".'stats_'.$param->table."}
47 WHERE timeend >= $param->timeafter AND stattype = 'activity' AND roleid = 0
48 GROUP BY courseid
49 $param->extras
50 ORDER BY $param->orderby";
53 $courses = $DB->get_records_sql($sql, $param->params, 0, $numcourses);
55 if (empty($courses)) {
56 $PAGE->set_url('/report/courseoverview/index.php');
57 print_error('statsnodata', 'error', $PAGE->url->out());
61 $graph = new graph(750,400);
63 $graph->parameter['legend'] = 'outside-right';
64 $graph->parameter['legend_size'] = 10;
65 $graph->parameter['x_axis_angle'] = 90;
66 $graph->parameter['title'] = false; // moodle will do a nicer job.
67 $graph->y_tick_labels = null;
68 $graph->offset_relation = null;
69 if ($report != STATS_REPORT_ACTIVE_COURSES) {
70 $graph->parameter['y_decimal_left'] = 2;
73 foreach ($courses as $c) {
74 $graph->x_data[] = $DB->get_field('course', 'shortname', array('id'=>$c->courseid));
75 $graph->y_data['bar1'][] = $c->{$param->graphline};
77 $graph->y_order = array('bar1');
78 $graph->y_format['bar1'] = array('colour' => 'blue','bar' => 'fill','legend' => $param->{$param->graphline});
80 $graph->draw_stack();