From aa9671c9906d184c01ebf719189d5a506bc25f45 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Wed, 29 Oct 2008 09:10:41 +0000 Subject: [PATCH] user selection: MDL-16966 Improve some of the wording. --- group/members.php | 5 ++--- user/selector/lib.php | 26 +++++++++++++++++--------- user/selector/script.js | 7 +++++-- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/group/members.php b/group/members.php index 16924f5398..14f5daa4df 100644 --- a/group/members.php +++ b/group/members.php @@ -13,7 +13,7 @@ require_once(dirname(__FILE__) . '/lib.php'); 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'); @@ -88,10 +88,9 @@ check_theme_arrows();

-
+
- diff --git a/user/selector/lib.php b/user/selector/lib.php index 04b1b3d87c..e1cdfbb635 100644 --- a/user/selector/lib.php +++ b/user/selector/lib.php @@ -151,7 +151,7 @@ abstract class user_selector_base { $multiselect . 'size="' . $this->rows . '">' . "\n"; // Populate the select. - $output .= $this->output_options($groupedusers); + $output .= $this->output_options($groupedusers, $search); // Output the search controls. $output .= "\n
\n"; @@ -364,7 +364,7 @@ abstract class user_selector_base { * @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. @@ -374,7 +374,7 @@ abstract class user_selector_base { // 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) { @@ -389,7 +389,7 @@ abstract class user_selector_base { // 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 @@ -526,14 +526,22 @@ abstract class groups_user_selector_base extends user_selector_base { * @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); } @@ -552,7 +560,7 @@ class group_members_selector extends groups_user_selector_base { $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); } } @@ -609,7 +617,7 @@ class group_non_members_selector extends groups_user_selector_base { $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); } } ?> \ No newline at end of file diff --git a/user/selector/script.js b/user/selector/script.js index b551c6d874..6850c8f745 100644 --- a/user/selector/script.js +++ b/user/selector/script.js @@ -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 @@ -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. @@ -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; } -- 2.39.5