Get prerequisite modules for a course in moodle

In moodle, we can setup dependency or prequisite for a module. Say if user doesn’t complete a quiz, he cannot take the next lesson. There can be a lot of criteria how we want to set this up. To find out if the user has completed certain quiz for example, we can run an sql as follows:

// $m->id is the module id, $USER->id is the user id.
$sql = "select, gi.itemname from {course_modules} cm, {course_modules_availability} cma, {grade_items} gi, {quiz_attempts} qa where = cma.coursemoduleid and cma.gradeitemid = and gi.iteminstance = qa.quiz and'$m->id' and qa.userid='$USER->id' and qa.state='finished'";

$dep = $DB->get_record_sql($sql);

This db diagram might help:


Author: bpeh

Bernard Peh is a great passioner of web technologies and one of the co-founder of Website Design and Reviews. He works with experienced web designers and developers everyday, developing and designing commercial websites. He specialises mainly in SEO and PHP programming.