$string['condifmodeditdefaults'] = 'The values you set here define the default values that are used in the activity settings form when you create a new activity. You can also configure which activity settings are considered advanced.';
$string['configmycoursesperpage'] = 'Maximum number of courses to display in any list of a user\'s own courses';
$string['configmymoodleredirect'] = 'This setting forces redirects to /my on login for non-admins and replaces the top level site navigation with /my';
+$string['confignavhidecategories'] = 'Do not show course categories in the navigation bar or navigation blocks';
+$string['confignavshowallcourses'] = 'Setting this ensures that all courses a user is registered in are shown on the navigation at all times. By default once a user browses to a course only that course is shown on the navigation.';
$string['confignodefaultuserrolelists'] = 'This setting prevents all users from being returned from the database from deprecated calls of get_course_user, etc., for the site course if the default role provides that access. Check this, if you suffer a performance hit.';
$string['confignonmetacoursesyncroleids'] = 'By default all role assignments from child courses are synchronised to metacourses. Roles that are selected here will not be included in the synchronisation process.';
$string['confignoreplyaddress'] = 'Emails are sometimes sent out on behalf of a user (eg forum posts). The email address you specify here will be used as the \"From\" address in those cases when the recipients should not be able to reply directly to the user (eg when a user chooses to keep their address private).';
$string['navigationupgrade'] = 'This upgrade introduces two new navigation blocks that will replace these blocks: Administration, Courses, Activities and Participants. If you had set any special permissions on those blocks you should check to make sure everything
is behaving as you want it.<br /><br />
You should also "Shift-Refresh" your browser to load the new styles, otherwise the new blocks will not work correctly.';
+$string['navhidecategories'] = 'Hide course categories';
+$string['navshowallcourses'] = 'Show all users courses';
$string['nobookmarksforuser'] = 'You do not have any bookmarks.';
$string['nochanges'] = 'No changes';
$string['nodatabase'] = 'No database';
return $depth;
}
+ /**
+ * Finds all nodes that have the specified type
+ *
+ * @param int $type One of navigation_node::TYPE_*
+ * @return array An array of navigation_node references for nodes of type $type
+ */
+ public function get_children_by_type($type) {
+ $nodes = array();
+ if (count($this->children)>0) {
+ foreach ($this->children as &$child) {
+ if ($child->type === $type) {
+ $nodes[] = $child;
+ }
+ }
+ }
+ return $nodes;
+ }
+
/**
* Finds all nodes (recursivily) that have the specified type, regardless of
* assumed order or position.
* @return bool Returns true
*/
public function initialise($jsargs = null) {
- global $PAGE, $SITE;
+ global $PAGE, $SITE, $CFG;
if ($this->initialised || during_initial_install()) {
return true;
}
* This gets called by {@link initialise()} when the context is CONTEXT_USER
*/
protected function load_for_user() {
- global $DB, $SITE, $PAGE;
+ global $DB, $SITE, $PAGE, $CFG;
if (!empty($PAGE->course->id)) {
$courseid = $PAGE->course->id;
} else {
$course = $DB->get_record('course', array('id'=>$courseid));
}
if (isset($course) && $course) {
+ if (!empty($CFG->navshowallcourses)) {
+ $this->load_categories();
+ }
$this->load_for_course();
} else {
$this->load_categories();
global $PAGE, $CFG;
$id = optional_param('id', null);
if ($lookforid && $id!==null) {
+ if (!empty($CFG->navshowallcourses)) {
+ $this->load_categories();
+ }
$this->load_categories($id);
$depth = $this->find_child_depth($id);
} else {
protected function load_for_course() {
global $PAGE, $CFG, $USER;
$keys = array();
+ if (!empty($CFG->navshowallcourses)) {
+ $this->load_categories();
+ }
$depth = $this->load_course_categories($keys);
$depth += $this->load_course($keys);
if (!$this->format_display_course_content($PAGE->course->format)) {
* @return int
*/
protected function load_for_activity() {
- global $PAGE, $DB;
+ global $PAGE, $DB, $CFG;
$keys = array();
$sectionnum = false;
}
}
+ if (!empty($CFG->navshowallcourses)) {
+ $this->load_categories();
+ }
+
$depth = $this->load_course_categories($keys);
$depth += $this->load_course($keys);
$depth += $this->load_course_activities($keys);
// Process this course into the nav structure
$url = new moodle_url($CFG->wwwroot.'/course/view.php', array('id'=>$course->id));
if ($categoryid===null) {
- $category = $this->find_child($course->category);
+ $category = $this->find_child($course->category, self::TYPE_CATEGORY);
+ } else if ($categoryid === false) {
+ $category = $this;
} else {
$category = $this->find_child($categoryid);
}
if (is_array($categories) && count($categories)>0) {
$categories = array_reverse($categories);
foreach ($categories as $category) {
- $url = new moodle_url($CFG->wwwroot.'/course/category.php', array('id'=>$category->id, 'categoryedit'=>'on', 'sesskey'=>sesskey()));
- $keys[] = $this->add_to_path($keys, $category->id, $category->name, $category->name, self::TYPE_CATEGORY, $url);
+ $key = $category->id.':'.self::TYPE_CATEGORY;
+ if (!$this->get_by_path(array_merge($keys, array($key)))) {
+ $url = new moodle_url($CFG->wwwroot.'/course/category.php', array('id'=>$category->id, 'categoryedit'=>'on', 'sesskey'=>sesskey()));
+ $keys[] = $this->add_to_path($keys, $category->id, $category->name, $category->name, self::TYPE_CATEGORY, $url);
+ } else {
+ $keys[] = $key;
+ }
}
}
return count($categories);
$categorypathids = explode('/',trim($course->categorypath,' /'));
// If no category has been specified limit the depth we display immediatly to
// that of the nav var depthforwards
- if ($categoryid===0 && count($categorypathids)>($this->depthforward+1)) {
+ if ($categoryid===0 && count($categorypathids)>($this->depthforward+1) && empty($CFG->navshowallcourses)) {
$categorypathids = array_slice($categorypathids, 0, ($this->depthforward+1));
}
$categoryids = array_merge($categoryids, $categorypathids);
}
}
}
+
+ public function collapse_course_categories() {
+ $categories = $this->get_children_by_type(self::TYPE_CATEGORY);
+ while (count($categories) > 0) {
+ foreach ($categories as $category) {
+ $this->children = array_merge($this->children, $category->children);
+ $this->remove_child($category->key, self::TYPE_CATEGORY);
+}
+ $categories = $this->get_children_by_type(self::TYPE_CATEGORY);
+ }
+ }
}
/**
* @return string HTML
*/
protected function parse_branch_to_html($navarray, $firstnode=true, $moreafterthis=false) {
+ global $CFG;
$separator = get_separator();
$output = '';
if ($firstnode===true) {
return $output;
}
$child = false;
- // Iterate the nodes in navarray and finde the active node
+ // Iterate the nodes in navarray and find the active node
foreach ($navarray as $tempchild) {
if ($tempchild->isactive || $tempchild->contains_active_node()) {
$child = $tempchild;
$oldaction = $child->action;
$child->action = null;
}
+ if (empty($CFG->navhidecategories) || $child->type !== navigation_node::TYPE_CATEGORY) {
// Now display the node
$output .= '<li>'.$separator.' '.$child->content(true).'</li>';
+ }
if (isset($oldaction)) {
$child->action = $oldaction;
}