Skip to content

Commit

Permalink
Merge branch 'wip-MDL-30378-m21' of git://github.com/samhemelryk/mood…
Browse files Browse the repository at this point in the history
…le into MOODLE_21_STABLE
  • Loading branch information
stronk7 committed Nov 29, 2011
2 parents 9316161 + c6a3aa7 commit 6d959a5
Showing 1 changed file with 131 additions and 126 deletions.
257 changes: 131 additions & 126 deletions lib/navigationlib.php
Expand Up @@ -1060,7 +1060,7 @@ public function initialise() {
$mycourses = enrol_get_my_courses(NULL, 'visible DESC,sortorder ASC', $limit); $mycourses = enrol_get_my_courses(NULL, 'visible DESC,sortorder ASC', $limit);
$showallcourses = (count($mycourses) == 0 || !empty($CFG->navshowallcourses)); $showallcourses = (count($mycourses) == 0 || !empty($CFG->navshowallcourses));
$showcategories = ($showallcourses && $this->show_categories()); $showcategories = ($showallcourses && $this->show_categories());
$issite = ($this->page->course->id != SITEID); $issite = ($this->page->course->id == SITEID);
$ismycourse = (array_key_exists($this->page->course->id, $mycourses)); $ismycourse = (array_key_exists($this->page->course->id, $mycourses));


// Check if any courses were returned. // Check if any courses were returned.
Expand All @@ -1080,148 +1080,84 @@ public function initialise() {
// JavaScript enabled. // JavaScript enabled.
$frontpagecourse = $this->load_course($SITE); $frontpagecourse = $this->load_course($SITE);
$this->add_front_page_course_essentials($frontpagecourse, $SITE); $this->add_front_page_course_essentials($frontpagecourse, $SITE);
$this->load_course_sections($SITE, $frontpagecourse);


$canviewcourseprofile = true; $canviewcourseprofile = true;


// Next load context specific content into the navigation // No need to run the generation code for if its the front page.
switch ($this->page->context->contextlevel) { // That has already been done for every page above.
case CONTEXT_SYSTEM : if (!$issite) {
// This has already been loaded we just need to map the variable // Next load context specific content into the navigation
$coursenode = $frontpagecourse; switch ($this->page->context->contextlevel) {
$this->load_all_categories(null, $showcategories); case CONTEXT_SYSTEM :
break; // This has already been loaded we just need to map the variable
case CONTEXT_COURSECAT : $coursenode = $frontpagecourse;
// This has already been loaded we just need to map the variable $this->load_all_categories(null, $showcategories);
$coursenode = $frontpagecourse;
$this->load_all_categories($this->page->context->instanceid, $showcategories);
break;
case CONTEXT_BLOCK :
case CONTEXT_COURSE :
// Load the course associated with the page into the navigation
$course = $this->page->course;
if ($showcategories && !$issite && !$ismycourse) {
$this->load_all_categories($course->category, $showcategories);
}
$coursenode = $this->load_course($course);

// If the course wasn't added then don't try going any further.
if (!$coursenode) {
$canviewcourseprofile = false;
break; break;
} case CONTEXT_COURSECAT :

// This has already been loaded we just need to map the variable
// If the user is not enrolled then we only want to show the $coursenode = $frontpagecourse;
// course node and not populate it. $this->load_all_categories($this->page->context->instanceid, $showcategories);
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); break;

case CONTEXT_BLOCK :
// Not enrolled, can't view, and hasn't switched roles case CONTEXT_COURSE :
if (!can_access_course($coursecontext)) { // Load the course associated with the page into the navigation
// TODO: very ugly hack - do not force "parents" to enrol into course their child is enrolled in, $course = $this->page->course;
// this hack has been propagated from user/view.php to display the navigation node. (MDL-25805) if ($showcategories && !$ismycourse) {
$isparent = false; $this->load_all_categories($course->category, $showcategories);
if ($this->useridtouseforparentchecks) {
if ($this->useridtouseforparentchecks != $USER->id) {
$usercontext = get_context_instance(CONTEXT_USER, $this->useridtouseforparentchecks, MUST_EXIST);
if ($DB->record_exists('role_assignments', array('userid' => $USER->id, 'contextid' => $usercontext->id))
and has_capability('moodle/user:viewdetails', $usercontext)) {
$isparent = true;
}
}
} }
$coursenode = $this->load_course($course);


if (!$isparent) { // If the course wasn't added then don't try going any further.
$coursenode->make_active(); if (!$coursenode) {
$canviewcourseprofile = false; $canviewcourseprofile = false;
break; break;
} }
}
// Add the essentials such as reports etc...
$this->add_course_essentials($coursenode, $course);
if ($this->format_display_course_content($course->format)) {
// Load the course sections
$sections = $this->load_course_sections($course, $coursenode);
}
if (!$coursenode->contains_active_node() && !$coursenode->search_for_active_node()) {
$coursenode->make_active();
}
break;
case CONTEXT_MODULE :
$course = $this->page->course;
$cm = $this->page->cm;


if ($showcategories && !$issite && !$ismycourse) { // If the user is not enrolled then we only want to show the
$this->load_all_categories($course->category, $showcategories); // course node and not populate it.
} $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);

// 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)) {
$coursenode->make_active();
$canviewcourseprofile = false;
break;
}


$this->add_course_essentials($coursenode, $course); // Not enrolled, can't view, and hasn't switched roles
// Load the course sections into the page if (!can_access_course($coursecontext)) {
$sections = $this->load_course_sections($course, $coursenode); // TODO: very ugly hack - do not force "parents" to enrol into course their child is enrolled in,
if ($course->id != SITEID) { // this hack has been propagated from user/view.php to display the navigation node. (MDL-25805)
// Find the section for the $CM associated with the page and collect $isparent = false;
// its section number. if ($this->useridtouseforparentchecks) {
if (isset($cm->sectionnum)) { if ($this->useridtouseforparentchecks != $USER->id) {
$cm->sectionnumber = $cm->sectionnum; $usercontext = get_context_instance(CONTEXT_USER, $this->useridtouseforparentchecks, MUST_EXIST);
} else { if ($DB->record_exists('role_assignments', array('userid' => $USER->id, 'contextid' => $usercontext->id))
foreach ($sections as $section) { and has_capability('moodle/user:viewdetails', $usercontext)) {
if ($section->id == $cm->section) { $isparent = true;
$cm->sectionnumber = $section->section; }
break;
} }
} }
}


// Load all of the section activities for the section the cm belongs to. if (!$isparent) {
if (isset($cm->sectionnumber) and !empty($sections[$cm->sectionnumber])) { $coursenode->make_active();
list($sectionarray, $activityarray) = $this->generate_sections_and_activities($course); $canviewcourseprofile = false;
$activities = $this->load_section_activities($sections[$cm->sectionnumber]->sectionnode, $cm->sectionnumber, $activityarray); break;
} else {
$activities = array();
if ($activity = $this->load_stealth_activity($coursenode, get_fast_modinfo($course))) {
// "stealth" activity from unavailable section
$activities[$cm->id] = $activity;
} }
} }
} else { // Add the essentials such as reports etc...
$activities = array(); $this->add_course_essentials($coursenode, $course);
$activities[$cm->id] = $coursenode->get($cm->id, navigation_node::TYPE_ACTIVITY); if ($this->format_display_course_content($course->format)) {
} // Load the course sections
if (!empty($activities[$cm->id])) { $sections = $this->load_course_sections($course, $coursenode);
// Finally load the cm specific navigaton information
$this->load_activity($cm, $course, $activities[$cm->id]);
// Check if we have an active ndoe
if (!$activities[$cm->id]->contains_active_node() && !$activities[$cm->id]->search_for_active_node()) {
// And make the activity node active.
$activities[$cm->id]->make_active();
} }
} else { if (!$coursenode->contains_active_node() && !$coursenode->search_for_active_node()) {
//TODO: something is wrong, what to do? (Skodak) $coursenode->make_active();
} }
break; break;
case CONTEXT_USER : case CONTEXT_MODULE :
$course = $this->page->course; $course = $this->page->course;
if ($course->id != SITEID) { $cm = $this->page->cm;
if ($showcategories && !$issite && !$ismycourse) {
if ($showcategories && !$ismycourse) {
$this->load_all_categories($course->category, $showcategories); $this->load_all_categories($course->category, $showcategories);
} }
// Load the course associated with the user 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 the course wasn't added then don't try going any further.
Expand All @@ -1238,10 +1174,79 @@ public function initialise() {
$canviewcourseprofile = false; $canviewcourseprofile = false;
break; break;
} }

