Permalink
Browse files

MDL-25974 fix access to activities when role switched in hidden cours…

…e and some coding style strict comparison fixes

The problem with strict comparison of numerical values fails badly if one is int and the other is string, moodle core apis do not guarantee return types much.
  • Loading branch information...
1 parent d911c72 commit 44303ca67a763a83387b6e965e3bc36ab4022649 @skodak skodak committed Feb 13, 2011
Showing with 14 additions and 8 deletions.
  1. +14 −8 lib/navigationlib.php
View
@@ -1023,7 +1023,7 @@ public function initialise() {
$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)) {
@@ -1105,7 +1105,7 @@ public function initialise() {
}
// 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);
}
}
@@ -1517,7 +1517,7 @@ protected function load_stealth_activity(navigation_node $coursenode, $modinfo)
*/
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);
@@ -1569,7 +1569,7 @@ protected function load_for_user($user=null, $forceforcontext=false) {
// 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 {
@@ -1857,9 +1857,15 @@ public function get_extending_users() {
*/
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);
@@ -2984,7 +2990,7 @@ protected function load_course_settings($forceopen = false) {
$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;

0 comments on commit 44303ca

Please sign in to comment.