我需要以编程方式从与群组相关的所有内容中删除用户,例如笔记和所有内容。我从表mdl_user_enrollments中删除了用户,但他仍然注册了,当他登录时,仍然显示该组的所有数据。我想删除该用户与该群组相关的所有内容,因此我可以再次注册他,并且他将从头开始。
答案 0 :(得分:1)
不知道这是否正是您正在寻找的,但是下面的过程会从用户中删除用户数据。并非所有已安装的moodle模块都会因每个Moodle配置而异,但您也可以为额外的模块添加一些查询。
CREATE DEFINER = `your_user`@`%` PROCEDURE `RemoveUserDataFromCourse`(IN `c_id` int,IN `u_id` int)
BEGIN
# ENROLLMENT
DELETE FROM mdl_user_enrolments WHERE userid = u_id AND enrolid IN (SELECT id FROM mdl_enrol WHERE courseid = c_id);
# LOG, EVENT, POSTS
DELETE FROM mdl_log WHERE course = c_id AND userid = u_id;
DELETE FROM mdl_event WHERE courseid = c_id AND userid = u_id;
DELETE FROM mdl_post WHERE courseid = c_id AND userid = u_id;
# Course completion
DELETE FROM mdl_course_modules_completion WHERE coursemoduleid IN (SELECT id FROM mdl_course_modules WHERE course= c_id and userid=u_id);
DELETE FROM mdl_course_completions WHERE course = c_id AND userid = u_id;
DELETE FROM mdl_course_completion_crit_compl WHERE course = c_id AND userid = u_id;
# Grades from all modules
DELETE FROM mdl_grade_grades WHERE userid = u_id and itemid IN (SELECT id FROM mdl_grade_items WHERE courseid = c_id);
# MODULES
# ASSIGNMENTS
DELETE FROM mdl_assign_grades WHERE userid = u_id AND assignment IN (SELECT id FROM mdl_assign WHERE course = c_id);
# QUIZ
DELETE FROM mdl_quiz_attempts WHERE userid = u_id AND quiz IN (SELECT id FROM mdl_quiz WHERE course = c_id);
DELETE FROM mdl_quiz_grades WHERE userid = u_id AND quiz IN (SELECT id FROM mdl_quiz WHERE course = c_id);
# SCORM
DELETE FROM mdl_scorm_scoes_track WHERE userid = u_id AND scormid IN (SELECT id FROM mdl_scorm WHERE course = c_id);
# CHECK LIST
DELETE FROM mdl_checklist_check WHERE userid = u_id AND item IN ( SELECT mci.id FROM mdl_checklist mc INNER JOIN mdl_checklist_item mci ON mci.checklist = mc.id WHERE course = c_id );
DELETE FROM mdl_checklist_comment WHERE userid = u_id AND itemid IN ( SELECT mci.id FROM mdl_checklist mc INNER JOIN mdl_checklist_item mci ON mci.checklist = mc.id WHERE course = c_id );
# CHOICE
DELETE FROM mdl_choice_answers WHERE userid = u_id AND choiceid IN (SELECT id FROM mdl_choice WHERE course = c_id);
END;
此过程基于course / reset.php所做的操作,它接收两个参数:课程ID和用户ID。根据您的Moodle配置添加/删除与模块相关的查询。