This commit is contained in:
Huong Nguyen
2025-09-17 08:40:39 +07:00
4 changed files with 50 additions and 0 deletions
+5
View File
@@ -98,6 +98,7 @@ switch ($action) {
$startdateselect = optional_param_array('startdateselect', [], PARAM_INT);
$recovergrades = optional_param('recovergrades', 0, PARAM_INT);
$timeend = optional_param_array('timeend', [], PARAM_INT);
$group = optional_param('group', null, PARAM_INT);
if (empty($roleid)) {
$roleid = null;
@@ -153,6 +154,7 @@ switch ($action) {
$mform = new enrol_manual_enrol_users_form(null, (object)["context" => $context]);
$userenroldata = [
'group' => $group,
'startdate' => $timestart,
'timeend' => $timeend,
];
@@ -175,6 +177,9 @@ switch ($action) {
if ($plugin->allow_enrol($instance) && has_capability('enrol/'.$plugin->get_name().':enrol', $context)) {
foreach ($users as $user) {
$plugin->enrol_user($instance, $user->id, $roleid, $timestart, $timeend, null, $recovergrades);
if ($group && has_capability('moodle/course:managegroups', $context)) {
groups_add_member($group, $user->id);
}
}
$outcome->count += count($users);
foreach ($cohorts as $cohort) {
@@ -122,6 +122,29 @@ class enrol_manual_enrol_users_form extends moodleform {
$mform->addElement('select', 'roletoassign', get_string('assignrole', 'enrol_manual'), $roles);
$mform->setDefault('roletoassign', $instance->roleid);
if (has_capability('moodle/course:managegroups', $context)) {
$options = [];
foreach (groups_get_all_groups($course->id) as $group) {
$options[$group->id] = $group->name;
}
if ($options) {
$mform->addElement(
'checkbox',
'showgroups',
get_string('addtogroup', 'enrol_manual'),
get_string('showgroups', 'enrol_manual'),
);
$mform->addElement(
'select',
'group',
null,
$options,
);
$mform->hideIf('group', 'showgroups', 'notchecked');
}
}
$mform->addAdvancedStatusElement('main');
$mform->addElement('checkbox', 'recovergrades', get_string('recovergrades', 'enrol'));
@@ -22,6 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['addtogroup'] = 'Add to group';
$string['advanced'] = 'Advanced';
$string['alterstatus'] = 'Alter status';
$string['altertimeend'] = 'Alter end time';
@@ -68,6 +69,7 @@ $string['selection'] = 'Selection';
$string['selectusers'] = 'Select users';
$string['selectcohorts'] = 'Select cohorts';
$string['sendexpirynotificationstask'] = "Manual enrolment send expiry notifications task";
$string['showgroups'] = 'Show groups';
$string['status'] = 'Enable manual enrolments';
$string['status_desc'] = 'Allow course access of internally enrolled users. This should be kept enabled in most cases.';
$string['status_help'] = 'This setting determines whether users can be enrolled manually, via a link in the course administration settings, by a user with appropriate permissions such as a teacher.';
@@ -212,6 +212,26 @@ Feature: Teacher can search and enrol users one by one into the course
And I type "Q994"
And I should see "No suggestions"
@javascript
Scenario: Add participant to a group
Given I navigate to course participants
When I press "Enrol users"
# No group created yet.
Then I should not see "Add to group" in the "Enrol users" "dialogue"
And I should not see "Show groups" in the "Enrol users" "dialogue"
And I click on "Cancel" "button" in the "Enrol users" "dialogue"
And I navigate to course participants
And the following "groups" exist:
| name | course | idnumber |
| Group 1 | C001 | G1 |
# Now we have a group, we can test adding a user.
And I press "Enrol users"
And I set the field "Select users" to "student001"
And I click on "showgroups" "checkbox"
And I set the field "Add to group" to "Group 1"
And I click on "Enrol users" "button" in the "Enrol users" "dialogue"
And I should see "Group 1" in the "Student 001" "table_row"
# The following tests are commented out as a result of MDL-66339.
# @javascript
# Scenario: Enrol user from participants page