Moodle  2.2.1
http://www.collinsharper.com
user_selector_base Class Reference
Inheritance diagram for user_selector_base:

Public Member Functions

 __construct ($name, $options=array())
 exclude ($arrayofuserids)
 clear_exclusions ()
 get_exclusions ()
 get_selected_users ()
 get_selected_user ()
 invalidate_selected_users ()
 display ($return=false)
 set_rows ($numrows)
 get_rows ()
 set_multiselect ($multiselect)
 is_multiselect ()
 get_name ()
 set_extra_fields ($fields)
 find_users ($search)
 output_user ($user)

Protected Member Functions

 get_options ()
 is_validating ()
 load_selected_users ()
 required_fields_sql ($u)
 search_sql ($search, $u)
 too_many_results ($search, $count)
 output_options ($groupedusers, $search)
 output_optgroup ($groupname, $users, $select)
 search_button_caption ()
 initialise_javascript ($search)

Protected Attributes

 $name
 $extrafields
 $accesscontext
 $multiselect = true
 $rows = USER_SELECTOR_DEFAULT_ROWS
 $exclude = array()
 $selected = null
 $preserveselected = false
 $autoselectunique = false
 $searchanywhere = false
 $validatinguserids = null

Static Protected Attributes

static $jsmodule

Detailed Description

Base class for user selectors.

In your theme, you must give each user-selector a defined width. If the user selector has name="myid", then the div myid_wrapper must have a width specified.

Definition at line 38 of file lib.php.


Constructor & Destructor Documentation

__construct ( name,
options = array() 
)

Constructor. Each subclass must have a constructor with this signature.

Parameters:
string$namethe control name/id for use in the HTML.
array$optionsother options needed to construct this selector. You must be able to clone a userselector by doing new get_class($us)($us->get_name(), $us->get_options());

Reimplemented in forum_potential_subscriber_selector, forum_subscriber_selector_base, existing_role_holders, role_assign_user_selector_base, groups_user_selector_base, mnetservice_enrol_potential_users_selector, mnetservice_enrol_existing_users_selector, cohort_existing_selector, cohort_candidate_selector, enrol_manual_current_participant, service_user_selector, and enrol_manual_potential_participant.

Definition at line 90 of file lib.php.

Here is the call graph for this function:


Member Function Documentation

Clear the list of excluded user ids.

Definition at line 139 of file lib.php.

display ( return = false)

Output this user_selector as HTML.

Parameters:
boolean$returnif true, return the HTML as a string instead of outputting it.
Returns:
mixed if $return is true, returns the HTML as a string, otherwise returns nothing.

Definition at line 196 of file lib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

exclude ( arrayofuserids)

All to the list of user ids that this control will not select. For example, on the role assign page, we do not list the users who already have the role in question.

Parameters:
array$arrayofuseridsthe user ids to exclude.

Definition at line 132 of file lib.php.

Here is the caller graph for this function:

find_users ( search) [abstract]

Search the database for users matching the $search string, and any other 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 and in admin/roles/lib.php. They should help you see exactly what you have to do.

Parameters:
string$searchthe search string.
Returns:
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 arrays should be userids, and the values should be user objects containing at least the list of fields returned by the method required_fields_sql(). If a user object has a ->disabled property that is true, then that option will be displayed greyed out, and will not be returned by get_selected_users.

Reimplemented in forum_existing_subscriber_selector, forum_potential_subscriber_selector, admins_existing_selector, admins_potential_selector, existing_role_holders, potential_assignees_course_and_above, potential_assignees_below_course, group_non_members_selector, group_members_selector, mnetservice_enrol_potential_users_selector, mnetservice_enrol_existing_users_selector, cohort_existing_selector, cohort_candidate_selector, enrol_manual_current_participant, service_user_selector, and enrol_manual_potential_participant.

Here is the caller graph for this function:

Returns:
array the list of user ids that this control will not select.

Definition at line 146 of file lib.php.

Here is the call graph for this function:

get_name ( )
Returns:
string the id/name that this control will have in the HTML.

Definition at line 290 of file lib.php.

get_options ( ) [protected]

Note: this function must be implemented if you use the search ajax field (e.g. set $options['file'] = '/admin/filecontainingyourclass.php';)

Returns:
array the options needed to recreate this user_selector.

Reimplemented in forum_potential_subscriber_selector, forum_subscriber_selector_base, admins_existing_selector, admins_potential_selector, role_assign_user_selector_base, groups_user_selector_base, mnetservice_enrol_potential_users_selector, mnetservice_enrol_existing_users_selector, cohort_existing_selector, cohort_candidate_selector, enrol_manual_current_participant, service_user_selector, and enrol_manual_potential_participant.

Definition at line 341 of file lib.php.

Here is the call graph for this function:

get_rows ( )
Returns:
integer the height this control will be displayed, in rows.

Definition at line 267 of file lib.php.

Convenience method for when multiselect is false (throws an exception if not).

Returns:
object the selected user object, or null if none.

