$mform->setDefault('roleid', $student->id);
}
- if ($cohorts = cohort_get_available_cohorts(context_course::instance($COURSE->id), COHORT_WITH_ENROLLED_MEMBERS_ONLY, 0, 0)) {
+ $coursecontext = context_course::instance($COURSE->id);
+ if ($cohorts = cohort_get_available_cohorts($coursecontext, COHORT_WITH_ENROLLED_MEMBERS_ONLY)) {
$options = array(0 => get_string('anycohort', 'cohort'));
foreach ($cohorts as $c) {
$options[$c->id] = format_string($c->name, true, context::instance_by_id($c->contextid));
$mform->disabledIf('notingroup', 'groupingid', 'neq', 0);
$mform->disabledIf('notingroup', 'groupid', 'neq', 0);
+ if (has_capability('moodle/course:viewsuspendedusers', $coursecontext)) {
+ $mform->addElement('checkbox', 'includeonlyactiveenrol', get_string('includeonlyactiveenrol', 'group'), '');
+ $mform->addHelpButton('includeonlyactiveenrol', 'includeonlyactiveenrol', 'group');
+ $mform->setDefault('includeonlyactiveenrol', true);
+ }
+
$mform->addElement('header', 'groupinghdr', get_string('grouping', 'group'));
$options = array('0' => get_string('nogrouping', 'group'),
* @param mixed $source restrict to cohort, grouping or group id
* @param string $orderby The column to sort users by
* @param int $notingroup restrict to users not in existing groups
+ * @param bool $onlyactiveenrolments restrict to users who have an active enrolment in the course
* @return array An array of the users
*/
function groups_get_potential_members($courseid, $roleid = null, $source = null,
$orderby = 'lastname ASC, firstname ASC',
- $notingroup = null) {
+ $notingroup = null, $onlyactiveenrolments = false) {
global $DB;
$context = context_course::instance($courseid);
- list($esql, $params) = get_enrolled_sql($context);
+ list($esql, $params) = get_enrolled_sql($context, '', 0, $onlyactiveenrolments);
$notingroupsql = "";
if ($notingroup) {
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
- | student0 | Student | 0 | student0@example.com |
| student1 | Student | 1 | student1@example.com |
| student2 | Student | 2 | student2@example.com |
| student3 | Student | 3 | student3@example.com |
| student7 | Student | 7 | student7@example.com |
| student8 | Student | 8 | student8@example.com |
| student9 | Student | 9 | student9@example.com |
+ | student10 | Student | 10 | student10@example.com |
+ | suspendedstudent11 | Suspended student | 11 | suspendedstudent11@example.com |
And the following "course enrolments" exist:
- | user | course | role |
- | teacher1 | C1 | editingteacher |
- | student0 | C1 | student |
- | student1 | C1 | student |
- | student2 | C1 | student |
- | student3 | C1 | student |
- | student4 | C1 | student |
- | student5 | C1 | student |
- | student6 | C1 | student |
- | student7 | C1 | student |
- | student8 | C1 | student |
- | student9 | C1 | student |
+ | user | course | role | status |
+ | teacher1 | C1 | editingteacher | 0 |
+ | student1 | C1 | student | 0 |
+ | student2 | C1 | student | 0 |
+ | student3 | C1 | student | 0 |
+ | student4 | C1 | student | 0 |
+ | student5 | C1 | student | 0 |
+ | student6 | C1 | student | 0 |
+ | student7 | C1 | student | 0 |
+ | student8 | C1 | student | 0 |
+ | student9 | C1 | student | 0 |
+ | student10 | C1 | student | 0 |
+ | suspendedstudent11 | C1 | student | 1 |
And I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I set the following fields to these values:
| Group name | Group 2 |
And I press "Save changes"
- When I add "Student 0" user to "Group 1" group members
- And I add "Student 1" user to "Group 1" group members
- And I add "Student 2" user to "Group 2" group members
+ When I add "Student 1" user to "Group 1" group members
+ And I add "Student 2" user to "Group 1" group members
And I add "Student 3" user to "Group 2" group members
+ And I add "Student 4" user to "Group 2" group members
And I press "Auto-create groups"
And I expand all fieldsets
And I set the field "Auto create based on" to "Number of groups"
| Grouping of auto-created groups | No grouping |
And I press "Submit"
And the "groups" select box should contain "Test 1 (3)"
- And the "groups" select box should contain "Test 2 (2)"
\ No newline at end of file
+ And the "groups" select box should contain "Test 2 (2)"
+
+ Scenario: Exclude suspended users when auto-creating groups
+ Given I set the field "Include only active enrolments" to "1"
+ And I set the field "Auto create based on" to "Members per group"
+ When I set the field "Group/member count" to "11"
+ And I press "Preview"
+ Then I should not see "Suspended Student 11"
+
+ Scenario: Include suspended users when auto-creating groups
+ Given I set the field "Include only active enrolments" to "0"
+ And I set the field "Auto create based on" to "Members per group"
+ When I set the field "Group/member count" to "11"
+ And I press "Preview"
+ Then I should see "Suspended student 11"
+
+ Scenario: Do not display 'Include only active enrolments' if user does not have the 'moodle/course:viewsuspendedusers' capability
+ Given I log out
+ And I log in as "admin"
+ And I set the following system permissions of "Teacher" role:
+ | capability | permission |
+ | moodle/course:viewsuspendedusers | Prevent |
+ And I log out
+ And I log in as "teacher1"
+ And I follow "Course 1"
+ And I expand "Users" node
+ And I follow "Groups"
+ When I press "Auto-create groups"
+ Then I should not see "Include only active enrolments"
+ And I set the field "Group/member count" to "11"
+ And I press "Preview"
+ And I should not see "Suspended Student 11"