Browse files

MDL-28184 navigation: Tidied up handling of coursenode when adding co…

…urse essentials
  • Loading branch information...
1 parent a938306 commit f3e47fc8d2a2c1b3ab5736f256a69fb92b160782 Sam Hemelryk committed Jul 13, 2011
Showing with 16 additions and 5 deletions.
  1. +16 −5 lib/navigationlib.php
View
21 lib/navigationlib.php
@@ -1159,13 +1159,17 @@ public function initialise() {
// Load the course associated with the page into the navigation
$coursenode = $this->load_course($course);
+ // If the course wasn't added then don't try going any further.
+ if (!$coursenode) {
+ $canviewcourseprofile = false;
+ break;
+ }
+
// If the user is not enrolled then we only want to show the
// course node and not populate it.
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
if (!can_access_course($coursecontext)) {
- if ($coursenode) {
- $coursenode->make_active();
- }
+ $coursenode->make_active();
$canviewcourseprofile = false;
break;
}
@@ -1222,6 +1226,13 @@ public function initialise() {
}
// Load the course associated with the user into the navigation
$coursenode = $this->load_course($course);
+
+ // If the course wasn't added then don't try going any further.
+ if (!$coursenode) {
+ $canviewcourseprofile = false;
+ break;
+ }
+
// If the user is not enrolled then we only want to show the
// course node and not populate it.
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
@@ -2170,14 +2181,14 @@ public function add_course(stdClass $course, $forcegeneric = false, $ismycourse
* @param stdClass $course
* @return bool
*/
- public function add_course_essentials(navigation_node $coursenode, stdClass $course) {
+ public function add_course_essentials($coursenode, stdClass $course) {
global $CFG;
if ($course->id == SITEID) {
return $this->add_front_page_course_essentials($coursenode, $course);
}
- if ($coursenode == false || $coursenode->get('participants', navigation_node::TYPE_CONTAINER)) {
+ if ($coursenode == false || !($coursenode instanceof navigation_node) || $coursenode->get('participants', navigation_node::TYPE_CONTAINER)) {
return true;
}

0 comments on commit f3e47fc

Please sign in to comment.