To create customised menu, we need to be able to run custom queries. Say I want to get all the modules for a course that I am enrolled, a query like this helps.
// say $course->id is the id of the course you want to look at $sql = "select cm.id, m.name, cm.instance from {modules} m, {course_modules} cm where cm.module=m.id and cm.course = '$course->id' and cm.id in (SELECT cs.sequence FROM {course_sections} cs where cs.course = '$course->id')"; $res = $DB->get_records_sql($sql); print_r($res);
I’ve created a simple relationship table. Hopefully, it helps.