我需要立即取消注册特定类别中所有类(class)的所有用户(选择在我的 moodle 网站中按名称或简称)。 我认为 SQL 语句就是执行此操作的方法。
类(class)不为空,因此无法删除所有类(class)。
谢谢
最佳答案
我没有测试以下解决方案,但它应该会产生预期的效果:
require($CFG->libdir . '/coursecatlib.php');
require($CFG->libdir . '/enrollib.php');
$categoryid = 0; // Replace with the desired category ID.
$category = coursecat::get($categoryid);
foreach ($category->get_courses() as $course) {
// Simulates the deletion of the course, a better solution is to copy
// the logic from `enrol_course_delete` here directly.
enrol_course_delete($course);
}
上面的脚本可能需要一段时间,因此您可能应该从命令行执行它。
您可以使用以下方法循环子类别:
$categories = $category->get_children();
foreach ($categories as $category) {
}
要按短名称获取类别 ID,请使用以下命令:
$name = "My category";
$categoryid = $DB->get_field('course_categories', 'id', array('name' => $name), MUST_EXIST);
请注意,类别可以具有相同的名称,您应该使用类别idnumber
。
关于mysql - 使用 SQL 取消注册某个类别中的 Moodle 用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39948520/