2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * Advanced checkbox type form element
21 * Contains HTML class for an advcheckbox type form element
24 * @copyright 2007 Jamie Pratt <me@jamiep.org>
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 require_once('HTML/QuickForm/advcheckbox.php');
31 * HTML class for an advcheckbox type element
33 * Overloaded {@link HTML_QuickForm_advcheckbox} with default behavior modified for Moodle.
34 * This will return '0' if not checked and '1' if checked.
38 * @copyright 2007 Jamie Pratt <me@jamiep.org>
39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41 class MoodleQuickForm_advcheckbox
extends HTML_QuickForm_advcheckbox
{
42 /** @var string html for help button, if empty then no help will icon will be dispalyed. */
45 /** @var string Group to which this checkbox belongs (for select all/select none button) */
51 * @param string $elementName (optional) name of the checkbox
52 * @param string $elementLabel (optional) checkbox label
53 * @param string $text (optional) Text to put after the checkbox
54 * @param mixed $attributes (optional) Either a typical HTML attribute string
55 * or an associative array
56 * @param mixed $values (optional) Values to pass if checked or not checked
58 public function __construct($elementName=null, $elementLabel=null, $text=null, $attributes=null, $values=null)
60 if ($values === null){
61 $values = array(0, 1);
64 if (!empty($attributes['group'])) {
66 $this->_group
= 'checkboxgroup' . $attributes['group'];
67 unset($attributes['group']);
68 if (is_null($attributes)) {
69 $attributes = array();
70 $attributes['class'] .= " $this->_group";
71 } elseif (is_array($attributes)) {
72 if (isset($attributes['class'])) {
73 $attributes['class'] .= " $this->_group";
75 $attributes['class'] = $this->_group
;
77 } elseif ($strpos = stripos($attributes, 'class="')) {
78 $attributes = str_ireplace('class="', 'class="' . $this->_group
. ' ', $attributes);
80 $attributes .= ' class="' . $this->_group
. '"';
84 parent
::__construct($elementName, $elementLabel, $text, $attributes, $values);
88 * Old syntax of class constructor. Deprecated in PHP7.
90 * @deprecated since Moodle 3.1
92 public function MoodleQuickForm_advcheckbox($elementName=null, $elementLabel=null, $text=null, $attributes=null, $values=null) {
93 debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER
);
94 self
::__construct($elementName, $elementLabel, $text, $attributes, $values);
98 * get html for help button
100 * @return string html for help button
102 function getHelpButton(){
103 return $this->_helpbutton
;
107 * Returns HTML for advchecbox form element.
113 return '<span>' . parent
::toHtml() . '</span>';
117 * Returns the disabled field. Accessibility: the return "[ ]" from parent
118 * class is not acceptable for screenreader users, and we DO want a label.
122 function getFrozenHtml()
124 //$this->_generateId();
125 $output = '<input type="checkbox" disabled="disabled" id="'.$this->getAttribute('id').'" ';
126 if ($this->getChecked()) {
127 $output .= 'checked="checked" />'.$this->_getPersistantData();