diff --git a/admin/settings/appearance.php b/admin/settings/appearance.php index dc2ba27ca43..6b251fba81d 100644 --- a/admin/settings/appearance.php +++ b/admin/settings/appearance.php @@ -91,6 +91,7 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page $temp->add(new admin_setting_configcheckbox('navshowcategories', get_string('navshowcategories', 'admin'), get_string('confignavshowcategories', 'admin'), 1)); $temp->add(new admin_setting_configcheckbox('navshowallcourses', get_string('navshowallcourses', 'admin'), get_string('confignavshowallcourses', 'admin'), 0)); $temp->add(new admin_setting_configtext('navcourselimit',get_string('navcourselimit','admin'),get_string('confignavcourselimit', 'admin'),20,PARAM_INT)); + $temp->add(new admin_setting_configcheckbox('navlinkcoursesections', get_string('navlinkcoursesections', 'admin'), get_string('navlinkcoursesections_help', 'admin'), 0)); $ADMIN->add('appearance', $temp); diff --git a/course/format/topics/lib.php b/course/format/topics/lib.php index c80b5180a1c..9bd94d4a153 100644 --- a/course/format/topics/lib.php +++ b/course/format/topics/lib.php @@ -90,3 +90,14 @@ function callback_topics_ajax_support() { $ajaxsupport->testedbrowsers = array('MSIE' => 6.0, 'Gecko' => 20061111, 'Safari' => 531, 'Chrome' => 6.0); return $ajaxsupport; } + +/** + * Returns a URL to arrive directly at a section + * + * @param int $courseid The id of the course to get the link for + * @param int $sectionnum The section number to jump to + * @return moodle_url + */ +function callback_topics_get_section_url($courseid, $sectionnum) { + return new moodle_url('/course/view.php', array('id' => $courseid, 'topic' => $sectionnum)); +} \ No newline at end of file diff --git a/course/format/weeks/lib.php b/course/format/weeks/lib.php index e37454f38ff..34fd5010ed6 100644 --- a/course/format/weeks/lib.php +++ b/course/format/weeks/lib.php @@ -112,3 +112,14 @@ function callback_weeks_ajax_support() { $ajaxsupport->testedbrowsers = array('MSIE' => 6.0, 'Gecko' => 20061111, 'Safari' => 531, 'Chrome' => 6.0); return $ajaxsupport; } + +/** + * Returns a URL to arrive directly at a section + * + * @param int $courseid The id of the course to get the link for + * @param int $sectionnum The section number to jump to + * @return moodle_url + */ +function callback_weeks_get_section_url($courseid, $sectionnum) { + return new moodle_url('/course/view.php', array('id' => $courseid, 'week' => $sectionnum)); +} diff --git a/lang/en/admin.php b/lang/en/admin.php index bf5b8b05a92..77021d920fb 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -732,6 +732,8 @@ $string['mysql416bypassed'] = 'However, if your site is using iso-8859-1 (latin) $string['mysql416required'] = 'MySQL 4.1.16 is the minimum version required for Moodle 1.6 in order to guarantee that all data can be converted to UTF-8 in the future.'; $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.'; $string['navcourselimit'] = 'Course limit'; +$string['navlinkcoursesections'] = 'Link course sections'; +$string['navlinkcoursesections_help'] = 'If enabled course sections will be shown as links within the navigation.'; $string['navshowallcourses'] = 'Show all courses'; $string['navshowcategories'] = 'Show course categories'; $string['neverdeleteruns'] = 'Never delete runs'; diff --git a/lib/navigationlib.php b/lib/navigationlib.php index c76963bb50b..69dd5a9f97d 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -1635,9 +1635,20 @@ class global_navigation extends navigation_node { $namingfunction = 'callback_'.$courseformat.'_get_section_name'; $namingfunctionexists = (function_exists($namingfunction)); - $activesection = course_get_display($course->id); + $viewhiddensections = has_capability('moodle/course:viewhiddensections', $this->page->context); + $urlfunction = 'callback_'.$courseformat.'_get_section_url'; + if (empty($CFG->navlinkcoursesections) || !function_exists($urlfunction)) { + $urlfunction = null; + } + + $keyfunction = 'callback_'.$courseformat.'_request_key'; + $key = course_get_display($course->id); + if (defined('AJAX_SCRIPT') && AJAX_SCRIPT == '0' && function_exists($keyfunction) && $this->page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE)) { + $key = optional_param($keyfunction(), $key, PARAM_INT); + } + $navigationsections = array(); foreach ($sections as $sectionid => $section) { $section = clone($section); @@ -1652,13 +1663,16 @@ class global_navigation extends navigation_node { } else { $sectionname = get_string('section').' '.$section->section; } - //$url = new moodle_url('/course/view.php', array('id'=>$course->id)); + $url = null; + if (!empty($urlfunction)) { + $url = $urlfunction($course->id, $section->section); + } $sectionnode = $coursenode->add($sectionname, $url, navigation_node::TYPE_SECTION, null, $section->id); $sectionnode->nodetype = navigation_node::NODETYPE_BRANCH; $sectionnode->hidden = (!$section->visible); - if ($this->page->context->contextlevel != CONTEXT_MODULE && $section->hasactivites && ($sectionnode->isactive || ($activesection && $section->section == $activesection))) { - $sectionnode->force_open(); + if ($key != '0' && $section->section != '0' && $section->section == $key && $this->page->context->contextlevel != CONTEXT_MODULE && $section->hasactivites) { + $sectionnode->make_active(); $this->load_section_activities($sectionnode, $section->section, $activities); } $section->sectionnode = $sectionnode;