Skip to content

Commit

Permalink
MDL-28184 navigation: Tidied up handling of coursenode when adding co…
Browse files Browse the repository at this point in the history
…urse essentials
  • Loading branch information
Sam Hemelryk committed Jul 13, 2011
1 parent 89b2800 commit 49d85b7
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/navigationlib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1040,13 +1040,17 @@ public function initialise() {
// Load the course associated with the page into the navigation // Load the course associated with the page into the navigation
$coursenode = $this->load_course($course); $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 // If the user is not enrolled then we only want to show the
// course node and not populate it. // course node and not populate it.
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
if (!can_access_course($coursecontext)) { if (!can_access_course($coursecontext)) {
if ($coursenode) { $coursenode->make_active();
$coursenode->make_active();
}
$canviewcourseprofile = false; $canviewcourseprofile = false;
break; break;
} }
Expand Down Expand Up @@ -1099,6 +1103,13 @@ public function initialise() {
if ($course->id != SITEID) { if ($course->id != SITEID) {
// Load the course associated with the user into the navigation // Load the course associated with the user into the navigation
$coursenode = $this->load_course($course); $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 // If the user is not enrolled then we only want to show the
// course node and not populate it. // course node and not populate it.
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
Expand Down Expand Up @@ -1994,14 +2005,14 @@ public function add_course(stdClass $course, $forcegeneric = false) {
* @param stdClass $course * @param stdClass $course
* @return bool * @return bool
*/ */
public function add_course_essentials(navigation_node $coursenode, stdClass $course) { public function add_course_essentials($coursenode, stdClass $course) {
global $CFG; global $CFG;


if ($course->id == SITEID) { if ($course->id == SITEID) {
return $this->add_front_page_course_essentials($coursenode, $course); 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; return true;
} }


Expand Down

0 comments on commit 49d85b7

Please sign in to comment.