Commit 647681d4 authored by Andrew Nicols's avatar Andrew Nicols
Browse files

Merge branch 'MDL-49687-master' of git://github.com/andrewnicols/moodle

parents b38b62f8 31635bfb
@core_enrol @core_group
Feature: Users can be added to multiple groups at once
In order to manage group membership effectively
As a user
I need to add another user to multiple groups
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@asd.com |
| student1 | Student | 1 | student1@asd.com |
And the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | topics |
And the following "groups" exist:
| name | course | idnumber |
| Group 1 | C1 | G1 |
| Group 2 | C1 | G2 |
| Group 3 | C1 | G3 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | editingteacher |
Scenario: Adding a user to one group
Given I log in as "teacher1"
And I follow "Course 1"
And I navigate to "Enrolled users" node in "Course administration > Users"
And I click on "Add user into group" "link" in the "student1" "table_row"
When I set the field "Add user into group" to "Group 1"
And I press "Save changes"
Then I should see "Group 1"
Scenario: Adding a user to multiple group
Given I log in as "teacher1"
And I follow "Course 1"
And I navigate to "Enrolled users" node in "Course administration > Users"
And I click on "Add user into group" "link" in the "student1" "table_row"
When I set the field "Add user into group" to "Group 1, Group 2, Group 3"
And I press "Save changes"
Then I should see "Group 1"
And I should see "Group 2"
And I should see "Group 3"
......@@ -144,7 +144,12 @@ if ($action) {
$mform = new enrol_users_addmember_form(NULL, array('user'=>$user, 'course'=>$course, 'allgroups'=>$manager->get_all_groups()));
$mform->set_data($PAGE->url->params());
$data = $mform->get_data();
if ($mform->is_cancelled() || ($data && $manager->add_user_to_group($user, $data->groupid))) {
if ($mform->is_cancelled()) {
redirect($PAGE->url);
} if (!empty($data->groupids)) {
foreach ($data->groupids as $groupid) {
$manager->add_user_to_group($user, $groupid);
}
redirect($PAGE->url);
} else {
$pagetitle = get_string('addgroup', 'group');
......
......@@ -99,7 +99,8 @@ class enrol_users_addmember_form extends moodleform {
$mform->addElement('header','general', fullname($user));
$mform->addElement('select', 'groupid', get_string('addgroup', 'group'), $options);
$mform->addElement('select', 'groupids', get_string('addgroup', 'group'), $options, array('multiple' => 'multiple'));
$mform->addRule('groupids', null, 'required');
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
......
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