mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 07:56:06 +02:00
navigation MDL-20651 Added config setting to hide course categories on the navigation
As requested and voted on admin can now choose not to include course categories within the navbar and global navigation block. At the same time I also introduced a second setting, showallcourses, which ensures all of the courses a user is registered in are shown on the navigation at all times.
This commit is contained in:
parent
8bdc9cacad
commit
da3ab9c4be
@ -65,6 +65,12 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
|
||||
$temp->add(new admin_setting_configtext('maxexternalblogsperuser', get_string('maxexternalblogsperuser','blog'), get_string('configmaxexternalblogsperuser', 'blog'), 1));
|
||||
$ADMIN->add('appearance', $temp);
|
||||
|
||||
// Navigation settings
|
||||
$temp = new admin_settingpage('navigation', get_string('navigation'));
|
||||
$temp->add(new admin_setting_configcheckbox('navhidecategories', get_string('navhidecategories', 'admin'), get_string('confignavhidecategories', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('navshowallcourses', get_string('navshowallcourses', 'admin'), get_string('confignavshowallcourses', 'admin'), 0));
|
||||
$ADMIN->add('appearance', $temp);
|
||||
|
||||
/* TODO: reimplement editor settings and preferences, editors are now full plugins ;-)
|
||||
// "htmleditor" settingpage
|
||||
$ADMIN->add('appearance', new admin_category('htmleditor', get_string('htmleditor', 'admin')));
|
||||
|
@ -126,6 +126,11 @@ class block_global_navigation_tree extends block_tree {
|
||||
$this->remove_empty_section_branches();
|
||||
}
|
||||
|
||||
// Load the my courses branch if the user has selected to
|
||||
if (!empty($CFG->navhidecategories)) {
|
||||
$this->page->navigation->collapse_course_categories();
|
||||
}
|
||||
|
||||
// Load the my courses branch if the user has selected to
|
||||
if (!empty($this->config->showmycourses) && $this->config->showmycourses=='yes') {
|
||||
$this->showmycourses();
|
||||
@ -359,7 +364,7 @@ class block_global_navigation_tree extends block_tree {
|
||||
// Add a branch labelled something like My Courses
|
||||
$mycoursesbranch = $PAGE->navigation->add(get_string('mycourses'), null,navigation_node::TYPE_CATEGORY, null, 'mycourses');
|
||||
$PAGE->navigation->add_courses($courses, $mycoursesbranch);
|
||||
|
||||
$PAGE->navigation->get($mycoursesbranch)->type = navigation_node::TYPE_SETTING;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -241,6 +241,8 @@ $string['configminpasswordupper'] = 'Passwords must have at least these many upp
|
||||
$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).';
|
||||
@ -645,6 +647,8 @@ $string['mysql416required'] = 'MySQL 4.1.16 is the minimum version required for
|
||||
$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';
|
||||
|
@ -1065,6 +1065,7 @@ $string['namesocial'] = 'section';
|
||||
$string['nametopics'] = 'topic';
|
||||
$string['nameweeks'] = 'week';
|
||||
$string['nameweekscss'] = 'week';
|
||||
$string['navigation'] = 'Navigation';
|
||||
$string['needed'] = 'Needed';
|
||||
$string['never'] = 'Never';
|
||||
$string['neverdeletelogs'] = 'Never delete logs';
|
||||
|
@ -539,6 +539,24 @@ class navigation_node {
|
||||
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.
|
||||
@ -895,7 +913,7 @@ class global_navigation extends navigation_node {
|
||||
* @return bool Returns true
|
||||
*/
|
||||
public function initialise($jsargs = null) {
|
||||
global $PAGE, $SITE;
|
||||
global $PAGE, $SITE, $CFG;
|
||||
if ($this->initialised || during_initial_install()) {
|
||||
return true;
|
||||
}
|
||||
@ -941,7 +959,7 @@ class global_navigation extends navigation_node {
|
||||
* 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 {
|
||||
@ -951,6 +969,9 @@ class global_navigation extends navigation_node {
|
||||
$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();
|
||||
@ -968,6 +989,9 @@ class global_navigation extends navigation_node {
|
||||
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 {
|
||||
@ -984,6 +1008,9 @@ class global_navigation extends navigation_node {
|
||||
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)) {
|
||||
@ -1182,7 +1209,7 @@ class global_navigation extends navigation_node {
|
||||
* @return int
|
||||
*/
|
||||
protected function load_for_activity() {
|
||||
global $PAGE, $DB;
|
||||
global $PAGE, $DB, $CFG;
|
||||
$keys = array();
|
||||
|
||||
$sectionnum = false;
|
||||
@ -1193,6 +1220,10 @@ class global_navigation extends navigation_node {
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($CFG->navshowallcourses)) {
|
||||
$this->load_categories();
|
||||
}
|
||||
|
||||
$depth = $this->load_course_categories($keys);
|
||||
$depth += $this->load_course($keys);
|
||||
$depth += $this->load_course_activities($keys);
|
||||
@ -1312,7 +1343,9 @@ class global_navigation extends navigation_node {
|
||||
// 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);
|
||||
}
|
||||
@ -1563,8 +1596,13 @@ class global_navigation extends navigation_node {
|
||||
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);
|
||||
@ -1626,7 +1664,7 @@ class global_navigation extends navigation_node {
|
||||
$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);
|
||||
@ -1716,6 +1754,17 @@ class global_navigation extends navigation_node {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2170,6 +2219,7 @@ class navbar extends navigation_node {
|
||||
* @return string HTML
|
||||
*/
|
||||
protected function parse_branch_to_html($navarray, $firstnode=true, $moreafterthis=false) {
|
||||
global $CFG;
|
||||
$separator = get_separator();
|
||||
$output = '';
|
||||
if ($firstnode===true) {
|
||||
@ -2189,7 +2239,7 @@ class navbar extends navigation_node {
|
||||
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;
|
||||
@ -2211,8 +2261,10 @@ class navbar extends navigation_node {
|
||||
$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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user