$this->add_course_essentials($coursenode, $course); $this->add_course_essentials($coursenode, $course);
// Load the course sections into the page
$sections = $this->load_course_sections($course, $coursenode); $sections = $this->load_course_sections($course, $coursenode);
} if ($course->id != SITEID) {
break; // Find the section for the $CM associated with the page and collect
// its section number.
if (isset($cm->sectionnum)) {
$cm->sectionnumber = $cm->sectionnum;
} else {
foreach ($sections as $section) {
if ($section->id == $cm->section) {
$cm->sectionnumber = $section->section;
break;
}
}
}

// Load all of the section activities for the section the cm belongs to.
if (isset($cm->sectionnumber) and !empty($sections[$cm->sectionnumber])) {
list($sectionarray, $activityarray) = $this->generate_sections_and_activities($course);
$activities = $this->load_section_activities($sections[$cm->sectionnumber]->sectionnode, $cm->sectionnumber, $activityarray);
} else {
$activities = array();
if ($activity = $this->load_stealth_activity($coursenode, get_fast_modinfo($course))) {
// "stealth" activity from unavailable section
$activities[$cm->id] = $activity;
}
}
} else {
$activities = array();
$activities[$cm->id] = $coursenode->get($cm->id, navigation_node::TYPE_ACTIVITY);
}
if (!empty($activities[$cm->id])) {
// Finally load the cm specific navigaton information
$this->load_activity($cm, $course, $activities[$cm->id]);
// Check if we have an active ndoe
if (!$activities[$cm->id]->contains_active_node() && !$activities[$cm->id]->search_for_active_node()) {
// And make the activity node active.
$activities[$cm->id]->make_active();
}
} else {
//TODO: something is wrong, what to do? (Skodak)
}
break;
case CONTEXT_USER :
$course = $this->page->course;
if ($course->id != SITEID) {
if ($showcategories && !$ismycourse) {
$this->load_all_categories($course->category, $showcategories);
}
// 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);
if (!can_access_course($coursecontext)) {
$coursenode->make_active();
$canviewcourseprofile = false;
break;
}
$this->add_course_essentials($coursenode, $course);
$sections = $this->load_course_sections($course, $coursenode);
}
break;
}
} }


$limit = 20; $limit = 20;
Expand Down

0 comments on commit 6d959a5

Please sign in to comment.