// 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);
+ $extrafields = get_extra_user_fields($context);
$users = groups_get_potential_members($data->courseid, $data->roleid, $source, $orderby, !empty($data->notingroup),
- $onlyactive);
+ $onlyactive, $extrafields);
$usercnt = count($users);
if ($data->allocateby == 'random') {
if ($data->allocateby != 'no') {
$unames = array();
foreach ($group['members'] as $user) {
- $unames[] = fullname($user, true);
+ $fullname = fullname($user, true);
+ if ($extrafields) {
+ $extrafieldsdisplay = [];
+ foreach ($extrafields as $field) {
+ $extrafieldsdisplay[] = s($user->{$field});
+ }
+ $fullname .= ' (' . implode(', ', $extrafieldsdisplay) . ')';
+ }
+
+ $unames[] = $fullname;
}
$line[] = implode(', ', $unames);
$line[] = count($group['members']);
case 'ajax_getmembersingroup':
$roles = array();
- if ($groupmemberroles = groups_get_members_by_role($groupids[0], $courseid, 'u.id, ' . get_all_user_name_fields(true, 'u'))) {
+
+ $extrafields = get_extra_user_fields($context);
+ if ($groupmemberroles = groups_get_members_by_role($groupids[0], $courseid,
+ 'u.id, ' . user_picture::fields('u', $extrafields))) {
+
foreach($groupmemberroles as $roleid=>$roledata) {
$shortroledata = new stdClass();
$shortroledata->name = $roledata->name;
$shortmember = new stdClass();
$shortmember->id = $member->id;
$shortmember->name = fullname($member, true);
+ if ($extrafields) {
+ $extrafieldsdisplay = [];
+ foreach ($extrafields as $field) {
+ $extrafieldsdisplay[] = s($member->{$field});
+ }
+ $shortmember->name .= ' (' . implode(', ', $extrafieldsdisplay) . ')';
+ }
+
$shortroledata->users[] = $shortmember;
}
$roles[] = $shortroledata;
// Get list of group members to render if there is a single selected group.
$members = array();
if ($singlegroup) {
- $usernamefields = get_all_user_name_fields(true, 'u');
- if ($groupmemberroles = groups_get_members_by_role(reset($groupids), $courseid, 'u.id, ' . $usernamefields)) {
+ $extrafields = get_extra_user_fields($context);
+ if ($groupmemberroles = groups_get_members_by_role(reset($groupids), $courseid,
+ 'u.id, ' . user_picture::fields('u', $extrafields))) {
+
foreach ($groupmemberroles as $roleid => $roledata) {
$users = array();
foreach ($roledata->users as $member) {
- $users[] = (object)[
- 'value' => $member->id,
- 'text' => fullname($member, true)
- ];
+ $shortmember = new stdClass();
+ $shortmember->value = $member->id;
+ $shortmember->text = fullname($member, true);
+ if ($extrafields) {
+ $extrafieldsdisplay = [];
+ foreach ($extrafields as $field) {
+ $extrafieldsdisplay[] = s($member->{$field});
+ }
+ $shortmember->text .= ' (' . implode(', ', $extrafieldsdisplay) . ')';
+ }
+
+ $users[] = $shortmember;
}
$members[] = (object)[
'role' => s($roledata->name),
* @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
+ * @param array $extrafields Extra user fields to return
* @return array An array of the users
*/
function groups_get_potential_members($courseid, $roleid = null, $source = null,
$orderby = 'lastname ASC, firstname ASC',
- $notingroup = null, $onlyactiveenrolments = false) {
+ $notingroup = null, $onlyactiveenrolments = false, $extrafields = []) {
global $DB;
$context = context_course::instance($courseid);
}
}
- $allusernamefields = get_all_user_name_fields(true, 'u');
+ $allusernamefields = user_picture::fields('u', $extrafields);
$sql = "SELECT DISTINCT u.id, u.username, $allusernamefields, u.idnumber
FROM {user} u
JOIN ($esql) e ON e.id = u.id
list($sort, $sortparams) = users_order_by_sql('u');
-$allnames = get_all_user_name_fields(true, 'u');
+$extrafields = get_extra_user_fields($context);
+$allnames = 'u.id, ' . user_picture::fields('u', $extrafields);
+
$sql = "SELECT g.id AS groupid, gg.groupingid, u.id AS userid, $allnames, u.idnumber, u.username
FROM {groups} g
LEFT JOIN {groupings_groups} gg ON g.id = gg.groupid
$rs = $DB->get_recordset_sql($sql, array_merge($params, $sortparams));
foreach ($rs as $row) {
- $user = new stdClass();
- $user = username_load_fields_from_object($user, $row, null, array('id' => 'userid', 'username', 'idnumber'));
+ $user = username_load_fields_from_object((object) [], $row, null,
+ array_merge(['id' => 'userid', 'username', 'idnumber'], $extrafields));
+
if (!$row->groupingid) {
$row->groupingid = OVERVIEW_GROUPING_GROUP_NO_GROUPING;
}
}
$fullnames = array();
foreach ($users as $user) {
- $fullnames[] = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&course='.$course->id.'">'.fullname($user, true).'</a>';
+ $displayname = fullname($user, true);
+ if ($extrafields) {
+ $extrafieldsdisplay = [];
+ foreach ($extrafields as $field) {
+ $extrafieldsdisplay[] = s($user->{$field});
+ }
+ $displayname .= ' (' . implode(', ', $extrafieldsdisplay) . ')';
+ }
+
+ $fullnames[] = html_writer::link(new moodle_url('/user/view.php', ['id' => $user->id, 'course' => $course->id]),
+ $displayname);
}
$line[] = implode(', ', $fullnames);
$line[] = count($users);
| Group/member count | 4 |
| Grouping of auto-created groups | New grouping |
| Grouping name | Grouping name |
+ | Allocate members | Alphabetically by last name, first name |
And I press "Preview"
- Then I should see "Group members"
- And I should see "User count"
- And I should see "Group A" in the ".generaltable" "css_element"
- And I should see "Group B" in the ".generaltable" "css_element"
- And I should see "Group C" in the ".generaltable" "css_element"
- And I should see "4" in the "Group A" "table_row"
- And I should see "4" in the "Group B" "table_row"
- And I should see "2" in the "Group C" "table_row"
+ Then the following should exist in the "generaltable" table:
+ | Groups (3) | Group members | User count (10) |
+ | Group A | Student 1 (student1@example.com) | 4 |
+ | Group B | Student 5 (student5@example.com) | 4 |
+ | Group C | Student 9 (student9@example.com) | 2 |
And I set the field "Prevent last small group" to "1"
And I press "Preview"
And I should see "Group A" in the ".generaltable" "css_element"
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"
+ Then I should see "Suspended student 11 (suspendedstudent11@example.com)"
Scenario: Do not display 'Include only active enrolments' if user does not have the 'moodle/course:viewsuspendedusers' capability
Given I log out
And I add "Student 2 (student2@example.com)" user to "Group 2" group members
And I add "Student 3 (student3@example.com)" user to "Group 2" group members
Then I set the field "groups" to "Group 1 (2)"
- And the "members" select box should contain "Student 0"
- And the "members" select box should contain "Student 1"
- And the "members" select box should not contain "Student 2"
+ And the "members" select box should contain "Student 0 (student0@example.com)"
+ And the "members" select box should contain "Student 1 (student1@example.com)"
+ And the "members" select box should not contain "Student 2 (student2@example.com)"
+ And the "members" select box should not contain "Student 3 (student3@example.com)"
And I set the field "groups" to "Group 2 (2)"
- And the "members" select box should contain "Student 2"
- And the "members" select box should contain "Student 3"
- And the "members" select box should not contain "Student 0"
+ And the "members" select box should contain "Student 2 (student2@example.com)"
+ And the "members" select box should contain "Student 3 (student3@example.com)"
+ And the "members" select box should not contain "Student 0 (student0@example.com)"
+ And the "members" select box should not contain "Student 1 (student1@example.com)"
And I navigate to course participants
And I open the autocomplete suggestions list
And I click on "Group: Group 1" item in the autocomplete list
And I should see "Student 3"
And I should not see "Student 0"
+ @javascript
+ Scenario: Assign students to groups with site user identity configured
+ Given the following "courses" exist:
+ | fullname | shortname | groupmode |
+ | Course 1 | C1 | 1 |
+ And the following "users" exist:
+ | username | firstname | lastname | email | country |
+ | teacher | Teacher | 1 | teacher@example.com | GB |
+ | student | Student | 1 | student@example.com | DE |
+ And the following "course enrolments" exist:
+ | user | course | role |
+ | teacher | C1 | editingteacher |
+ | student | C1 | student |
+ And the following config values are set as admin:
+ | showuseridentity | email,country |
+ And I log in as "teacher"
+ And I am on "Course 1" course homepage
+ And I navigate to "Users > Groups" in current page administration
+ And I press "Create group"
+ And I set the following fields to these values:
+ | Group name | Group 1 |
+ And I press "Save changes"
+ When I add "Student 1 (student@example.com, DE)" user to "Group 1" group members
+ And I set the field "groups" to "Group 1 (1)"
+ Then the "members" select box should contain "Student 1 (student@example.com\, DE)"
+ # Non-AJAX version of the groups page.
+ And I press "Add/remove users"
+ And I press "Back to groups"
+ And the "members" select box should contain "Student 1 (student@example.com\, DE)"
+
Scenario: Create groups and groupings without the 'moodle/course:changeidnumber' capability
Given the following "courses" exist:
| fullname | shortname | category | groupmode |