From d755d8c3bd9f85d800cd329803815971ed7a343d Mon Sep 17 00:00:00 2001 From: samhemelryk Date: Fri, 11 Sep 2009 08:26:36 +0000 Subject: [PATCH] navigation MDL-14632 Fixed bug whereby if someone called PAGE->set_course() on a page outside of a course and then a user browsed to it they would be shown the course content in the navigation --- lib/navigationlib.php | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 78c604acd1d..24ea48ee2a0 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -881,7 +881,7 @@ class global_navigation extends navigation_node { * @return int The depth to the active(requested) node */ protected function load_for_course() { - global $PAGE, $CFG; + global $PAGE, $CFG, $USER; $keys = array(); $depth = $this->load_course_categories($keys); $depth += $this->load_course($keys); @@ -892,8 +892,11 @@ class global_navigation extends navigation_node { } return $depth; } - $depth += $this->load_course_activities($keys); - $depth += $this->load_course_sections($keys); + + if (isloggedin() && has_capability('moodle/course:view', get_context_instance(CONTEXT_COURSE, $PAGE->course->id))) { + $depth += $this->load_course_activities($keys); + $depth += $this->load_course_sections($keys); + } return $depth; } @@ -1595,13 +1598,17 @@ class limited_global_navigation extends global_navigation { $keys = array(); parent::load_course($keys, $course); - if (!$this->cache->cached('course'.$course->id.'section0')) { - $this->cache->{'course'.$course->id.'section0'} = $DB->get_record('course_sections', array('course'=>$course->id, 'section'=>'0')); - } - $section = $this->cache->{'course'.$course->id.'section0'}; - $this->load_section_activities($course, $section); - if ($this->depthforward>0) { - $this->load_course_sections($keys, $course); + + if (isloggedin() && has_capability('moodle/course:view', get_context_instance(CONTEXT_COURSE, $instanceid))) { + + if (!$this->cache->cached('course'.$course->id.'section0')) { + $this->cache->{'course'.$course->id.'section0'} = $DB->get_record('course_sections', array('course'=>$course->id, 'section'=>'0')); + } + $section = $this->cache->{'course'.$course->id.'section0'}; + $this->load_section_activities($course, $section); + if ($this->depthforward>0) { + $this->load_course_sections($keys, $course); + } } } /**