Note: You are currently viewing documentation for Moodle 1.9. Up-to-date documentation for the latest stable version is available here: course display.

course display

From MoodleDocs

an old way to get roles of users in a course.

(as far as i can understand the code, it is deprecated)

and as suggested by Tim Hunt:

mdl_course_display is wrong. You need role_assignments, which means you also need contexts. Something like

SELECT * FROM mdl_user u
JOIN mdl_role_assignments ra ON ra.userid = u.id
JOIN mdl_role r ON ra.roleid = r.id
JOIN mdl_context con ON ra.contextid = con.id
JOIN mdl_course c ON c.id = con.instanceid AND con.contextlevel = 50
WHERE r.shortname = 'student' AND c.id = XXX

will get you all the students in a course. mdl_context.instanceid points to different things depending on mdl_context.contextlevel. 50 means course, the other levels can be looked up in the accesslib.php code here, For example, mdl_context.contextlevel 70 is modules, then instanceid points to the mdl_course_modules table.

If you really want to understand this, you need to read the Development:Roles documentation.