Skip to content

Commit

Permalink
Merge branch 'MDL-53072_master' of git://github.com/markn86/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Mar 1, 2016
2 parents c25f0b4 + 3ee812f commit 25c0e10
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 21 deletions.
7 changes: 6 additions & 1 deletion group/autogroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@
if ($data->groupid) {
$source['groupid'] = $data->groupid;
}
$users = groups_get_potential_members($data->courseid, $data->roleid, $source, $orderby, !empty($data->notingroup));

// Display only active users if the option was selected or they do not have the capability to view suspended users.
$onlyactive = !empty($data->includeonlyactiveenrol) || !has_capability('moodle/course:viewsuspendedusers', $context);

$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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 = 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) {
Expand Down
67 changes: 50 additions & 17 deletions group/tests/behat/auto_creation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Feature: Automatic creation of groups
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 |
Expand All @@ -21,19 +20,22 @@ Feature: Automatic creation of groups
| 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
Expand Down Expand Up @@ -96,10 +98,10 @@ Feature: Automatic creation of groups
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"
Expand Down Expand Up @@ -138,4 +140,35 @@ Feature: Automatic creation 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)"
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"
2 changes: 2 additions & 0 deletions lang/en/group.php
Original file line number Diff line number Diff line change
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 25c0e10

Please sign in to comment.