Permalink
Browse files

MDL-33017 Show Currently viewed course in new node

  • Loading branch information...
andrewnicols authored and Sam Hemelryk committed Jul 13, 2012
1 parent 6109f21 commit 6caf3f5c74f317c572feb1aa3a4e78115b9d131d
Showing with 32 additions and 12 deletions.
  1. +1 −0 lang/en/moodle.php
  2. +31 −12 lib/navigationlib.php
View
@@ -390,6 +390,7 @@
$string['creatingusers'] = 'Creating users';
$string['creatingxmlfile'] = 'Creating XML file';
$string['currency'] = 'Currency';
$string['currentcourse'] = 'Current course';
$string['currentcourseadding'] = 'Current course, adding data to it';
$string['currentcoursedeleting'] = 'Current course, deleting it first';
$string['currentlanguage'] = 'Current language';
View
@@ -73,6 +73,12 @@ class navigation_node implements renderable {
const TYPE_USER = 80;
/** @var int Setting node type, used for containers of no importance 90 */
const TYPE_CONTAINER = 90;
/** var int Course the current user is not enrolled in */
const COURSE_OTHER = 0;
/** var int Course the current user is enrolled in but not viewing */
const COURSE_MY = 1;
/** var int Course the current user is currently viewing */
const COURSE_CURRENT = 2;
/** @var int Parameter to aid the coder in tracking [optional] */
public $id = null;
@@ -1050,6 +1056,7 @@ public function initialise() {
}
$this->rootnodes['site'] = $this->add_course($SITE);
$this->rootnodes['myprofile'] = $this->add(get_string('myprofile'), null, self::TYPE_USER, null, 'myprofile');
$this->rootnodes['currentcourse'] = $this->add(get_string('currentcourse'), null, self::TYPE_ROOTNODE, null, 'currentcourse');
$this->rootnodes['mycourses'] = $this->add(get_string('mycourses'), null, self::TYPE_ROOTNODE, null, 'mycourses');
$this->rootnodes['courses'] = $this->add(get_string('courses'), new moodle_url('/course/index.php'), self::TYPE_ROOTNODE, null, 'courses');
$this->rootnodes['users'] = $this->add(get_string('users'), null, self::TYPE_ROOTNODE, null, 'users');
@@ -1068,6 +1075,10 @@ public function initialise() {
// $ismycourse gets set to true if the user is enrolled in the current pages course.
$ismycourse = !$issite && (array_key_exists($this->page->course->id, $mycourses));
if ($ismycourse) {
unset($mycourses[$this->page->course->id]);
}
// Check if any courses were returned.
if (count($mycourses) > 0) {
@@ -1149,7 +1160,7 @@ public function initialise() {
// Add all of the users courses to the navigation.
// First up we need to add to the mycourses section.
foreach ($mycourses as $course) {
$course->coursenode = $this->add_course($course, false, true);
$course->coursenode = $this->add_course($course, false, self::COURSE_MY);
}
if (!empty($CFG->navshowallcourses)) {
@@ -1180,6 +1191,8 @@ public function initialise() {
}
}
}
} else if ($this->page->course) {
// Do nothing - handled later.
} else if (!empty($CFG->navshowallcourses) || !$this->show_categories()) {
// Load all courses
$this->load_all_courses();
@@ -1211,14 +1224,12 @@ public function initialise() {
}
break;
}
// Load the course associated with the page into the navigation
// Load the course associated with the current page into the navigation.
$course = $this->page->course;
if ($this->show_categories() && !$ismycourse) {
// The user isn't enrolled in the course and we need to show categories in which case we need
// to load the category relating to the course and depending up $showcategories all of the root categories as well.
$this->load_all_categories($course->category, $showcategories);
}
$coursenode = $this->load_course($course);
$coursecontext = context_course::instance($course->id);
$coursenode = $this->add_course($course, false, self::COURSE_CURRENT);
// If the course wasn't added then don't try going any further.
if (!$coursenode) {
@@ -1243,20 +1254,21 @@ public function initialise() {
}
}
}
if (!$isparent) {
$coursenode->make_active();
$canviewcourseprofile = false;
break;
}
}
// Add the essentials such as reports etc...
$this->add_course_essentials($coursenode, $course);
// Extend course navigation with it's sections/activities
$this->load_course_sections($course, $coursenode);
if (!$coursenode->contains_active_node() && !$coursenode->search_for_active_node()) {
$coursenode->make_active();
}
break;
case CONTEXT_MODULE :
if ($issite) {
@@ -1410,7 +1422,7 @@ public function initialise() {
}
}
}
} else if ((!empty($CFG->navshowallcourses) || empty($mycourses)) && !$this->can_add_more_courses_to_category($this->rootnodes['courses'])) {
} else if ((!empty($CFG->navshowallcourses) || (empty($mycourses) && !$ismycourse)) && !$this->can_add_more_courses_to_category($this->rootnodes['courses'])) {
$this->rootnodes['courses']->add(get_string('viewallcoursescategories'), new moodle_url('/course/index.php'), self::TYPE_SETTING);
}
@@ -1638,6 +1650,10 @@ protected function load_all_courses($categoryids = null) {
// frotpage is not wanted here
continue;
}
if ($this->page->course && ($this->page->course->id == $course->id)) {
// Don't include the currentcourse in this nodelist - it's displayed in the Current course node
continue;
}
context_instance_preload($course);
if (!$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
continue;
@@ -2431,7 +2447,7 @@ public function get_extending_users() {
* @param bool $ismycourse
* @return navigation_node
*/
public function add_course(stdClass $course, $forcegeneric = false, $ismycourse = false) {
public function add_course(stdClass $course, $forcegeneric = false, $coursetype = self::COURSE_OTHER) {
global $CFG, $SITE;
// We found the course... we can return it now :)
@@ -2458,7 +2474,10 @@ public function add_course(stdClass $course, $forcegeneric = false, $ismycourse
if (empty($CFG->usesitenameforsitepages)) {
$shortname = get_string('sitepages');
}
} else if ($ismycourse && !$forcegeneric) {
} else if ($coursetype == self::COURSE_CURRENT) {
$parent = $this->rootnodes['currentcourse'];
$url = new moodle_url('/course/view.php', array('id'=>$course->id));
} else if ($coursetype == self::COURSE_MY && !$forcegeneric) {
if (!empty($CFG->navshowmycoursecategories) && ($parent = $this->rootnodes['mycourses']->find($course->category, self::TYPE_CATEGORY))) {
// Nothing to do here the above statement set $parent to the category within mycourses.
} else {

0 comments on commit 6caf3f5

Please sign in to comment.