$this->add_course_essentials($coursenode, $course);
// Load the course sections into the page
$sections = $this->load_course_sections($course, $coursenode);
- if ($course->id !== SITEID) {
+ if ($course->id != SITEID) {
// Find the section for the $CM associated with the page and collect
// its section number.
if (isset($cm->sectionnum)) {
}
// Load each extending user into the navigation.
foreach ($this->extendforuser as $user) {
- if ($user->id !== $USER->id) {
+ if ($user->id != $USER->id) {
$this->load_for_user($user);
}
}
*/
protected function load_activity($cm, stdClass $course, navigation_node $activity) {
global $CFG, $DB;
-
+
// make sure we have a $cm from get_fast_modinfo as this contains activity access details
if (!($cm instanceof cm_info)) {
$modinfo = get_fast_modinfo($course);
// Get the course set against the page, by default this will be the site
$course = $this->page->course;
$baseargs = array('id'=>$user->id);
- if ($course->id !== SITEID && (!$iscurrentuser || $forceforcontext)) {
+ if ($course->id != SITEID && (!$iscurrentuser || $forceforcontext)) {
if (array_key_exists($course->id, $this->mycourses)) {
$coursenode = $this->mycourses[$course->id]->coursenode;
} else {
*/
public function add_course(stdClass $course, $forcegeneric = false) {
global $CFG;
- $canviewhidden = has_capability('moodle/course:viewhiddencourses', $this->page->context);
- if ($course->id !== SITEID && !$canviewhidden && !$course->visible) {
- return false;
+
+ if ($course->id != SITEID) {
+ if (!$course->visible) {
+ if (is_role_switched($course->id)) {
+ // user has to be able to access course in order to switch, let's skip the visibility test here
+ } else if (!has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) {
+ return false;
+ }
+ }
}
$issite = ($course->id == SITEID);
$availableroles = get_switchable_roles($coursecontext);
if (is_array($availableroles)) {
foreach ($availableroles as $key=>$role) {
- if ($assumedrole===(int)$key) {
+ if ($assumedrole == (int)$key) {
continue;
}
$roles[$key] = $role;