From: tjhunt Date: Mon, 29 Oct 2007 15:38:46 +0000 (+0000) Subject: MDL-11784 - On the role assign page, list who is assigned the role for roles with... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=9a41d8a1f1e1c265f43d9e7f3d23f11f429a43a6;p=moodle.git MDL-11784 - On the role assign page, list who is assigned the role for roles with only a few assignments. Improved version. Now, it only shows the extra column if some roles have between 1 and 10 assignees, as per Martin D's request. Merged from MOODLE_19_STABLE. --- diff --git a/admin/roles/assign.php b/admin/roles/assign.php index 01f9c3f318..859b9c2cbf 100755 --- a/admin/roles/assign.php +++ b/admin/roles/assign.php @@ -420,17 +420,16 @@ sync_metacourse($course); } - $table->tablealign = 'center'; - $table->cellpadding = 5; - $table->cellspacing = 0; - $table->width = '60%'; - $table->head = array(get_string('roles', 'role'), get_string('description'), get_string('users'), ''); - $table->wrap = array('nowrap', '', 'nowrap', 'nowrap'); - $table->align = array('right', 'left', 'center', 'left'); - + // Get the names of role holders for roles with between 1 and MAX_USERS_TO_LIST_PER_ROLE users, + // and so determine whether to show the extra column. + $rolehodlercount = array(); + $rolehodlernames = array(); + $strmorethanten = get_string('morethan', 'role', MAX_USERS_TO_LIST_PER_ROLE); + $showroleholders = false; foreach ($assignableroles as $roleid => $rolename) { $countusers = count_role_users($roleid, $context); - $strroleusers = ''; + $rolehodlercount[$roleid] = $countusers; + $roleusers = ''; if (0 < $countusers && $countusers <= MAX_USERS_TO_LIST_PER_ROLE) { $roleusers = get_role_users($roleid, $context, false, 'u.id, u.lastname, u.firstname'); if (!empty($roleusers)) { @@ -438,13 +437,37 @@ foreach ($roleusers as $user) { $strroleusers[] = '' . fullname($user) . ''; } - $strroleusers = implode('
', $strroleusers); + $rolehodlernames[$roleid] = implode('
', $strroleusers); + $showroleholders = true; } } else if ($countusers > MAX_USERS_TO_LIST_PER_ROLE) { - $strroleusers = get_string('morethan', 'role', MAX_USERS_TO_LIST_PER_ROLE); + $rolehodlernames[$roleid] = ''.$strmorethanten.''; + } else { + $rolehodlernames[$roleid] = ''; } + } + + // Print overview table + $table->tablealign = 'center'; + $table->cellpadding = 5; + $table->cellspacing = 0; + $table->width = '60%'; + $table->head = array(get_string('roles', 'role'), get_string('description'), get_string('users')); + $table->wrap = array('nowrap', '', 'nowrap'); + $table->align = array('right', 'left', 'center'); + if ($showroleholders) { + $table->head[] = ''; + $table->wrap[] = 'nowrap'; + $table->align[] = 'left'; + } + + foreach ($assignableroles as $roleid => $rolename) { $description = format_string(get_field('role', 'description', 'id', $roleid)); - $table->data[] = array(''.$rolename.'',$description, $countusers, $strroleusers); + $row = array(''.$rolename.'',$description, $rolehodlercount[$roleid]); + if ($showroleholders) { + $row[] = $rolehodlernames[$roleid]; + } + $table->data[] = $row; } print_table($table);