Skip to content

Commit

Permalink
user selection: MDL-16966 Improve some of the wording.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjhunt committed Oct 29, 2008
1 parent 6d5a0e9 commit aa9671c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
5 changes: 2 additions & 3 deletions group/members.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
require_once($CFG->dirroot . '/user/selector/lib.php');
require_js('group/clientlib.js');

$groupid = required_param('group', PARAM_INT);
$groupid = required_param('group', PARAM_INT);

if (!$group = $DB->get_record('groups', array('id'=>$groupid))) {
print_error('invalidgroupid');
Expand Down Expand Up @@ -88,10 +88,9 @@
<div id="addmembersform">
<h3 class="main"><?php print_string('adduserstogroup', 'group'); echo ": $groupname"; ?></h3>

<form id="assignform" method="post" action="members.php">
<form id="assignform" method="post" action="<?php echo $CFG->wwwroot; ?>/group/members.php?group=<?php echo $groupid; ?>">
<div>
<input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
<input type="hidden" name="group" value="<?php echo $groupid; ?>" />

<table class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">
<tr>
Expand Down
26 changes: 17 additions & 9 deletions user/selector/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function display($return = false) {
$multiselect . 'size="' . $this->rows . '">' . "\n";

// Populate the select.
$output .= $this->output_options($groupedusers);
$output .= $this->output_options($groupedusers, $search);

// Output the search controls.
$output .= "</select>\n<div>\n";
Expand Down Expand Up @@ -364,7 +364,7 @@ protected function search_sql($search, $u) {
* @param array $groupedusers an array, as returned by find_users.
* @return string HTML code.
*/
protected function output_options($groupedusers) {
protected function output_options($groupedusers, $search) {
$output = '';

// Ensure that the list of previously selected users is up to date.
Expand All @@ -374,7 +374,7 @@ protected function output_options($groupedusers) {
// is only one selected user, set a flag to select them.
$select = false;
if (empty($groupedusers)) {
$groupedusers = array(get_string('nomatchingusers') => array());
$groupedusers = array(get_string('nomatchingusers', '', $search) => array());
} else if (count($groupedusers) == 1 && count(reset($groupedusers)) == 1) {
$select = true;
if (!$this->multiselect) {
Expand All @@ -389,7 +389,7 @@ protected function output_options($groupedusers) {

// If there were previously selected users who do not match the search, show them too.
if (!empty($this->selected)) {
$output .= $this->output_optgroup(get_string('previouslyselectedusers'), $this->selected, true);
$output .= $this->output_optgroup(get_string('previouslyselectedusers', '', $search), $this->selected, true);
}

// This method trashes $this->selected, so clear the cache so it is
Expand Down Expand Up @@ -526,14 +526,22 @@ protected function get_options() {
* @param array $roles array in the format returned by groups_calculate_role_people.
* @return array array in the format find_users is supposed to return.
*/
protected function convert_array_format($roles) {
protected function convert_array_format($roles, $search) {
if (empty($roles)) {
$roles = array();
}
$groupedusers = array();
foreach ($roles as $role) {
$groupedusers[$role->name] = $role->users;
foreach ($groupedusers[$role->name] as &$user) {
if ($search) {
$a = new stdClass;
$a->role = $role->name;
$a->search = $search;
$groupname = get_string('matchingsearchandrole', '', $a);
} else {
$groupname = $role->name;
}
$groupedusers[$groupname] = $role->users;
foreach ($groupedusers[$groupname] as &$user) {
unset($user->roles);
$user->fullname = fullname($user);
}
Expand All @@ -552,7 +560,7 @@ public function find_users($search) {
$roles = groups_get_members_by_role($this->groupid, $this->courseid,
$this->required_fields_sql('u'), 'u.lastname, u.firstname',
$wherecondition, $params);
return $this->convert_array_format($roles);
return $this->convert_array_format($roles, $search);
}
}

Expand Down Expand Up @@ -609,7 +617,7 @@ public function find_users($search) {
$rs = $DB->get_recordset_sql($fields . $sql . $orderby, $params);
$roles = groups_calculate_role_people($rs, $context);

return $this->convert_array_format($roles);
return $this->convert_array_format($roles, $search);
}
}
?>
7 changes: 5 additions & 2 deletions user/selector/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ user_selector.prototype.handle_selection_change = function() {
}

// Methods for refreshing the list of displayed options ========================
user_selector.prototype.insert_search_into_str = function(string, search) {
return string.replace("''", "'" + search + "'");
}

/**
* This method should do the same sort of thing as the PHP method
Expand Down Expand Up @@ -317,7 +320,7 @@ user_selector.prototype.output_options = function(data) {
}

if (nogroups) {
this.output_group(this.strnomatchingusers, {}, false)
this.output_group(this.insert_search_into_str(this.strnomatchingusers, this.lastsearch), {}, false)
}

// If there was only one option matching the search results, select it.
Expand All @@ -336,7 +339,7 @@ user_selector.prototype.output_options = function(data) {
break;
}
if (areprevselected) {
this.output_group(this.strprevselected, this.selected, true);
this.output_group(this.insert_search_into_str(this.strprevselected, this.lastsearch), this.selected, true);
}
this.selected = null;
}
Expand Down

0 comments on commit aa9671c

Please sign in to comment.