2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
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
);
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
)) {
45 $sql = "SELECT courseid, $param->fields
46 FROM {".'stats_'.$param->table
."}
47 WHERE timeend >= $param->timeafter AND stattype = 'activity' AND roleid = 0
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
});