Skip to content

Commit

Permalink
MDL-58096 reports: Optimize database request
Browse files Browse the repository at this point in the history
  • Loading branch information
leblangi committed Apr 18, 2017
1 parent 6d14355 commit 6a54bd2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion report/stats/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,26 @@ function report_stats_report($course, $report, $mode, $user, $roleid, $time) {
$userid = 0;
}

$courses = get_courses('all','c.shortname','c.id,c.shortname,c.fullname');
$courses = $DB->get_recordset('course', null, 'shortname', 'id,shortname,visible');
$courseoptions = array();

foreach ($courses as $c) {
context_helper::preload_from_record($c);
$context = context_course::instance($c->id);

if (has_capability('report/stats:view', $context)) {
if (isset($c->visible) && $c->visible <= 0) {
// For hidden courses, require visibility check.
if (!has_capability('moodle/course:viewhiddencourses', $context)) {
continue;
}
}
$courseoptions[$c->id] = format_string($c->shortname, true, array('context' => $context));
}
}

$courses->close();

$reportoptions = stats_get_report_options($course->id, $mode);
$timeoptions = report_stats_timeoptions($mode);
if (empty($timeoptions)) {
Expand Down

0 comments on commit 6a54bd2

Please sign in to comment.