MDL-26647 (3) Support showuseridentity on Browse Users page

This commit is contained in:
sam marshall 2011-04-13 15:44:42 +01:00
parent a1c947bde2
commit 1fdc0c6aaa
2 changed files with 57 additions and 19 deletions

View File

@ -7,7 +7,7 @@
$delete = optional_param('delete', 0, PARAM_INT);
$confirm = optional_param('confirm', '', PARAM_ALPHANUM); //md5 confirmation hash
$confirmuser = optional_param('confirmuser', 0, PARAM_INT);
$sort = optional_param('sort', 'name', PARAM_ALPHA);
$sort = optional_param('sort', 'name', PARAM_ALPHANUM);
$dir = optional_param('dir', 'ASC', PARAM_ALPHA);
$page = optional_param('page', 0, PARAM_INT);
$perpage = optional_param('perpage', 30, PARAM_INT); // how many per page
@ -117,11 +117,13 @@
echo $OUTPUT->header();
// Carry on with the user listing
$columns = array("firstname", "lastname", "email", "city", "country", "lastaccess");
$context = context_system::instance();
$extracolumns = get_extra_user_fields($context);
$columns = array_merge(array('firstname', 'lastname'), $extracolumns,
array('city', 'country', 'lastaccess'));
foreach ($columns as $column) {
$string[$column] = get_string("$column");
$string[$column] = get_user_field_name($column);
if ($sort != $column) {
$columnicon = "";
if ($column == "lastaccess") {
@ -147,7 +149,8 @@
}
list($extrasql, $params) = $ufiltering->get_sql_filter();
$users = get_users_listing($sort, $dir, $page*$perpage, $perpage, '', '', '', $extrasql, $params);
$users = get_users_listing($sort, $dir, $page*$perpage, $perpage, '', '', '',
$extrasql, $params, $context);
$usercount = get_users(false);
$usersearchcount = get_users(false, '', true, null, "", '', '', '', '', '*', $extrasql, $params);
@ -208,8 +211,27 @@
}
$table = new html_table();
$table->head = array ($fullnamedisplay, $email, $city, $country, $lastaccess, "", "", "");
$table->align = array ("left", "left", "left", "left", "left", "center", "center", "center");
$table->head = array ();
$table->align = array();
$table->head[] = $fullnamedisplay;
$table->align[] = 'left';
foreach ($extracolumns as $field) {
$table->head[] = ${$field};
$table->align[] = 'left';
}
$table->head[] = $city;
$table->align[] = 'left';
$table->head[] = $country;
$table->align[] = 'left';
$table->head[] = $lastaccess;
$table->align[] = 'left';
$table->head[] = "";
$table->align[] = 'center';
$table->head[] = "";
$table->align[] = 'center';
$table->head[] = "";
$table->align[] = 'center';
$table->width = "95%";
foreach ($users as $user) {
if (isguestuser($user)) {
@ -272,14 +294,18 @@
}
$fullname = fullname($user, true);
$table->data[] = array ("<a href=\"../user/view.php?id=$user->id&amp;course=$site->id\">$fullname</a>",
"$user->email",
"$user->city",
"$user->country",
$strlastaccess,
$editbutton,
$deletebutton,
$confirmbutton);
$row = array ();
$row[] = "<a href=\"../user/view.php?id=$user->id&amp;course=$site->id\">$fullname</a>";
foreach ($extracolumns as $field) {
$row[] = $user->{$field};
}
$row[] = $user->city;
$row[] = $user->country;
$row[] = $strlastaccess;
$row[] = $editbutton;
$row[] = $deletebutton;
$row[] = $confirmbutton;
$table->data[] = $row;
}
}

View File

@ -249,11 +249,13 @@ function get_users($get=true, $search='', $confirmed=false, array $exceptions=nu
* @param string $lastinitial Users whose last name starts with $lastinitial
* @param string $extraselect An additional SQL select statement to append to the query
* @param array $extraparams Additional parameters to use for the above $extraselect
* @param object $extracontext If specified, will include user 'extra fields'
* as appropriate for current user and given context
* @return array Array of {@link $USER} records
*/
function get_users_listing($sort='lastaccess', $dir='ASC', $page=0, $recordsperpage=0,
$search='', $firstinitial='', $lastinitial='', $extraselect='', array $extraparams=null) {
$search='', $firstinitial='', $lastinitial='', $extraselect='',
array $extraparams=null, $extracontext = null) {
global $DB;
$fullname = $DB->sql_fullname();
@ -289,8 +291,18 @@ function get_users_listing($sort='lastaccess', $dir='ASC', $page=0, $recordsperp
$sort = " ORDER BY $sort $dir";
}
/// warning: will return UNCONFIRMED USERS
return $DB->get_records_sql("SELECT id, username, email, firstname, lastname, city, country, lastaccess, confirmed, mnethostid
// If a context is specified, get extra user fields that the current user
// is supposed to see.
$extrafields = '';
if ($extracontext) {
$extrafields = get_extra_user_fields_sql($extracontext, '', '',
array('id', 'username', 'email', 'firstname', 'lastname', 'city', 'country',
'lastaccess', 'confirmed', 'mnethostid'));
}
// warning: will return UNCONFIRMED USERS
return $DB->get_records_sql("SELECT id, username, email, firstname, lastname, city, country,
lastaccess, confirmed, mnethostid$extrafields
FROM {user}
WHERE $select
$sort", $params, $page, $recordsperpage);