Skip to content

Commit

Permalink
MDL-62485 enrol: Success message after enroll/unenroll user in a course
Browse files Browse the repository at this point in the history
  • Loading branch information
willianmano committed Oct 24, 2019
1 parent 9f997f9 commit 7a27c90
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 3 deletions.
8 changes: 7 additions & 1 deletion enrol/manual/ajax.php
Expand Up @@ -157,8 +157,14 @@
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');
Expand Down
2 changes: 2 additions & 0 deletions enrol/manual/lib.php
Expand Up @@ -502,6 +502,7 @@ public function can_hide_show_instance($instance) {
* @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;
Expand All @@ -514,6 +515,7 @@ public function enrol_cohort(stdClass $instance, $cohortid, $roleid = null, $tim
foreach ($members as $userid) {
$this->enrol_user($instance, $userid, $roleid, $timestart, $timeend, $status, $recovergrades);
}
return count($members);
}

/**
Expand Down
8 changes: 6 additions & 2 deletions enrol/manual/locallib.php
Expand Up @@ -350,20 +350,24 @@ public function get_form($defaultaction = null, $defaultcustomdata = null) {
* @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;
}
}
Expand Down
1 change: 1 addition & 0 deletions enrol/manual/tests/behat/quickenrolment.feature
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions enrol/self/lib.php
Expand Up @@ -157,6 +157,8 @@ public function enrol_self(stdClass $instance, $data = null) {

$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');
Expand Down
2 changes: 2 additions & 0 deletions enrol/self/unenrolself.php
Expand Up @@ -50,6 +50,8 @@
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'));
}

Expand Down
4 changes: 4 additions & 0 deletions 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:
Expand Down
3 changes: 3 additions & 0 deletions lang/en/enrol.php
Expand Up @@ -132,6 +132,7 @@
$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';
Expand Down Expand Up @@ -161,3 +162,5 @@
$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}".';
1 change: 1 addition & 0 deletions user/tests/behat/bulk_editenrolment.feature
Expand Up @@ -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
Expand Down

0 comments on commit 7a27c90

Please sign in to comment.