3 require_once('../../../config.php');
4 require_once($CFG->dirroot
.'/lib/statslib.php');
5 require_once($CFG->dirroot
.'/lib/graphlib.php');
7 $report = required_param('report', PARAM_INT
);
8 $time = required_param('time', PARAM_INT
);
9 $numcourses = required_param('numcourses', PARAM_INT
);
13 require_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM
));
15 stats_check_uptodate();
17 $param = stats_get_parameters($time,$report,SITEID
,STATS_MODE_RANKED
);
19 if (!empty($param->sql
)) {
22 $sql = "SELECT courseid,".$param->fields
." FROM ".$CFG->prefix
.'stats_'.$param->table
23 ." WHERE timeend >= $param->timeafter AND stattype = 'activity' AND roleid = 0"
24 ." GROUP BY courseid "
26 ." ORDER BY ".$param->orderby
;
29 $courses = get_records_sql($sql, 0, $numcourses);
31 if (empty($courses)) {
32 print_error('statsnodata', "", $CFG->wwwroot
.'/'.$CFG->admin
.'/report/course/index.php');
36 $graph = new graph(750,400);
38 $graph->parameter
['legend'] = 'outside-right';
39 $graph->parameter
['legend_size'] = 10;
40 $graph->parameter
['x_axis_angle'] = 90;
41 $graph->parameter
['title'] = false; // moodle will do a nicer job.
42 $graph->y_tick_labels
= null;
43 $graph->offset_relation
= null;
44 if ($report != STATS_REPORT_ACTIVE_COURSES
) {
45 $graph->parameter
['y_decimal_left'] = 2;
48 foreach ($courses as $c) {
49 $graph->x_data
[] = get_field('course','shortname','id',$c->courseid
);
50 $graph->y_data
['bar1'][] = $c->{$param->graphline
};
52 $graph->y_order
= array('bar1');
53 $graph->y_format
['bar1'] = array('colour' => 'blue','bar' => 'fill','legend' => $param->{$param->graphline
});