timeline: if a section is set to hidden and the user is not capable of editing a...
[moodle-blog-course-format.git] / lib / form / select.php
blob92a69cba198143dce8f0af329eab93a2a49f25d4
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;
19 function MoodleQuickForm_select($elementName=null, $elementLabel=null, $options=null, $attributes=null) {
20 parent::HTML_QuickForm_select($elementName, $elementLabel, $options, $attributes);
22 function setHiddenLabel($hiddenLabel){
23 $this->_hiddenLabel = $hiddenLabel;
25 function toHtml(){
26 if ($this->_hiddenLabel){
27 $this->_generateId();
28 return '<label class="accesshide" for="'.$this->getAttribute('id').'" >'.
29 $this->getLabel().'</label>'.parent::toHtml();
30 } else {
31 return parent::toHtml();
34 /**
35 * Automatically generates and assigns an 'id' attribute for the element.
37 * Currently used to ensure that labels work on radio buttons and
38 * checkboxes. Per idea of Alexander Radivanovich.
39 * Overriden in moodleforms to remove qf_ prefix.
41 * @access private
42 * @return void
44 function _generateId()
46 static $idx = 1;
48 if (!$this->getAttribute('id')) {
49 $this->updateAttributes(array('id' => 'id_'. substr(md5(microtime() . $idx++), 0, 6)));
51 } // end func _generateId
52 /**
53 * set html for help button
55 * @access public
56 * @param array $help array of arguments to make a help button
57 * @param string $function function name to call to get html
59 function setHelpButton($helpbuttonargs, $function='helpbutton'){
60 if (!is_array($helpbuttonargs)){
61 $helpbuttonargs=array($helpbuttonargs);
62 }else{
63 $helpbuttonargs=$helpbuttonargs;
65 //we do this to to return html instead of printing it
66 //without having to specify it in every call to make a button.
67 if ('helpbutton' == $function){
68 $defaultargs=array('', '', 'moodle', true, false, '', true);
69 $helpbuttonargs=$helpbuttonargs + $defaultargs ;
71 $this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
73 /**
74 * get html for help button
76 * @access public
77 * @return string html for help button
79 function getHelpButton(){
80 return $this->_helpbutton;
82 /**
83 * Removes an OPTION from the SELECT
85 * @param string $value Value for the OPTION to remove
86 * @since 1.0
87 * @access public
88 * @return void
90 function removeOption($value)
92 $key=array_search($value, $this->_values);
93 if ($key!==FALSE and $key!==null) {
94 unset($this->_values[$key]);
96 foreach ($this->_options as $key=>$option){
97 if ($option['attr']['value']==$value){
98 unset($this->_options[$key]);
99 // we must reindex the options because the ugly code in quickforms' select.php expects that keys are 0,1,2,3... !?!?
100 $this->_options = array_merge($this->_options);
101 return;
104 } // end func removeOption
106 * Removes all OPTIONs from the SELECT
108 * @param string $value Value for the OPTION to remove
109 * @since 1.0
110 * @access public
111 * @return void
113 function removeOptions()
115 $this->_options = array();
116 } // end func removeOption
118 * Slightly different container template when frozen. Don't want to use a label tag
119 * with a for attribute in that case for the element label but instead use a div.
120 * Templates are defined in renderer constructor.
122 * @return string
124 function getElementTemplateType(){
125 if ($this->_flagFrozen){
126 return 'static';
127 } else {
128 return 'default';