Skip to content

Commit

Permalink
MDL-24787 fixing group UI to work for users without roles too
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Oct 26, 2010
1 parent fad1178 commit 1c7a2f8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
23 changes: 14 additions & 9 deletions group/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,11 +646,10 @@ function groups_get_members_by_role($groupid, $courseid, $fields='u.*',
u.id AS userid, $fields
FROM {groups_members} gm
JOIN {user} u ON u.id = gm.userid
JOIN {role_assignments} ra ON ra.userid = u.id
JOIN {role} r ON r.id = ra.roleid
LEFT JOIN {role_assignments} ra ON (ra.userid = u.id AND ra.contextid ".get_related_contexts_string($context).")
LEFT JOIN {role} r ON r.id = ra.roleid
WHERE gm.groupid=:mgroupid
AND ra.contextid ".get_related_contexts_string($context).
$extrawheretest."
".$extrawheretest."
ORDER BY r.sortorder, $sort";
$whereparams['mgroupid'] = $groupid;
$rs = $DB->get_recordset_sql($sql, $whereparams);
Expand Down Expand Up @@ -687,7 +686,7 @@ function groups_calculate_role_people($rs, $context) {
if (!array_key_exists($rec->userid, $users)) {
// User data includes all the optional fields, but not any of the
// stuff we added to get the role details
$userdata=clone($rec);
$userdata = clone($rec);
unset($userdata->roleid);
unset($userdata->roleshortname);
unset($userdata->rolename);
Expand Down Expand Up @@ -720,7 +719,7 @@ function groups_calculate_role_people($rs, $context) {
$rs->close();

// Return false if there weren't any users
if (count($users)==0) {
if (count($users) == 0) {
return false;
}

Expand All @@ -730,12 +729,18 @@ function groups_calculate_role_people($rs, $context) {
$roledata->users = array();
$roles['*'] = $roledata;

$roledata = new stdClass();
$roledata->name = get_string('noroles','role');
$roledata->users = array();
$roles[0] = $roledata;

// Now we rearrange the data to store users by role
foreach ($users as $userid=>$userdata) {
$rolecount = count($userdata->roles);
if ($rolecount==0) {
debugging("Unexpected: user $userid is missing roles");
} else if($rolecount>1) {
if ($rolecount == 0) {
// does not have any roles
$roleid = 0;
} else if($rolecount > 1) {
$roleid = '*';
} else {
$roleid = $userdata->roles[0]->id;
Expand Down
1 change: 1 addition & 0 deletions lang/en/role.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@
$string['nocapabilitiesincontext'] = 'No capabilities available in this context';
$string['noneinthisx'] = 'None in this {$a}';
$string['noneinthisxmatching'] = 'No users matching \'{$a->search}\' in this {$a->contexttype}';
$string['noroles'] = 'No roles';
$string['noroleassignments'] = 'This user does not have any role assignments anywhere in this site.';
$string['notabletoassignroleshere'] = 'You are not able to assign any roles here';
$string['notabletooverrideroleshere'] = 'You are not able to override the permissions on any roles here';
Expand Down
18 changes: 9 additions & 9 deletions user/selector/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ public function print_user_summaries($courseid) {
global $DB, $PAGE;

$usersummaries = array();

// Get other groups user already belongs to
$usergroups = array();
$potentialmembersids = $this->potentialmembersids;
Expand Down Expand Up @@ -792,10 +792,12 @@ public function find_users($search) {

// Get list of allowed roles.
$context = get_context_instance(CONTEXT_COURSE, $this->courseid);
if (!$validroleids = groups_get_possible_roles($context)) {
return array();
if ($validroleids = groups_get_possible_roles($context)) {
list($roleids, $roleparams) = $DB->get_in_or_equal($validroleids, SQL_PARAMS_NAMED, 'r00');
} else {
$roleids = " = -1";
$roleparams = array();
}
list($roleids, $roleparams) = $DB->get_in_or_equal($validroleids, SQL_PARAMS_NAMED, 'r00');

// Get the search condition.
list($searchcondition, $searchparams) = $this->search_sql($search, 'u');
Expand All @@ -810,11 +812,9 @@ public function find_users($search) {
WHERE igm.userid = u.id AND ig.courseid = :courseid) AS numgroups";
$sql = " FROM {user} u
JOIN ($enrolsql) e ON e.id = u.id
JOIN {role_assignments} ra ON ra.userid = u.id
JOIN {role} r ON r.id = ra.roleid
WHERE ra.contextid " . get_related_contexts_string($context) . "
AND u.deleted = 0
AND ra.roleid $roleids
LEFT JOIN {role_assignments} ra ON (ra.userid = u.id AND ra.contextid " . get_related_contexts_string($context) . " AND ra.roleid $roleids)
LEFT JOIN {role} r ON r.id = ra.roleid
WHERE u.deleted = 0
AND u.id NOT IN (SELECT userid
FROM {groups_members}
WHERE groupid = :groupid)
Expand Down

0 comments on commit 1c7a2f8

Please sign in to comment.