MDL-53072 group: added 'only active' option when auto-creating groups

This commit is contained in:
Niclas Tollstorff
2016-02-26 11:42:14 +08:00
committed by Mark Nelson
parent 03b8b55f10
commit 7b96ffb044
4 changed files with 20 additions and 4 deletions
+7 -1
View File
@@ -95,7 +95,13 @@ if ($editform->is_cancelled()) {
if ($data->groupid) {
$source['groupid'] = $data->groupid;
}
$users = groups_get_potential_members($data->courseid, $data->roleid, $source, $orderby, !empty($data->notingroup));
$onlyactive = true;
if (!$data->includeonlyactiveenrol && has_capability('moodle/course:viewsuspendedusers', $context)) {
$onlyactive = false;
}
$users = groups_get_potential_members($data->courseid, $data->roleid, $source, $orderby, !empty($data->notingroup), $onlyactive);
$usercnt = count($users);
if ($data->allocateby == 'random') {
+8 -1
View File
@@ -82,7 +82,8 @@ class autogroup_form extends moodleform {
$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));
@@ -140,6 +141,12 @@ class autogroup_form extends moodleform {
$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'),
+3 -2
View File
@@ -717,16 +717,17 @@ function groups_get_possible_roles($context) {
* @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 = true) {
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) {
+2
View File
@@ -137,6 +137,8 @@ $string['importgroups_help'] = 'Groups may be imported via text file. The format
* Required fieldname is groupname
* Optional fieldnames are description, enrolmentkey, picture, hidepicture';
$string['importgroups_link'] = 'group/import';
$string['includeonlyactiveenrol'] = 'Include only active enrolments';
$string['includeonlyactiveenrol_help'] = 'This setting determines if only active enrolled users will be included in the groups. If enabled, suspended users will not be included in groups.';
$string['javascriptrequired'] = 'This page requires JavaScript to be enabled.';
$string['members'] = 'Members per group';
$string['membersofselectedgroup'] = 'Members of:';