2 require_once('HTML/QuickForm/advcheckbox.php');
5 * HTML class for a advcheckbox type element
7 * default behavior special for Moodle is to return '0' if not checked
10 * * @author Jamie Pratt
13 class MoodleQuickForm_advcheckbox
extends HTML_QuickForm_advcheckbox
{
15 * html for help button, if empty then no help
22 * Group to which this checkbox belongs (for select all/select none button)
30 * @param string $elementName (optional)Input field name attribute
31 * @param string $elementLabel (optional)Input field label
32 * @param string $text (optional)Text to put after the checkbox
33 * @param mixed $attributes (optional)Either a typical HTML attribute string
34 * or an associative array
35 * @param mixed $values (optional)Values to pass if checked or not checked
41 function MoodleQuickForm_advcheckbox($elementName=null, $elementLabel=null, $text=null, $attributes=null, $values=null)
43 if ($values === null){
44 $values = array(0, 1);
47 if (!is_null($attributes['group'])) {
49 $this->_group
= 'checkboxgroup' . $attributes['group'];
50 unset($attributes['group']);
51 if (is_null($attributes)) {
52 $attributes = array();
53 $attributes['class'] .= " $this->_group";
54 } elseif (is_array($attributes)) {
55 if (isset($attributes['class'])) {
56 $attributes['class'] .= " $this->_group";
58 $attributes['class'] = $this->_group
;
60 } elseif ($strpos = stripos($attributes, 'class="')) {
61 $attributes = str_ireplace('class="', 'class="' . $this->_group
. ' ', $attributes);
63 $attributes .= ' class="' . $this->_group
. '"';
67 parent
::HTML_QuickForm_advcheckbox($elementName, $elementLabel, $text, $attributes, $values);
72 * set html for help button
75 * @param array $help array of arguments to make a help button
76 * @param string $function function name to call to get html
78 function setHelpButton($helpbuttonargs, $function='helpbutton'){
79 if (!is_array($helpbuttonargs)){
80 $helpbuttonargs=array($helpbuttonargs);
82 $helpbuttonargs=$helpbuttonargs;
84 //we do this to to return html instead of printing it
85 //without having to specify it in every call to make a button.
86 if ('helpbutton' == $function){
87 $defaultargs=array('', '', 'moodle', true, false, '', true);
88 $helpbuttonargs=$helpbuttonargs +
$defaultargs ;
90 $this->_helpbutton
=call_user_func_array($function, $helpbuttonargs);
93 * get html for help button
96 * @return string html for help button
98 function getHelpButton(){
99 return $this->_helpbutton
;
102 * Automatically generates and assigns an 'id' attribute for the element.
104 * Currently used to ensure that labels work on radio buttons and
105 * advcheckboxes. Per idea of Alexander Radivanovich.
106 * Overriden in moodleforms to remove qf_ prefix.
111 function _generateId()
115 if (!$this->getAttribute('id')) {
116 $this->updateAttributes(array('id' => 'id_'.substr(md5(microtime() . $idx++
), 0, 6)));
118 } // end func _generateId
122 return '<span>' . parent
::toHtml() . '</span>';
126 * Returns the disabled field. Accessibility: the return "[ ]" from parent
127 * class is not acceptable for screenreader users, and we DO want a label.
130 function getFrozenHtml()
132 //$this->_generateId();
133 $output = '<input type="checkbox" disabled="disabled" id="'.$this->getAttribute('id').'" ';
134 if ($this->getChecked()) {
135 $output .= 'checked="checked" />'.$this->_getPersistantData();
140 } //end func getFrozenHtml