Skip to content

Commit

Permalink
MDL-26477 Added a setting to display course sections as links within …
Browse files Browse the repository at this point in the history
…the navigation
  • Loading branch information
Sam Hemelryk authored and skodak committed Aug 2, 2011
1 parent 4a47631 commit ad47009
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions admin/settings/appearance.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
$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);

Expand Down
11 changes: 11 additions & 0 deletions course/format/topics/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
11 changes: 11 additions & 0 deletions course/format/weeks/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
2 changes: 2 additions & 0 deletions lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,8 @@
$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';
Expand Down
22 changes: 18 additions & 4 deletions lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1635,9 +1635,20 @@ public function load_generic_course_sections(stdClass $course, 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);
Expand All @@ -1652,13 +1663,16 @@ public function load_generic_course_sections(stdClass $course, 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;
Expand Down

0 comments on commit ad47009

Please sign in to comment.