}
- // when in "course login as" - load only course capabilitites (it may not always work as expected)
- if (!empty($USER->realuser) and $USER->loginascontext->contextlevel != CONTEXT_SYSTEM) {
- $children = array_keys(get_child_contexts($USER->loginascontext));
- $children[] = $USER->loginascontext->id;
- foreach ($USER->capabilities as $conid => $caps) {
- if (!in_array($conid, $children)) {
- unset($USER->capabilities[$conid]);
- }
- }
- }
-
// handle role switching in courses
if (!empty($USER->switchrole)) {
foreach ($USER->switchrole as $contextid => $roleid) {
// worthwhile...) and we may hit SQL parser limits
// because we use IN()
//
- if ($userid === $USER->id
- && isset($USER->mycourses)
- && is_string($USER->mycourses)) {
- if ($USER->mycourses === '') {
- // empty str means: user has no courses
- // ... so do the easy thing...
- return array();
- } else {
+ if ($userid === $USER->id) {
+ if (isset($USER->loginascontext)) {
+ // list _only_ this course
+ // anything else is asking for trouble...
+ $courseids = $USER->loginascontext->instanceid;
+ } elseif (isset($USER->mycourses)
+ && is_string($USER->mycourses)) {
+ if ($USER->mycourses === '') {
+ // empty str means: user has no courses
+ // ... so do the easy thing...
+ return array();
+ } else {
+ $courseids = $USER->mycourses;
+ }
+ }
+ if (isset($courseids)) {
// The data massaging here MUST be kept in sync with
// get_user_courses_bycap() so we return
// the same...
FROM {$CFG->prefix}course c
JOIN {$CFG->prefix}context ctx
ON (c.id=ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSE.")
- WHERE c.id IN ({$USER->mycourses})
+ WHERE c.id IN ($courseids)
ORDER BY $sort";
$rs = get_recordset_sql($sql);
$courses = array();