4 * Library of functions and constants for user filters
7 require_once($CFG->dirroot
. '/user/filters/user_filter_form.php');
10 * The base user filter.
12 class user_filter_type
{
14 * The name of this filter instance.
18 * The label of this filter instance.
22 * The field database used for filtering data.
26 * The value used for filtering data.
31 * @param string $name the name of the filter instance
32 * @param string $label the label of the filter instance
33 * @param string $field the field used for filtering data
34 * @param string $value the value used for filtering data
36 function user_filter_type($name, $label, $field, $value=null) {
38 $this->_label
= $label;
39 $this->_field
= $field;
40 $this->_value
= $value;
44 * Returns the condition to be used with SQL where
45 * @return string the filtering condition or null if the filter is disabled
47 function getSQLFilter() {
48 return $this->_field
. '="' . $this->_value
. '"';
52 * Retrieves data from the form data
53 * @param object $formdata data submited with the form
55 function checkData($formdata) {
56 $field = $this->_name
;
57 $this->_value
= (string)@$formdata->$field;
61 * Adds controls specific to this filter in the form.
62 * @param object $mform a MoodleForm object to setup
64 function setupForm(&$mform) {
65 $mform->addElement('text', $this->_name
, $this->_label
);
66 $mform->setDefault($this->_name
, $this->_value
);
70 * Returns a human friendly description of the filter.
71 * @return string filter description
73 function getDescription() {
74 return $this->_label
. ' is "' . $this->_value
. '"';