Hi developers
How please do I get the URL for each section in a course?
Background:
I have created a function in a theme/new_theme/renderers.php to add the current class and sections in the custom menu.
It works good, except I can't find a way to get the section URL for each section. The section info I get in $modinfo doesn't appear to have the navigation/URL so I tried calling a function in course/format/lib.php called "get_view_url)
However, I am mixing my objects and methods with function calls, so that does not appear to be the right way.
Code to date:
<?php
class theme_standardplus_core_renderer extends core_renderer {
protected function render_custom_menu(custom_menu $menu) {
global $CFG;
require_once($CFG->dirroot.'/course/lib.php');
require_once($CFG->dirroot.'/course/format/lib.php');
$position_currentcourse = 12000 ;
if (isloggedin()&& !isguestuser()) {
$currentcourse=$PAGE->course ;
if(!$currentcourse || $currentcourse->id == SITEID) {
return ; //No course is set or we are in course SITEID (not a real course) so return with no change
}
$courseurl = new moodle_url('/course/view.php', array('id' => $currentcourse->id)); //Course Home URL
$branch = $menu->add('Current Course', $courseurl, $currentcourse->fullname, $position_currentcourse); //Add Parent Custom Menu Item Title - Current Course
$modinfo = get_fast_modinfo($currentcourse); //do we want current course or ->id ?
$mods = $modinfo->get_cms();
$coursesections = $modinfo->get_section_info_all();
foreach($coursesections as $section) {
/* I need the URL for the section, but the next line of code fails with these calls/methods:
get_view_url($section,null)
this->get_view_url($section,null)
page->get_view_url($section,null)
modinfo->get_view_url($section,null)
Strangely, get_section_name($currentcourse,$section) works fine and if I substitute $courseurl it works fine, I just have the wrong URL
*/
$branch->add(get_section_name($currentcourse,$section), $this->get_view_url($section,null), 'some morewords');
}
}
}
}