Skip to content

Commit

Permalink
MDL-53072 group: added 'only active' option when auto-creating groups
Browse files Browse the repository at this point in the history
  • Loading branch information
tollstorff authored and mdjnelson committed Feb 26, 2016
1 parent 03b8b55 commit 7b96ffb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
8 changes: 7 additions & 1 deletion group/autogroup.php
Expand Up @@ -95,7 +95,13 @@
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') {
Expand Down
9 changes: 8 additions & 1 deletion group/autogroup_form.php
Expand Up @@ -82,7 +82,8 @@ function definition() {
$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));
Expand Down Expand Up @@ -140,6 +141,12 @@ function definition() {
$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'),
Expand Down
5 changes: 3 additions & 2 deletions group/lib.php
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions lang/en/group.php
Expand Up @@ -137,6 +137,8 @@
* 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:';
Expand Down

0 comments on commit 7b96ffb

Please sign in to comment.