Hi,
I cannot seem to get a My Courses dropdown menu working in 2.6.
I have based my work till now on Extending the theme custom menu - the Courses dropdown works fine, but no luck displaying only My Courses.
Has anyone perhaps implemented this successfully in Moodle 2.6?
Here is what I have so far:
(apologies, I cannot seem to get the code formatted properly in the forum)
<?php
class theme_testtheme_core_renderer extends core_renderer {
protected function render_custom_menu(custom_menu $menu) {
global $CFG;
require_once($CFG->dirroot.'/course/lib.php');
$branch = $menu->add(get_string('courses', 'theme_testtheme'), null, null, 2);
$categorytree = get_course_category_tree();
foreach ($categorytree as $category) {
$this->add_category_to_custommenu($branch, $category);
}
return parent::render_custom_menu($menu);
$this->render_mycourses_custom_menu($menu, 12000) ;
}
protected function add_category_to_custommenu(custom_menu_item $parent, stdClass $category) {
$branch = $parent->add($category->name, new moodle_url('/course/category.php', array('id' => $category->id)));
if (!empty($category->categories)) {
foreach ($category->categories as $subcategory) {
$this->add_category_to_custommenu($branch, $subcategory);
}
}
if (!empty($category->courses)) {
foreach ($category->courses as $course) {
$branch->add($course->shortname, new moodle_url('/course/view.php', array('id' => $course->id)), $course->fullname);
}
}
}
protected function render_mycourses_custom_menu(custom_menu_item $menu, $position) {
global $CFG;
require_once($CFG->dirroot.'/course/lib.php');
// Moodle 2.4 doesn't appear to support $mycourses = $this->page->navigation->get('mycourses'); so
if (isloggedin() && !isguestuser() && $mycourses = enrol_get_my_courses(NULL, 'visible DESC, fullname ASC')) { //which does work
$branchlabel = get_string('mycourses') ;
$branchurl = new moodle_url('/course/index.php');
$branchtitle = $branchlabel;
$branchsort = 8000 ; // lower numbers = higher priority e.g. move this item to the left on the Custom Menu
$branch = $menu->add($branchlabel, $branchurl, $branchtitle, $branchsort);
foreach ($mycourses as $mycourse) {
$branch->add($mycourse->shortname, new moodle_url('/course/view.php', array('id' => $mycourse->id)), $mycourse->fullname);
}
}
}
}
Thanks!