MDL-63086 block_rss_client: Move skip time calculation to task
[moodle.git] / lib / form / advcheckbox.php
blob4b9a724cf985761a81ee6e5fb8539ae884ea07a9
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
18 /**
19 * Advanced checkbox type form element
21 * Contains HTML class for an advcheckbox type form element
23 * @package core_form
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');
29 require_once('templatable_form_element.php');
31 /**
32 * HTML class for an advcheckbox type element
34 * Overloaded {@link HTML_QuickForm_advcheckbox} with default behavior modified for Moodle.
35 * This will return '0' if not checked and '1' if checked.
37 * @package core_form
38 * @category form
39 * @copyright 2007 Jamie Pratt <me@jamiep.org>
40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42 class MoodleQuickForm_advcheckbox extends HTML_QuickForm_advcheckbox implements templatable {
44 use templatable_form_element {
45 export_for_template as export_for_template_base;
48 /** @var string html for help button, if empty then no help will icon will be dispalyed. */
49 var $_helpbutton='';
51 /** @var string Group to which this checkbox belongs (for select all/select none button) */
52 var $_group;
54 /**
55 * constructor
57 * @param string $elementName (optional) name of the checkbox
58 * @param string $elementLabel (optional) checkbox label
59 * @param string $text (optional) Text to put after the checkbox
60 * @param mixed $attributes (optional) Either a typical HTML attribute string
61 * or an associative array
62 * @param mixed $values (optional) Values to pass if checked or not checked
64 public function __construct($elementName=null, $elementLabel=null, $text=null, $attributes=null, $values=null)
66 if ($values === null){
67 $values = array(0, 1);
70 if (!empty($attributes['group'])) {
72 $this->_group = 'checkboxgroup' . $attributes['group'];
73 unset($attributes['group']);
74 if (is_null($attributes)) {
75 $attributes = array();
76 $attributes['class'] .= " $this->_group";
77 } elseif (is_array($attributes)) {
78 if (isset($attributes['class'])) {
79 $attributes['class'] .= " $this->_group";
80 } else {
81 $attributes['class'] = $this->_group;
83 } elseif ($strpos = stripos($attributes, 'class="')) {
84 $attributes = str_ireplace('class="', 'class="' . $this->_group . ' ', $attributes);
85 } else {
86 $attributes .= ' class="' . $this->_group . '"';
90 parent::__construct($elementName, $elementLabel, $text, $attributes, $values);
91 $this->_type = 'advcheckbox';
94 /**
95 * Old syntax of class constructor. Deprecated in PHP7.
97 * @deprecated since Moodle 3.1
99 public function MoodleQuickForm_advcheckbox($elementName=null, $elementLabel=null, $text=null, $attributes=null, $values=null) {
100 debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
101 self::__construct($elementName, $elementLabel, $text, $attributes, $values);
105 * get html for help button
107 * @return string html for help button
109 function getHelpButton(){
110 return $this->_helpbutton;
114 * Returns HTML for advchecbox form element.
116 * @return string
118 function toHtml()
120 return '<span>' . parent::toHtml() . '</span>';
124 * Returns the disabled field. Accessibility: the return "[ ]" from parent
125 * class is not acceptable for screenreader users, and we DO want a label.
127 * @return string
129 function getFrozenHtml()
131 //$this->_generateId();
132 $output = '<input type="checkbox" disabled="disabled" id="'.$this->getAttribute('id').'" ';
133 if ($this->getChecked()) {
134 $output .= 'checked="checked" />'.$this->_getPersistantData();
135 } else {
136 $output .= '/>';
138 return $output;
141 public function export_for_template(renderer_base $output) {
142 $context = $this->export_for_template_base($output);
144 $context['selectedvalue'] = $this->_values[1];
145 $context['deselectedvalue'] = $this->_values[0];
146 $context['frozenvalue'] = $this->getValue();
147 return $context;