$string['phone2'] = 'Mobile Phone';
$string['phpinfo'] = 'PHP info';
$string['pleaseclose'] = 'Please close this window now.';
+$string['pleasesearchmore'] = 'Please search some more';
+$string['pleaseusesearch'] = 'Please use the search';
$string['plugincheck'] = 'Plugins check';
$string['pluginchecknotice'] = 'The following tables show the modules, blocks and filters that have been detected in your current Moodle installation;
They indicate which plugins are standard, and which are not. All non-standard plugins should be checked and upgraded to their most recent versions
$string['toeveryone'] = 'to everyone';
$string['toomanybounces'] = 'That email address has had too many bounces. You <b>must</b> change it to continue.';
$string['toomanytoshow'] = 'There are too many users to show.';
+$string['toomanyuserstoshow'] = 'Too many users ($a) to show';
+$string['toomanyusersmatchsearch'] = 'Too many users ($a->count) match \'$a->search\'';
$string['toonly'] = 'to $a only';
$string['top'] = 'Top';
$string['topic'] = 'Topic';
* conditions that apply. The SQL for testing whether a user matches the
* search string should be obtained by calling the search_sql method.
*
+ * This method is used both when getting the list of choices to display to
+ * the user, and also when validating a list of users that was selected.
+ *
+ * When preparing a list of users to choose from ($this->is_validating()
+ * return false) you should probably have an maximum number of users you will
+ * return, and if more users than this match your search, you should instead
+ * return a message generated by the too_many_results() method. However, you
+ * should not do this when validating.
+ *
+ * If you are writing a new user_selector subclass, I strongly recommend you
+ * look at some of the subclasses later in this file. They should help you
+ * see exactly what you have to do.
+ *
* @param string $search the search string.
* @return array An array of arrays of users. The array keys of the outer
* array should be the string names of optgroups. The keys of the inner
// Inner workings ==========================================================
+ /**
+ * @return boolean if true, we are validating a list of selected users,
+ * rather than preparing a list of uesrs to choose from.
+ */
+ protected function is_validating() {
+ return !is_null($this->validatinguserids);
+ }
+
/**
* Get the list of users that were selected by doing optional_param then
* validating the result.
return array(implode(' AND ', $tests), $params);
}
+ /**
+ * Used to generate a nice message when there are too many users to show.
+ * The message includes the number of users that currently match, and the
+ * text of the message depends on whether the search term is non-blank.
+ *
+ * @param string $search the search term, as passed in to the find users method.
+ * @param unknown_type $count the number of users that currently match.
+ * @return array in the right format to return from the find_users method.
+ */
+ protected function too_many_results($search, $count) {
+ if ($search) {
+ $a = new stdClass;
+ $a->count = $count;
+ $a->search = $search;
+ return array(get_string('toomanyusersmatchsearch', '', $a) => array(),
+ get_string('pleasesearchmore') => array());
+ } else {
+ return array(get_string('toomanyuserstoshow', '', $count) => array(),
+ get_string('pleaseusesearch') => array());
+ }
+ }
+
/**
* Output the list of <optgroup>s and <options>s that go inside the select.
* This method should do the same as the JavaScript method
$params[] = $this->roleid;
// Check to see if there are too many to show sensibly.
- $potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params);
- if ($potentialmemberscount > role_assign_user_selector_base::MAX_USERS_PER_PAGE) {
- return array(get_string('toomanytoshow') => array(),
- get_string('trysearching') => array());
+ if (!$this->is_validating()) {
+ $potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params);
+ if ($potentialmemberscount > role_assign_user_selector_base::MAX_USERS_PER_PAGE) {
+ return $this->too_many_results($search, $potentialmemberscount);
+ }
}
// If not, show them.
$params[] = $this->context->id;
$params[] = $this->roleid;
- $potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params);
- if ($potentialmemberscount > role_assign_user_selector_base::MAX_USERS_PER_PAGE) {
- return array(get_string('toomanytoshow') => array(),
- get_string('trysearching') => array());
+ if (!$this->is_validating()) {
+ $potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params);
+ if ($potentialmemberscount > role_assign_user_selector_base::MAX_USERS_PER_PAGE) {
+ return $this->too_many_results($search, $potentialmemberscount);
+ }
}
$availableusers = $DB->get_records_sql($fields . $sql . $order, $params);
$orderby = " ORDER BY u.lastname, u.firstname";
$params = array_merge($roleparams, array($this->groupid), $searchparams);
- $potentialmemberscount = $DB->count_records_sql('SELECT count(DISTINCT u.id) ' . $sql, $params);
- if ($potentialmemberscount > group_non_members_selector::MAX_USERS_PER_PAGE) {
- return array(get_string('toomanytoshow') => array(),
- get_string('trysearching') => array());
+ if (!$this->is_validating()) {
+ $potentialmemberscount = $DB->count_records_sql('SELECT count(DISTINCT u.id) ' . $sql, $params);
+ if ($potentialmemberscount > group_non_members_selector::MAX_USERS_PER_PAGE) {
+ return $this->too_many_results($search, $potentialmemberscount);
+ }
}
array_unshift($params, $this->courseid);