穆德尔3.8中角色老师的ID号是多少

时间:2020-06-05 14:43:14

标签: sql moodle

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

我要输入角色老师的ID号,而不是6个。

1 个答案:

答案 0 :(得分:0)

为什么不简单:

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'

其中“ 50”是“课程”的上下文级别。这将显示在课程级别上具有“老师”角色的所有用户,并提供老师的姓名,课程的名称以及课程中存在的所有组的列表(将有完整的行用于每个小组,并且不会考虑老师是否是该小组的成员。

请注意,列表中将仅包括“非编辑教师”,如果您同时希望“教师”和“非编辑教师”,则需要将最后一行更改为:

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