Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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.
13
//
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/>.
16
 
17
 
18
/**
19
 * radio type form element
20
 *
21
 * Contains HTML class for a radio type element
22
 *
23
 * @package   core_form
24
 * @copyright 2006 Jamie Pratt <me@jamiep.org>
25
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 */
27
 
28
require_once('HTML/QuickForm/radio.php');
29
require_once('templatable_form_element.php');
30
/**
31
 * radio type form element
32
 *
33
 * HTML class for a radio type element
34
 *
35
 * @package   core_form
36
 * @category  form
37
 * @copyright 2006 Jamie Pratt <me@jamiep.org>
38
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39
 */
40
class MoodleQuickForm_radio extends HTML_QuickForm_radio implements templatable {
41
    use templatable_form_element;
42
 
43
    /** @var string html for help button, if empty then no help */
44
    var $_helpbutton='';
45
 
46
    /** @var bool if true label will be hidden. */
47
    protected $_hiddenLabel = false;
48
 
49
    /**
50
     * constructor
51
     *
52
     * @param string $elementName (optional) name of the radio element
53
     * @param string $elementLabel (optional) label for radio element
54
     * @param string $text (optional) Text to put after the radio element
55
     * @param string $value (optional) default value
56
     * @param mixed $attributes (optional) Either a typical HTML attribute string
57
     *              or an associative array
58
     */
59
    public function __construct($elementName=null, $elementLabel=null, $text=null, $value=null, $attributes=null) {
60
        parent::__construct($elementName, $elementLabel, $text, $value, $attributes);
61
    }
62
 
63
    /**
64
     * Old syntax of class constructor. Deprecated in PHP7.
65
     *
66
     * @deprecated since Moodle 3.1
67
     */
68
    public function MoodleQuickForm_radio($elementName=null, $elementLabel=null, $text=null, $value=null, $attributes=null) {
69
        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
70
        self::__construct($elementName, $elementLabel, $text, $value, $attributes);
71
    }
72
 
73
    /**
74
     * get html for help button
75
     *
76
     * @return string html for help button
77
     */
78
    function getHelpButton(){
79
        return $this->_helpbutton;
80
    }
81
 
82
    /**
83
     * Slightly different container template when frozen.
84
     *
85
     * @return string
86
     */
87
    function getElementTemplateType(){
88
        if ($this->_flagFrozen){
89
            return 'static';
90
        } else {
91
            return 'default';
92
        }
93
    }
94
 
95
    /**
96
     * Returns the disabled field. Accessibility: the return "( )" from parent
97
     * class is not acceptable for screenreader users, and we DO want a label.
98
     *
99
     * @return string
100
     */
101
    function getFrozenHtml()
102
    {
103
        $output = '<input type="radio" disabled="disabled" id="'.$this->getAttribute('id').'" ';
104
        if ($this->getChecked()) {
105
            $output .= 'checked="checked" />'.$this->_getPersistantData();
106
        } else {
107
            $output .= '/>';
108
        }
109
        return $output;
110
    }
111
 
112
    /**
113
     * Returns HTML for advchecbox form element.
114
     *
115
     * @return string
116
     */
117
    function toHtml()
118
    {
119
        return '<span>' . parent::toHtml() . '</span>';
120
    }
121
 
122
    /**
123
     * Sets label to be hidden
124
     *
125
     * @param bool $hiddenLabel sets if label should be hidden
126
     */
127
    public function setHiddenLabel($hiddenLabel) {
128
        $this->_hiddenLabel = $hiddenLabel;
129
    }
130
}