mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Merge branch 'MDL-45991_master' of https://github.com/Syxton/moodle
This commit is contained in:
commit
628e818be2
@ -85,7 +85,7 @@ if ($editform->is_cancelled()) {
|
|||||||
default:
|
default:
|
||||||
print_error('unknoworder');
|
print_error('unknoworder');
|
||||||
}
|
}
|
||||||
$users = groups_get_potential_members($data->courseid, $data->roleid, $data->cohortid, $orderby);
|
$users = groups_get_potential_members($data->courseid, $data->roleid, $data->cohortid, $orderby, !empty($data->notingroup));
|
||||||
$usercnt = count($users);
|
$usercnt = count($users);
|
||||||
|
|
||||||
if ($data->allocateby == 'random') {
|
if ($data->allocateby == 'random') {
|
||||||
|
@ -110,6 +110,8 @@ class autogroup_form extends moodleform {
|
|||||||
$mform->addElement('checkbox', 'nosmallgroups', get_string('nosmallgroups', 'group'));
|
$mform->addElement('checkbox', 'nosmallgroups', get_string('nosmallgroups', 'group'));
|
||||||
$mform->disabledIf('nosmallgroups', 'groupby', 'noteq', 'members');
|
$mform->disabledIf('nosmallgroups', 'groupby', 'noteq', 'members');
|
||||||
|
|
||||||
|
$mform->addElement('checkbox', 'notingroup', get_string('notingroup', 'group'));
|
||||||
|
|
||||||
$mform->addElement('header', 'groupinghdr', get_string('grouping', 'group'));
|
$mform->addElement('header', 'groupinghdr', get_string('grouping', 'group'));
|
||||||
|
|
||||||
$options = array('0' => get_string('nogrouping', 'group'),
|
$options = array('0' => get_string('nogrouping', 'group'),
|
||||||
|
@ -709,23 +709,42 @@ function groups_get_possible_roles($context) {
|
|||||||
* @param int $roleid The role to select users from
|
* @param int $roleid The role to select users from
|
||||||
* @param int $cohortid restrict to cohort id
|
* @param int $cohortid restrict to cohort id
|
||||||
* @param string $orderby The column to sort users by
|
* @param string $orderby The column to sort users by
|
||||||
|
* @param int $notingroup restrict to users not in existing groups
|
||||||
* @return array An array of the users
|
* @return array An array of the users
|
||||||
*/
|
*/
|
||||||
function groups_get_potential_members($courseid, $roleid = null, $cohortid = null, $orderby = 'lastname ASC, firstname ASC') {
|
function groups_get_potential_members($courseid, $roleid = null, $cohortid = null,
|
||||||
|
$orderby = 'lastname ASC, firstname ASC',
|
||||||
|
$notingroup = null) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$context = context_course::instance($courseid);
|
$context = context_course::instance($courseid);
|
||||||
|
|
||||||
list($esql, $params) = get_enrolled_sql($context);
|
list($esql, $params) = get_enrolled_sql($context);
|
||||||
|
|
||||||
|
$notingroupsql = "";
|
||||||
|
if ($notingroup) {
|
||||||
|
// We want to eliminate users that are already associated with a course group.
|
||||||
|
$notingroupsql = "u.id NOT IN (SELECT userid
|
||||||
|
FROM {groups_members}
|
||||||
|
WHERE groupid IN (SELECT id
|
||||||
|
FROM {groups}
|
||||||
|
WHERE courseid = :courseid))";
|
||||||
|
$params['courseid'] = $courseid;
|
||||||
|
}
|
||||||
|
|
||||||
if ($roleid) {
|
if ($roleid) {
|
||||||
// We are looking for all users with this role assigned in this context or higher.
|
// We are looking for all users with this role assigned in this context or higher.
|
||||||
list($relatedctxsql, $relatedctxparams) = $DB->get_in_or_equal($context->get_parent_context_ids(true), SQL_PARAMS_NAMED, 'relatedctx');
|
list($relatedctxsql, $relatedctxparams) = $DB->get_in_or_equal($context->get_parent_context_ids(true),
|
||||||
|
SQL_PARAMS_NAMED,
|
||||||
|
'relatedctx');
|
||||||
|
|
||||||
$params = array_merge($params, $relatedctxparams, array('roleid' => $roleid));
|
$params = array_merge($params, $relatedctxparams, array('roleid' => $roleid));
|
||||||
$where = "WHERE u.id IN (SELECT userid
|
$where = "WHERE u.id IN (SELECT userid
|
||||||
FROM {role_assignments}
|
FROM {role_assignments}
|
||||||
WHERE roleid = :roleid AND contextid $relatedctxsql)";
|
WHERE roleid = :roleid AND contextid $relatedctxsql)";
|
||||||
|
$where .= $notingroup ? "AND $notingroupsql" : "";
|
||||||
|
} else if ($notingroup) {
|
||||||
|
$where = "WHERE $notingroupsql";
|
||||||
} else {
|
} else {
|
||||||
$where = "";
|
$where = "";
|
||||||
}
|
}
|
||||||
|
@ -84,3 +84,28 @@ Feature: Automatic creation of groups
|
|||||||
And I should see "Group B" in the ".generaltable" "css_element"
|
And I should see "Group B" in the ".generaltable" "css_element"
|
||||||
And I should see "5" in the "Group A" "table_row"
|
And I should see "5" in the "Group A" "table_row"
|
||||||
And I should see "5" in the "Group B" "table_row"
|
And I should see "5" in the "Group B" "table_row"
|
||||||
|
|
||||||
|
@javascript
|
||||||
|
Scenario: Split automatically the course users in groups that are not in groups
|
||||||
|
Given I press "Cancel"
|
||||||
|
And I press "Create group"
|
||||||
|
And I fill the moodle form with:
|
||||||
|
| Group name | Group 1 |
|
||||||
|
And I press "Save changes"
|
||||||
|
And I press "Create group"
|
||||||
|
And I fill the moodle form with:
|
||||||
|
| Group name | Group 2 |
|
||||||
|
And I press "Save changes"
|
||||||
|
When I add "student0" user to "Group 1" group
|
||||||
|
And I add "student1" user to "Group 1" group
|
||||||
|
And I add "student2" user to "Group 2" group
|
||||||
|
And I add "student3" user to "Group 2" group
|
||||||
|
And I press "Auto-create groups"
|
||||||
|
And I expand all fieldsets
|
||||||
|
And I set the field "Auto create based on" to "Number of groups"
|
||||||
|
And I set the field "Group/member count" to "2"
|
||||||
|
And I set the field "Grouping of auto-created groups" to "No grouping"
|
||||||
|
And I set the field "Ignore users in groups" to "1"
|
||||||
|
And I press "Submit"
|
||||||
|
And the "groups" select box should contain "Group A (3)"
|
||||||
|
And the "groups" select box should contain "Group B (3)"
|
@ -157,6 +157,7 @@ $string['nogroups'] = 'There are no groups set up in this course yet';
|
|||||||
$string['nogroupsassigned'] = 'No groups assigned';
|
$string['nogroupsassigned'] = 'No groups assigned';
|
||||||
$string['nopermissionforcreation'] = 'Can\'t create group "{$a}" as you don\'t have the required permissions';
|
$string['nopermissionforcreation'] = 'Can\'t create group "{$a}" as you don\'t have the required permissions';
|
||||||
$string['nosmallgroups'] = 'Prevent last small group';
|
$string['nosmallgroups'] = 'Prevent last small group';
|
||||||
|
$string['notingroup'] = 'Ignore users in groups';
|
||||||
$string['notingrouping'] = '[Not in a grouping]';
|
$string['notingrouping'] = '[Not in a grouping]';
|
||||||
$string['nousersinrole'] = 'There are no suitable users in the selected role';
|
$string['nousersinrole'] = 'There are no suitable users in the selected role';
|
||||||
$string['number'] = 'Group/member count';
|
$string['number'] = 'Group/member count';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user