Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / lib / form / advcheckbox.php
blob43cd2d3a6839d0fa6808783e08358da5616d857e
1 <?php
2 require_once('HTML/QuickForm/advcheckbox.php');
4 /**
5 * HTML class for a advcheckbox type element
7 * default behavior special for Moodle is to return '0' if not checked
8 * '1' for checked.
10 * * @author Jamie Pratt
11 * @access public
13 class MoodleQuickForm_advcheckbox extends HTML_QuickForm_advcheckbox{
14 /**
15 * html for help button, if empty then no help
17 * @var string
19 var $_helpbutton='';
20 /**
21 * Class constructor
23 * @param string $elementName (optional)Input field name attribute
24 * @param string $elementLabel (optional)Input field label
25 * @param string $text (optional)Text to put after the checkbox
26 * @param mixed $attributes (optional)Either a typical HTML attribute string
27 * or an associative array
28 * @param mixed $values (optional)Values to pass if checked or not checked
30 * @since 1.0
31 * @access public
32 * @return void
34 function MoodleQuickForm_advcheckbox($elementName=null, $elementLabel=null, $text=null, $attributes=null, $values=null)
36 if ($values === null){
37 $values = array(0, 1);
39 parent::HTML_QuickForm_advcheckbox($elementName, $elementLabel, $text, $attributes, $values);
40 } //end constructor
43 /**
44 * set html for help button
46 * @access public
47 * @param array $help array of arguments to make a help button
48 * @param string $function function name to call to get html
50 function setHelpButton($helpbuttonargs, $function='helpbutton'){
51 if (!is_array($helpbuttonargs)){
52 $helpbuttonargs=array($helpbuttonargs);
53 }else{
54 $helpbuttonargs=$helpbuttonargs;
56 //we do this to to return html instead of printing it
57 //without having to specify it in every call to make a button.
58 if ('helpbutton' == $function){
59 $defaultargs=array('', '', 'moodle', true, false, '', true);
60 $helpbuttonargs=$helpbuttonargs + $defaultargs ;
62 $this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
64 /**
65 * get html for help button
67 * @access public
68 * @return string html for help button
70 function getHelpButton(){
71 return $this->_helpbutton;
73 /**
74 * Automatically generates and assigns an 'id' attribute for the element.
76 * Currently used to ensure that labels work on radio buttons and
77 * advcheckboxes. Per idea of Alexander Radivanovich.
78 * Overriden in moodleforms to remove qf_ prefix.
80 * @access private
81 * @return void
83 function _generateId()
85 static $idx = 1;
87 if (!$this->getAttribute('id')) {
88 $this->updateAttributes(array('id' => 'id_'.substr(md5(microtime() . $idx++), 0, 6)));
90 } // end func _generateId
91 /**
92 * Slightly different container template when frozen. Don't want to use a label tag
93 * with a for attribute in that case for the element label but instead use a div.
94 * Templates are defined in renderer constructor.
96 * @return string
98 function getElementTemplateType(){
99 if ($this->_flagFrozen){
100 return 'static';
101 } else {
102 return 'default';