mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
fix course reset unenrollment in to work with roles MDL-7069 ; merged from MOODLE_17_STABLE
This commit is contained in:
parent
01059829c2
commit
20d55a1b7b
@ -2845,38 +2845,42 @@ function reset_course_userdata($data, $showfeedback=true) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delete other stuff
|
// Delete other stuff
|
||||||
|
$coursecontext = get_context_instance(CONTEXT_COURSE, $data->courseid);
|
||||||
|
|
||||||
if (!empty($data->reset_students)) {
|
if (!empty($data->reset_students) or !empty($data->reset_teachers)) {
|
||||||
/// Delete student enrolments
|
$teachers = array_keys(get_users_by_capability($coursecontext, 'moodle/course:update'));
|
||||||
if (delete_records('user_students', 'course', $data->courseid)) {
|
$participants = array_keys(get_users_by_capability($coursecontext, 'moodle/course:view'));
|
||||||
if ($showfeedback) {
|
$students = array_diff($participants, $teachers);
|
||||||
notify($strdeleted .' user_students', 'notifysuccess');
|
|
||||||
|
if (!empty($data->reset_students)) {
|
||||||
|
foreach ($students as $studentid) {
|
||||||
|
role_unassign(0, $studentid, 0, $coursecontext->id);
|
||||||
|
}
|
||||||
|
if ($showfeedback) {
|
||||||
|
notify($strdeleted .' '.get_string('students'), 'notifysuccess');
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$result = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Delete group members (but keep the groups)
|
/// Delete group members (but keep the groups)
|
||||||
if ($groups = get_records('groups', 'courseid', $data->courseid)) {
|
if ($groups = get_records('groups', 'courseid', $data->courseid)) {
|
||||||
foreach ($groups as $group) {
|
foreach ($groups as $group) {
|
||||||
if (delete_records('groups_members', 'groupid', $group->id)) {
|
if (delete_records('groups_members', 'groupid', $group->id)) {
|
||||||
if ($showfeedback) {
|
if ($showfeedback) {
|
||||||
notify($strdeleted .' groups_members', 'notifysuccess');
|
notify($strdeleted .' groups_members', 'notifysuccess');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$result = false;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$result = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($data->reset_teachers)) {
|
if (!empty($data->reset_teachers)) {
|
||||||
if (delete_records('user_teachers', 'course', $data->courseid)) {
|
foreach ($teachers as $teacherid) {
|
||||||
if ($showfeedback) {
|
role_unassign(0, $teacherid, 0, $coursecontext->id);
|
||||||
notify($strdeleted .' user_teachers', 'notifysuccess');
|
}
|
||||||
|
if ($showfeedback) {
|
||||||
|
notify($strdeleted .' '.get_string('teachers'), 'notifysuccess');
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$result = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2916,9 +2920,8 @@ function reset_course_userdata($data, $showfeedback=true) {
|
|||||||
|
|
||||||
// deletes all role assignments, and local override, these have no courseid in table and needs separate process
|
// deletes all role assignments, and local override, these have no courseid in table and needs separate process
|
||||||
$context = get_context_instance(CONTEXT_COURSE, $data->courseid);
|
$context = get_context_instance(CONTEXT_COURSE, $data->courseid);
|
||||||
delete_records('role_assignments', 'contextid', $context->id);
|
|
||||||
delete_records('role_capabilities', 'contextid', $context->id);
|
delete_records('role_capabilities', 'contextid', $context->id);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user