MDL-59688 enrol: Show removed users

When users are automatically removed from the bulk action selection (due to a non-matching enrolment method)
we should show a warning to make it obvious.
This commit is contained in:
Damyon Wiese 2017-08-14 15:01:15 +08:00
parent 27466d7548
commit 80a2937dbe
2 changed files with 17 additions and 2 deletions

View File

@ -139,6 +139,7 @@ $string['unenrolroleusers'] = 'Unenrol users';
$string['uninstallmigrating'] = 'Migrating "{$a}" enrolments'; $string['uninstallmigrating'] = 'Migrating "{$a}" enrolments';
$string['unknowajaxaction'] = 'Unknown action requested'; $string['unknowajaxaction'] = 'Unknown action requested';
$string['unlimitedduration'] = 'Unlimited'; $string['unlimitedduration'] = 'Unlimited';
$string['userremovedfromselectiona'] = 'User "{$a}" was removed from the selection.';
$string['usersearch'] = 'Search '; $string['usersearch'] = 'Search ';
$string['withselectedusers'] = 'With selected users'; $string['withselectedusers'] = 'With selected users';
$string['extremovedaction'] = 'External unenrol action'; $string['extremovedaction'] = 'External unenrol action';

View File

@ -114,6 +114,18 @@ if ($formaction == 'bulkchange.php') {
$users = $manager->get_users_enrolments($userids); $users = $manager->get_users_enrolments($userids);
$removed = array_diff($userids, array_keys($users));
if (!empty($removed)) {
// This manager does not filter by enrolment method - so we can get the removed users details.
$removedmanager = new course_enrolment_manager($PAGE, $course);
$removedusers = $removedmanager->get_users_enrolments($removed);
foreach ($removedusers as $removeduser) {
$msg = get_string('userremovedfromselectiona', 'enrol', fullname($removeduser));
\core\notification::warning($msg);
}
}
// We may have users from any kind of enrolment, we need to filter for the enrolment plugin matching the bulk action. // We may have users from any kind of enrolment, we need to filter for the enrolment plugin matching the bulk action.
$matchesplugin = function($user) use ($plugin) { $matchesplugin = function($user) use ($plugin) {
foreach ($user->enrolments as $enrolment) { foreach ($user->enrolments as $enrolment) {
@ -123,12 +135,14 @@ if ($formaction == 'bulkchange.php') {
} }
return false; return false;
}; };
$users = array_filter($users, $matchesplugin); $filteredusers = array_filter($users, $matchesplugin);
if (empty($users)) { if (empty($filteredusers)) {
redirect($returnurl, get_string('noselectedusers', 'bulkusers')); redirect($returnurl, get_string('noselectedusers', 'bulkusers'));
} }
$users = $filteredusers;
// Get the form for the bulk operation. // Get the form for the bulk operation.
$mform = $operation->get_form($PAGE->url, array('users' => $users)); $mform = $operation->get_form($PAGE->url, array('users' => $users));
// If the mform is false then attempt an immediate process. This may be an immediate action that // If the mform is false then attempt an immediate process. This may be an immediate action that