Issues (1149)

class/class.formradio.php (2 issues)

1
<?php
2
/*
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright    XOOPS Project https://xoops.org/
14
 * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
15
 * @package
16
 * @since
17
 * @author       XOOPS Development Team, Kazumi Ono (AKA onokazu)
18
 */
19
20
defined('XOOPS_ROOT_PATH') || exit('XOOPS Root Path not defined');
21
/**
22
 *
23
 *
24
 * @package     kernel
25
 * @subpackage  form
26
 *
27
 * @author      Kazumi Ono <[email protected]>
28
 * @copyright   copyright (c) 2000-2003 XOOPS.org
29
 */
30
31
/**
32
 * A Group of radiobuttons
33
 *
34
 * @author     Kazumi Ono <[email protected]>
35
 * @copyright  copyright (c) 2000-2003 XOOPS.org
36
 *
37
 * @package    kernel
38
 * @subpackage form
39
 */
40
class efqFormRadio extends XoopsFormElement
0 ignored issues
show
The type XoopsFormElement was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
41
{
42
    /**
43
     * Array of Options
44
     * @var array
45
     * @access private
46
     */
47
    public $_options = array();
48
49
    /**
50
     * Pre-selected value
51
     * @var string
52
     * @access private
53
     */
54
    public $_value;
55
56
    /**
57
     * Pre-selected value
58
     * @var string
59
     * @access private
60
     */
61
    public $_linebreak;
62
63
    /**
64
     * Constructor
65
     *
66
     * @param string $caption Caption
67
     * @param string $name    "name" attribute
68
     * @param string $value   Pre-selected value
69
     * @param null   $linebreak
70
     */
71
    public function __construct($caption, $name, $value = null, $linebreak = null)
72
    {
73
        $this->setCaption($caption);
74
        $this->setName($name);
75
        if (isset($value)) {
76
            $this->setValue($value);
77
        }
78
        if (isset($linebreak)) {
79
            $this->setLineBreak($linebreak);
80
        } else {
81
            $this->setLineBreak('');
82
        }
83
    }
84
85
    /**
86
     * Get the pre-selected value
87
     *
88
     * @return string
89
     */
90
    public function getValue()
91
    {
92
        return $this->_value;
93
    }
94
95
    /**
96
     * Get the pre-selected value
97
     *
98
     * @return string
99
     */
100
    public function getLineBreak()
101
    {
102
        return $this->_linebreak;
103
    }
104
105
    /**
106
     * Set the pre-selected value
107
     *
108
     * @param $value string
109
     */
110
    public function setValue($value)
111
    {
112
        $this->_value = $value;
113
    }
114
115
    /**
116
     * Set the pre-selected value
117
     *
118
     * @param $linebreak
119
     * @internal param string $value
120
     */
121
    public function setLineBreak($linebreak)
122
    {
123
        $this->_linebreak = $linebreak;
124
    }
125
126
    /**
127
     * Add an option
128
     *
129
     * @param string $value "value" attribute - This gets submitted as form-data.
130
     * @param string $name  "name" attribute - This is displayed. If empty, we use the "value" instead.
131
     */
132 View Code Duplication
    public function addOption($value, $name = '')
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
133
    {
134
        if ($name !== '') {
135
            $this->_options[$value] = $name;
136
        } else {
137
            $this->_options[$value] = $value;
138
        }
139
    }
140
141
    /**
142
     * Adds multiple options
143
     *
144
     * @param array $options Associative array of value->name pairs.
145
     */
146
    public function addOptionArray($options)
147
    {
148
        if (is_array($options)) {
149
            foreach ($options as $k => $v) {
150
                $this->addOption($k, $v);
151
            }
152
        }
153
    }
154
155
    /**
156
     * Gets the options
157
     *
158
     * @return array Associative array of value->name pairs.
159
     */
160
    public function getOptions()
161
    {
162
        return $this->_options;
163
    }
164
165
    /**
166
     * Prepare HTML for output
167
     *
168
     * @return string HTML
169
     */
170
    public function render()
171
    {
172
        $ret = '';
173
        foreach ($this->getOptions() as $value => $name) {
174
            $ret      .= "<input type='radio' name='" . $this->getName() . '\' value=\'' . $value . '\'';
175
            $selected = $this->getValue();
176
            if (isset($selected) && ($value == $selected)) {
177
                $ret .= ' checked';
178
            }
179
            $ret .= $this->getExtra() . '>' . $name . '' . $this->getLineBreak() . "\n";
180
        }
181
182
        return $ret;
183
    }
184
}
185