|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 require_once($CFG->dirroot.'/user/filters/lib.php'); 00004 00008 class user_filter_simpleselect extends user_filter_type { 00012 var $_options; 00013 00014 var $_field; 00015 00024 function user_filter_simpleselect($name, $label, $advanced, $field, $options) { 00025 parent::user_filter_type($name, $label, $advanced); 00026 $this->_field = $field; 00027 $this->_options = $options; 00028 } 00029 00034 function setupForm(&$mform) { 00035 $choices = array(''=>get_string('anyvalue', 'filters')) + $this->_options; 00036 $mform->addElement('select', $this->_name, $this->_label, $choices); 00037 if ($this->_advanced) { 00038 $mform->setAdvanced($this->_name); 00039 } 00040 } 00041 00047 function check_data($formdata) { 00048 $field = $this->_name; 00049 00050 if (array_key_exists($field, $formdata) and $formdata->$field !== '') { 00051 return array('value'=>(string)$formdata->$field); 00052 } 00053 00054 return false; 00055 } 00056 00062 function get_sql_filter($data) { 00063 static $counter = 0; 00064 $name = 'ex_simpleselect'.$counter++; 00065 00066 $value = $data['value']; 00067 $params = array(); 00068 $field = $this->_field; 00069 if ($value == '') { 00070 return ''; 00071 } 00072 return array("$field=:$name", array($name=>$value)); 00073 } 00074 00080 function get_label($data) { 00081 $value = $data['value']; 00082 00083 $a = new stdClass(); 00084 $a->label = $this->_label; 00085 $a->value = '"'.s($this->_options[$value]).'"'; 00086 $a->operator = get_string('isequalto','filters'); 00087 00088 return get_string('selectlabel', 'filters', $a); 00089 } 00090 } 00091