}
$mycourses = array();
-
+
// Fix fields to refer to the course table c
$fields=preg_replace('/([a-z0-9*]+)/','c.$1',$fields);
// Check root permissions
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
- if (has_capability('moodle/course:view',$sitecontext,$userid,$doanything)) {
+
+ // we can optimise some things for true admins
+ $candoanything = false;
+ if ($doanything && has_capability('moodle/site:doanything',$sitecontext,$userid,true)) {
+ $candoanything = true;
+ }
+
+ if ($candoanything || has_capability('moodle/course:view',$sitecontext,$userid,$doanything)) {
// User can view all courses, although there might be exceptions
// which we will filter later.
$rs = get_recordset('course c', '', '', $sort, $fields);
if ($rs && $rs->RecordCount() > 0) {
while ($course = rs_fetch_next_record($rs)) {
if ($course->id != SITEID) {
+
+ if ($candoanything) { // no need for further checks...
+ $mycourses[$course->id] = $course;
+ continue;
+ }
+
// users with moodle/course:view are considered course participants
// the course needs to be visible, or user must have moodle/course:viewhiddencourses
// capability set to view hidden courses
/// MDL-9238, course in sub categories are not shown
// if the user has course:view at system level, then he can view all course
// skip this part
- if (!has_capability('moodle/course:view',$sitecontext,$userid,$doanything)) {
+ if (!$candoanything && !has_capability('moodle/course:view',$sitecontext,$userid,$doanything)) {
// get all course categories with an assignment
$SQL = "SELECT a.id, a.id FROM {$CFG->prefix}role_assignments ra