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/>.
18 * This file contains functions used by the course overview report.
20 * @package report_courseoverview
21 * @copyright 2016 Simey Lameze <simey@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 defined('MOODLE_INTERNAL') ||
die;
26 require_once('../../config.php');
27 require_once($CFG->dirroot
. '/lib/statslib.php');
30 * Gather course overview data and print the chart.
32 * @param int $report represents the report type field on the course overview report filter.
33 * @param int $time represents the time period field on the course overview report filter.
34 * @param int $numcourses represents the number of courses field on the course overview report filter.
37 function report_courseoverview_print_chart($report, $time, $numcourses) {
38 global $DB, $OUTPUT, $PAGE;
40 $param = stats_get_parameters($time, $report, SITEID
, STATS_MODE_RANKED
);
41 if (!empty($param->sql
)) {
44 $sql = "SELECT courseid, $param->fields
45 FROM {" . 'stats_' . $param->table
. "}
46 WHERE timeend >= $param->timeafter
47 AND stattype = 'activity'
51 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());
62 foreach ($courses as $c) {
63 $data['labels'][$i] = $DB->get_field('course', 'shortname', array('id' => $c->courseid
));
65 // Line3 represents the third column of the report table except for the most active users report.
66 // It is a float number and can be participation radio or activity per user.
67 if (isset($c->line3
)) {
68 $data['series'][$i] = round($c->line3
, 2);
70 $data['series'][$i] = $c->{$param->graphline
};
75 $chart = new \core\
chart_bar();
76 $series = new \core\
chart_series($param->{$param->graphline
}, $data['series']);
77 $chart->add_series($series);
78 $chart->set_labels($data['labels']);
80 echo $OUTPUT->render($chart);