timeline: if a section is set to hidden and the user is not capable of editing a...
[moodle-blog-course-format.git] / lib / form / text.php
blob26209d27ef8afd715ba4854773012b544857c4f2
1 <?php
2 require_once("HTML/QuickForm/text.php");
4 /**
5 * HTML class for a text type element
7 * @author Jamie Pratt
8 * @access public
9 */
10 class MoodleQuickForm_text extends HTML_QuickForm_text{
11 /**
12 * html for help button, if empty then no help
14 * @var string
16 var $_helpbutton='';
17 var $_hiddenLabel=false;
19 function MoodleQuickForm_text($elementName=null, $elementLabel=null, $attributes=null) {
20 parent::HTML_QuickForm_text($elementName, $elementLabel, $attributes);
23 function setHiddenLabel($hiddenLabel){
24 $this->_hiddenLabel = $hiddenLabel;
26 function toHtml(){
27 if ($this->_hiddenLabel){
28 $this->_generateId();
29 return '<label class="accesshide" for="'.$this->getAttribute('id').'" >'.
30 $this->getLabel().'</label>'.parent::toHtml();
31 } else {
32 return parent::toHtml();
35 /**
36 * Automatically generates and assigns an 'id' attribute for the element.
38 * Currently used to ensure that labels work on radio buttons and
39 * checkboxes. Per idea of Alexander Radivanovich.
40 * Overriden in moodleforms to remove qf_ prefix.
42 * @access private
43 * @return void
45 function _generateId()
47 static $idx = 1;
49 if (!$this->getAttribute('id')) {
50 $this->updateAttributes(array('id' => 'id_'. substr(md5(microtime() . $idx++), 0, 6)));
52 } // end func _generateId
53 /**
54 * set html for help button
56 * @access public
57 * @param array $help array of arguments to make a help button
58 * @param string $function function name to call to get html
60 function setHelpButton($helpbuttonargs, $function='helpbutton'){
61 if (!is_array($helpbuttonargs)){
62 $helpbuttonargs=array($helpbuttonargs);
63 }else{
64 $helpbuttonargs=$helpbuttonargs;
66 //we do this to to return html instead of printing it
67 //without having to specify it in every call to make a button.
68 if ('helpbutton' == $function){
69 $defaultargs=array('', '', 'moodle', true, false, '', true);
70 $helpbuttonargs=$helpbuttonargs + $defaultargs ;
72 $this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
74 /**
75 * get html for help button
77 * @access public
78 * @return string html for help button
80 function getHelpButton(){
81 return $this->_helpbutton;
83 /**
84 * Slightly different container template when frozen. Don't want to use a label tag
85 * with a for attribute in that case for the element label but instead use a div.
86 * Templates are defined in renderer constructor.
88 * @return string
90 function getElementTemplateType(){
91 if ($this->_flagFrozen){
92 return 'static';
93 } else {
94 return 'default';