Commit 7a27c901 authored by Willian Mano's avatar Willian Mano
Browse files

MDL-62485 enrol: Success message after enroll/unenroll user in a course

parent 9f997f9b
...@@ -157,8 +157,14 @@ switch ($action) { ...@@ -157,8 +157,14 @@ switch ($action) {
foreach ($users as $user) { foreach ($users as $user) {
$plugin->enrol_user($instance, $user->id, $roleid, $timestart, $timeend, null, $recovergrades); $plugin->enrol_user($instance, $user->id, $roleid, $timestart, $timeend, null, $recovergrades);
} }
$counter = count($users);
foreach ($cohorts as $cohort) { foreach ($cohorts as $cohort) {
$plugin->enrol_cohort($instance, $cohort->id, $roleid, $timestart, $timeend, null, $recovergrades); $totalenrolledusers = $plugin->enrol_cohort($instance, $cohort->id, $roleid, $timestart, $timeend, null, $recovergrades);
$counter += $totalenrolledusers;
}
// Display a notification message after the bulk user enrollment.
if ($counter > 0) {
\core\notification::info(get_string('totalenrolledusers', 'enrol', $counter));
} }
} else { } else {
throw new enrol_ajax_exception('enrolnotpermitted'); throw new enrol_ajax_exception('enrolnotpermitted');
......
...@@ -502,6 +502,7 @@ class enrol_manual_plugin extends enrol_plugin { ...@@ -502,6 +502,7 @@ class enrol_manual_plugin extends enrol_plugin {
* @param int $timeend 0 means forever * @param int $timeend 0 means forever
* @param int $status default to ENROL_USER_ACTIVE for new enrolments, no change by default in updates * @param int $status default to ENROL_USER_ACTIVE for new enrolments, no change by default in updates
* @param bool $recovergrades restore grade history * @param bool $recovergrades restore grade history
* @return int The number of enrolled cohort users
*/ */
public function enrol_cohort(stdClass $instance, $cohortid, $roleid = null, $timestart = 0, $timeend = 0, $status = null, $recovergrades = null) { public function enrol_cohort(stdClass $instance, $cohortid, $roleid = null, $timestart = 0, $timeend = 0, $status = null, $recovergrades = null) {
global $DB; global $DB;
...@@ -514,6 +515,7 @@ class enrol_manual_plugin extends enrol_plugin { ...@@ -514,6 +515,7 @@ class enrol_manual_plugin extends enrol_plugin {
foreach ($members as $userid) { foreach ($members as $userid) {
$this->enrol_user($instance, $userid, $roleid, $timestart, $timeend, $status, $recovergrades); $this->enrol_user($instance, $userid, $roleid, $timestart, $timeend, $status, $recovergrades);
} }
return count($members);
} }
/** /**
......
...@@ -350,20 +350,24 @@ class enrol_manual_deleteselectedusers_operation extends enrol_bulk_enrolment_op ...@@ -350,20 +350,24 @@ class enrol_manual_deleteselectedusers_operation extends enrol_bulk_enrolment_op
* @param stdClass $properties The data returned by the form. * @param stdClass $properties The data returned by the form.
*/ */
public function process(course_enrolment_manager $manager, array $users, stdClass $properties) { public function process(course_enrolment_manager $manager, array $users, stdClass $properties) {
global $DB;
if (!has_capability("enrol/manual:unenrol", $manager->get_context())) { if (!has_capability("enrol/manual:unenrol", $manager->get_context())) {
return false; return false;
} }
$counter = 0;
foreach ($users as $user) { foreach ($users as $user) {
foreach ($user->enrolments as $enrolment) { foreach ($user->enrolments as $enrolment) {
$plugin = $enrolment->enrolmentplugin; $plugin = $enrolment->enrolmentplugin;
$instance = $enrolment->enrolmentinstance; $instance = $enrolment->enrolmentinstance;
if ($plugin->allow_unenrol_user($instance, $enrolment)) { if ($plugin->allow_unenrol_user($instance, $enrolment)) {
$plugin->unenrol_user($instance, $user->id); $plugin->unenrol_user($instance, $user->id);
$counter++;
} }
} }
} }
// Display a notification message after the bulk user unenrollment.
if ($counter > 0) {
\core\notification::info(get_string('totalunenrolledusers', 'enrol', $counter));
}
return true; return true;
} }
} }
......
...@@ -124,6 +124,7 @@ Feature: Teacher can search and enrol users one by one into the course ...@@ -124,6 +124,7 @@ Feature: Teacher can search and enrol users one by one into the course
And I should see "Student 001" And I should see "Student 001"
And I click on "Enrol users" "button" in the "Enrol users" "dialogue" And I click on "Enrol users" "button" in the "Enrol users" "dialogue"
Then I should see "Active" in the "Student 001" "table_row" Then I should see "Active" in the "Student 001" "table_row"
And I should see "1 enrolled users"
@javascript @javascript
Scenario: Searching for a non-existing user Scenario: Searching for a non-existing user
......
...@@ -157,6 +157,8 @@ class enrol_self_plugin extends enrol_plugin { ...@@ -157,6 +157,8 @@ class enrol_self_plugin extends enrol_plugin {
$this->enrol_user($instance, $USER->id, $instance->roleid, $timestart, $timeend); $this->enrol_user($instance, $USER->id, $instance->roleid, $timestart, $timeend);
\core\notification::success(get_string('youenrolledincourse', 'enrol'));
if ($instance->password and $instance->customint1 and $data->enrolpassword !== $instance->password) { if ($instance->password and $instance->customint1 and $data->enrolpassword !== $instance->password) {
// It must be a group enrolment, let's assign group too. // It must be a group enrolment, let's assign group too.
$groups = $DB->get_records('groups', array('courseid'=>$instance->courseid), 'id', 'id, enrolmentkey'); $groups = $DB->get_records('groups', array('courseid'=>$instance->courseid), 'id', 'id, enrolmentkey');
......
...@@ -50,6 +50,8 @@ $PAGE->set_title($plugin->get_instance_name($instance)); ...@@ -50,6 +50,8 @@ $PAGE->set_title($plugin->get_instance_name($instance));
if ($confirm and confirm_sesskey()) { if ($confirm and confirm_sesskey()) {
$plugin->unenrol_user($instance, $USER->id); $plugin->unenrol_user($instance, $USER->id);
\core\notification::success(get_string('youunenrolledfromcourse', 'enrol', $course->fullname));
redirect(new moodle_url('/index.php')); redirect(new moodle_url('/index.php'));
} }
......
This files describes API changes in /enrol/* - plugins, This files describes API changes in /enrol/* - plugins,
information provided here is intended especially for developers. information provided here is intended especially for developers.
=== 3.8 ===
* Function enrol_manual_plugin::enrol_cohort now return the number of enrolled cohort users.
=== 3.7 === === 3.7 ===
* Functions get_potential_users() and search_other_users() now return more information to avoid extra count query: * Functions get_potential_users() and search_other_users() now return more information to avoid extra count query:
......
...@@ -132,6 +132,7 @@ $string['synced'] = 'Synced'; ...@@ -132,6 +132,7 @@ $string['synced'] = 'Synced';
$string['testsettings'] = 'Test settings'; $string['testsettings'] = 'Test settings';
$string['testsettingsheading'] = 'Test enrol settings - {$a}'; $string['testsettingsheading'] = 'Test enrol settings - {$a}';
$string['totalenrolledusers'] = '{$a} enrolled users'; $string['totalenrolledusers'] = '{$a} enrolled users';
$string['totalunenrolledusers'] = '{$a} unenrolled users';
$string['totalotherusers'] = '{$a} other users'; $string['totalotherusers'] = '{$a} other users';
$string['unassignnotpermitted'] = 'You do not have permission to unassign roles in this course'; $string['unassignnotpermitted'] = 'You do not have permission to unassign roles in this course';
$string['unenrol'] = 'Unenrol'; $string['unenrol'] = 'Unenrol';
...@@ -161,3 +162,5 @@ $string['privacy:metadata:user_enrolments:timeend'] = 'The time when the user en ...@@ -161,3 +162,5 @@ $string['privacy:metadata:user_enrolments:timeend'] = 'The time when the user en
$string['privacy:metadata:user_enrolments:timestart'] = 'The time when the user enrolment starts'; $string['privacy:metadata:user_enrolments:timestart'] = 'The time when the user enrolment starts';
$string['privacy:metadata:user_enrolments:timemodified'] = 'The time when the user enrolment was modified'; $string['privacy:metadata:user_enrolments:timemodified'] = 'The time when the user enrolment was modified';
$string['privacy:metadata:user_enrolments:userid'] = 'The ID of the user'; $string['privacy:metadata:user_enrolments:userid'] = 'The ID of the user';
$string['youenrolledincourse'] = 'You are enrolled in the course.';
$string['youunenrolledfromcourse'] = 'You are unenrolled from the course "{$a}".';
...@@ -46,6 +46,7 @@ Feature: Bulk enrolments ...@@ -46,6 +46,7 @@ Feature: Bulk enrolments
Then I should not see "Student 1" Then I should not see "Student 1"
And I should not see "Student 2" And I should not see "Student 2"
And I should not see "Teacher 1" And I should not see "Teacher 1"
And I should see "3 unenrolled users"
@javascript @javascript
Scenario: Bulk edit enrolment for deleted user Scenario: Bulk edit enrolment for deleted user
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment