简体   繁体   中英

What is the id number for role teacher in moodle 3.8

SELECT c.fullname, c.shortname, g.name, u.firstname, u.lastname, r.shortname
FROM prefix_course AS c
JOIN prefix_role_assignments AS ra
JOIN prefix_groups AS g ON c.id = g.courseid
JOIN prefix_role AS r
JOIN prefix_user AS u 
WHERE c.groupmode > 0 AND WHERE ra.roleid > 6

instead of 6 i want to enter id number of role teacher.

Why not simply:

SELECT c.fullname, c.shortname, g.name, u.firstname, u.lastname, r.shortname
FROM prefix_course AS c
JOIN prefix_context ctx ON ctx.instanceid = c.id AND ctx.contextlevel = 50
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id
JOIN prefix_groups AS g ON c.id = g.courseid
JOIN prefix_role AS r ON r.id = ra.roleid
JOIN prefix_user AS u ON u.id = ra.userid
WHERE c.groupmode > 0 AND r.shortname = 'teacher'

Where '50' is the context level for 'course'. This will show all the users who have the role 'teacher' at the course level, giving the name of the teacher, the name of the course and a list of all the groups that exist in the course (there will be a complete row for each group and it will not take into account whether or not the teacher is a member of that group).

Note that this will only include 'Non-editing teachers' in the list, if you wanted both 'Teachers' and 'Non-editing teachers', you would need to change the last line to:

WHERE c.groupmode > 0 AND (r.shortname = 'teacher' OR r.shortname = 'editingteacher')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM