mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Merge branch 'MDL-53072_master' of git://github.com/markn86/moodle
This commit is contained in:
commit
25c0e10122
@ -95,7 +95,12 @@ 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));
|
||||
|
||||
// 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') {
|
||||
|
@ -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'),
|
||||
|
@ -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) {
|
||||
|
@ -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 |
|
||||
@ -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
|
||||
@ -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"
|
||||
@ -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"
|
||||
|
@ -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:';
|
||||
|
Loading…
x
Reference in New Issue
Block a user