MDL-10496:
[moodle-linuxchix.git] / lib / form / select.php
blob95a1fb4fe40d802e60ce266ad559bbcdd3f65340
1 <?php
2 require_once('HTML/QuickForm/select.php');
4 /**
5 * HTML class for a select type element
7 * @author Jamie Pratt
8 * @access public
9 */
10 class MoodleQuickForm_select extends HTML_QuickForm_select{
11 /**
12 * html for help button, if empty then no help
14 * @var string
16 var $_helpbutton='';
17 var $_hiddenLabel=false;
18 function setHiddenLabel($hiddenLabel){
19 $this->_hiddenLabel = $hiddenLabel;
21 function toHtml(){
22 if ($this->_hiddenLabel){
23 $this->_generateId();
24 return '<label class="accesshide" for="'.$this->getAttribute('id').'" >'.
25 $this->getLabel().'</label>'.parent::toHtml();
26 } else {
27 return parent::toHtml();
30 /**
31 * Automatically generates and assigns an 'id' attribute for the element.
33 * Currently used to ensure that labels work on radio buttons and
34 * checkboxes. Per idea of Alexander Radivanovich.
35 * Overriden in moodleforms to remove qf_ prefix.
37 * @access private
38 * @return void
40 function _generateId()
42 static $idx = 1;
44 if (!$this->getAttribute('id')) {
45 $this->updateAttributes(array('id' => 'id_'. substr(md5(microtime() . $idx++), 0, 6)));
47 } // end func _generateId
48 /**
49 * set html for help button
51 * @access public
52 * @param array $help array of arguments to make a help button
53 * @param string $function function name to call to get html
55 function setHelpButton($helpbuttonargs, $function='helpbutton'){
56 if (!is_array($helpbuttonargs)){
57 $helpbuttonargs=array($helpbuttonargs);
58 }else{
59 $helpbuttonargs=$helpbuttonargs;
61 //we do this to to return html instead of printing it
62 //without having to specify it in every call to make a button.
63 if ('helpbutton' == $function){
64 $defaultargs=array('', '', 'moodle', true, false, '', true);
65 $helpbuttonargs=$helpbuttonargs + $defaultargs ;
67 $this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
69 /**
70 * get html for help button
72 * @access public
73 * @return string html for help button
75 function getHelpButton(){
76 return $this->_helpbutton;
78 /**
79 * Removes an OPTION from the SELECT
81 * @param string $value Value for the OPTION to remove
82 * @since 1.0
83 * @access public
84 * @return void
86 function removeOption($value)
88 $key=array_search($value, $this->_values);
89 if ($key!==FALSE and $key!==null) {
90 unset($this->_values[$key]);
92 foreach ($this->_options as $key=>$option){
93 if ($option['attr']['value']==$value){
94 unset($this->_options[$key]);
95 return;
98 } // end func removeOption
99 /**
100 * Removes all OPTIONs from the SELECT
102 * @param string $value Value for the OPTION to remove
103 * @since 1.0
104 * @access public
105 * @return void
107 function removeOptions()
109 $this->_options = array();
110 } // end func removeOption
112 * Slightly different container template when frozen. Don't want to use a label tag
113 * with a for attribute in that case for the element label but instead use a div.
114 * Templates are defined in renderer constructor.
116 * @return string
118 function getElementTemplateType(){
119 if ($this->_flagFrozen){
120 return 'static';
121 } else {
122 return 'default';