Definition at line 167 of file lib.php.

Here is the call graph for this function:

Returns:
array of user objects. The users that were selected. This is a more sophisticated version of optional_param($this->name, array(), PARAM_INTEGER) that validates the returned list of ids against the rules for this user selector.

Definition at line 155 of file lib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

initialise_javascript ( search) [protected]
Parameters:
boolean$optiontrackerif true, initialise JavaScript for updating the user prefs.
Returns:
any HTML needed here.

Definition at line 649 of file lib.php.

Here is the caller graph for this function:

If you update the database in such a way that it is likely to change the list of users that this component is allowed to select from, then you must call this method. For example, on the role assign page, after you have assigned some roles to some users, you should call this.

Definition at line 187 of file lib.php.

Returns:
boolean whether this control will allow selection of more than one user.

Definition at line 283 of file lib.php.

is_validating ( ) [protected]
Returns:
boolean if true, we are validating a list of selected users, rather than preparing a list of uesrs to choose from.

Definition at line 358 of file lib.php.

Here is the caller graph for this function:

load_selected_users ( ) [protected]

Get the list of users that were selected by doing optional_param then validating the result.

Returns:
array of user objects.

Definition at line 368 of file lib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

output_optgroup ( groupname,
users,
select 
) [protected]

Output one particular optgroup. Used by the preceding function output_options.

Parameters:
string$groupnamethe label for this optgroup.
array$usersthe users to put in this optgroup.
boolean$selectif true, select the users in this group.
Returns:
string HTML code.

Definition at line 568 of file lib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

output_options ( groupedusers,
search 
) [protected]

Output the list of <optgroup>s and <options>s that go inside the select. This method should do the same as the JavaScript method user_selector.prototype.handle_response.

Parameters:
array$groupedusersan array, as returned by find_users.
Returns:
string HTML code.

Definition at line 520 of file lib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

output_user ( user)

Convert a user object to a string suitable for displaying as an option in the list box.

Parameters:
object$userthe user to display.
Returns:
string a string representation of the user.

Reimplemented in group_non_members_selector.

Definition at line 596 of file lib.php.

Here is the caller graph for this function:

required_fields_sql ( u) [protected]
Parameters:
string$uthe table alias for the user table in the query being built. May be ''.
Returns:
string fragment of SQL to go in the select list of the query.

Definition at line 408 of file lib.php.

Here is the caller graph for this function:

search_button_caption ( ) [protected]
Returns:
string the caption for the search button.

Definition at line 611 of file lib.php.

Here is the caller graph for this function:

search_sql ( search,
u 
) [protected]
Parameters:
string$searchthe text to search for.
string$uthe table alias for the user table in the query being built. May be ''.
Returns:
array an array with two elements, a fragment of SQL to go in the where clause the query, and an array containing any required parameters. this uses ? style placeholders.

Definition at line 430 of file lib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

set_extra_fields ( fields)

Set the user fields that are displayed in the selector in addition to the user's name.

Parameters:
array$fieldsa list of field names that exist in the user table.

Definition at line 300 of file lib.php.

set_multiselect ( multiselect)

Whether this control will allow selection of many, or just one user.

Parameters:
boolean$multiselecttrue = allow multiple selection.

Definition at line 276 of file lib.php.

set_rows ( numrows)

The height this control will be displayed, in rows.

Parameters:
integer$numrowsthe desired height.

Definition at line 260 of file lib.php.

too_many_results ( search,
count 
) [protected]

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.

Parameters:
string$searchthe search term, as passed in to the find users method.
int$countthe number of users that currently match.
Returns:
array in the right format to return from the find_users method.

Definition at line 499 of file lib.php.

Here is the caller graph for this function:


Field Documentation

$accesscontext [protected]

Definition at line 45 of file lib.php.

$autoselectunique = false [protected]

Definition at line 58 of file lib.php.

$exclude = array() [protected]

Definition at line 51 of file lib.php.

$extrafields [protected]

Definition at line 42 of file lib.php.

$jsmodule [static, protected]
Initial value:
 array(
                'name' => 'user_selector',
                'fullpath' => '/user/selector/module.js',
                'requires'  => array('node', 'event-custom', 'datasource', 'json'),
                'strings' => array(
                    array('previouslyselectedusers', 'moodle', '%%SEARCHTERM%%'),
                    array('nomatchingusers', 'moodle', '%%SEARCHTERM%%'),
                    array('none', 'moodle')
                ))

Definition at line 70 of file lib.php.

$multiselect = true [protected]

Definition at line 47 of file lib.php.

$name [protected]

Definition at line 40 of file lib.php.

$preserveselected = false [protected]

Definition at line 56 of file lib.php.

$rows = USER_SELECTOR_DEFAULT_ROWS [protected]

Definition at line 49 of file lib.php.

$searchanywhere = false [protected]

Definition at line 61 of file lib.php.

$selected = null [protected]

Definition at line 53 of file lib.php.

$validatinguserids = null [protected]

Definition at line 63 of file lib.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations