From 7a27c90102f8714f90d606c75f5182648befc36c Mon Sep 17 00:00:00 2001 From: Willian Mano Date: Thu, 24 Oct 2019 13:43:27 -0300 Subject: [PATCH] MDL-62485 enrol: Success message after enroll/unenroll user in a course --- enrol/manual/ajax.php | 8 +++++++- enrol/manual/lib.php | 2 ++ enrol/manual/locallib.php | 8 ++++++-- enrol/manual/tests/behat/quickenrolment.feature | 1 + enrol/self/lib.php | 2 ++ enrol/self/unenrolself.php | 2 ++ enrol/upgrade.txt | 4 ++++ lang/en/enrol.php | 3 +++ user/tests/behat/bulk_editenrolment.feature | 1 + 9 files changed, 28 insertions(+), 3 deletions(-) diff --git a/enrol/manual/ajax.php b/enrol/manual/ajax.php index 5378aae6154..ba73f21d97a 100644 --- a/enrol/manual/ajax.php +++ b/enrol/manual/ajax.php @@ -157,8 +157,14 @@ switch ($action) { foreach ($users as $user) { $plugin->enrol_user($instance, $user->id, $roleid, $timestart, $timeend, null, $recovergrades); } + $counter = count($users); 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 { throw new enrol_ajax_exception('enrolnotpermitted'); diff --git a/enrol/manual/lib.php b/enrol/manual/lib.php index a346a08a8b5..24e312260ad 100644 --- a/enrol/manual/lib.php +++ b/enrol/manual/lib.php @@ -502,6 +502,7 @@ class enrol_manual_plugin extends enrol_plugin { * @param int $timeend 0 means forever * @param int $status default to ENROL_USER_ACTIVE for new enrolments, no change by default in updates * @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) { global $DB; @@ -514,6 +515,7 @@ class enrol_manual_plugin extends enrol_plugin { foreach ($members as $userid) { $this->enrol_user($instance, $userid, $roleid, $timestart, $timeend, $status, $recovergrades); } + return count($members); } /** diff --git a/enrol/manual/locallib.php b/enrol/manual/locallib.php index 89b99df1a0a..7324b6490c8 100644 --- a/enrol/manual/locallib.php +++ b/enrol/manual/locallib.php @@ -350,20 +350,24 @@ class enrol_manual_deleteselectedusers_operation extends enrol_bulk_enrolment_op * @param stdClass $properties The data returned by the form. */ public function process(course_enrolment_manager $manager, array $users, stdClass $properties) { - global $DB; - if (!has_capability("enrol/manual:unenrol", $manager->get_context())) { return false; } + $counter = 0; foreach ($users as $user) { foreach ($user->enrolments as $enrolment) { $plugin = $enrolment->enrolmentplugin; $instance = $enrolment->enrolmentinstance; if ($plugin->allow_unenrol_user($instance, $enrolment)) { $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; } } diff --git a/enrol/manual/tests/behat/quickenrolment.feature b/enrol/manual/tests/behat/quickenrolment.feature index 2208c7ca6ff..f2f3f6cc139 100644 --- a/enrol/manual/tests/behat/quickenrolment.feature +++ b/enrol/manual/tests/behat/quickenrolment.feature @@ -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 click on "Enrol users" "button" in the "Enrol users" "dialogue" Then I should see "Active" in the "Student 001" "table_row" + And I should see "1 enrolled users" @javascript Scenario: Searching for a non-existing user diff --git a/enrol/self/lib.php b/enrol/self/lib.php index bac388754b9..f3bc7b50237 100644 --- a/enrol/self/lib.php +++ b/enrol/self/lib.php @@ -157,6 +157,8 @@ class enrol_self_plugin extends enrol_plugin { $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) { // It must be a group enrolment, let's assign group too. $groups = $DB->get_records('groups', array('courseid'=>$instance->courseid), 'id', 'id, enrolmentkey'); diff --git a/enrol/self/unenrolself.php b/enrol/self/unenrolself.php index 2da62ee2ffe..007caabc008 100644 --- a/enrol/self/unenrolself.php +++ b/enrol/self/unenrolself.php @@ -50,6 +50,8 @@ $PAGE->set_title($plugin->get_instance_name($instance)); if ($confirm and confirm_sesskey()) { $plugin->unenrol_user($instance, $USER->id); + \core\notification::success(get_string('youunenrolledfromcourse', 'enrol', $course->fullname)); + redirect(new moodle_url('/index.php')); } diff --git a/enrol/upgrade.txt b/enrol/upgrade.txt index 892767bf0eb..bfec2ff74c7 100644 --- a/enrol/upgrade.txt +++ b/enrol/upgrade.txt @@ -1,6 +1,10 @@ This files describes API changes in /enrol/* - plugins, 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 === * Functions get_potential_users() and search_other_users() now return more information to avoid extra count query: diff --git a/lang/en/enrol.php b/lang/en/enrol.php index bdb64e4fb76..9e704416254 100644 --- a/lang/en/enrol.php +++ b/lang/en/enrol.php @@ -132,6 +132,7 @@ $string['synced'] = 'Synced'; $string['testsettings'] = 'Test settings'; $string['testsettingsheading'] = 'Test enrol settings - {$a}'; $string['totalenrolledusers'] = '{$a} enrolled users'; +$string['totalunenrolledusers'] = '{$a} unenrolled users'; $string['totalotherusers'] = '{$a} other users'; $string['unassignnotpermitted'] = 'You do not have permission to unassign roles in this course'; $string['unenrol'] = 'Unenrol'; @@ -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:timemodified'] = 'The time when the user enrolment was modified'; $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}".'; diff --git a/user/tests/behat/bulk_editenrolment.feature b/user/tests/behat/bulk_editenrolment.feature index 47f58d9ad95..7786fff4299 100644 --- a/user/tests/behat/bulk_editenrolment.feature +++ b/user/tests/behat/bulk_editenrolment.feature @@ -46,6 +46,7 @@ Feature: Bulk enrolments Then I should not see "Student 1" And I should not see "Student 2" And I should not see "Teacher 1" + And I should see "3 unenrolled users" @javascript Scenario: Bulk edit enrolment for deleted user