FormRadio   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 12

1 Method

Rating   Name   Duplication   Size   Complexity  
C render() 0 42 12
1
<?php namespace XoopsModules\Tdmcreate\Form;
2
3
/**
4
 * XOOPS form radio compo.
5
 *
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 * This program 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.
12
 *
13
 * @copyright   The XOOPS project https://xoops.org/
14
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
15
 *
16
 * @since       1.91
17
 *
18
 * @author      Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/
19
 * @author      Taiwen Jiang <[email protected]>
20
 *
21
 * @version     $Id: Tdmcreate\FormRadio.php 12360 2014-12-06 13:18:22Z timgno $
22
 */
23
24
class FormRadio extends \XoopsFormRadio
25
{
26
    /**
27
     * Prepare HTML for output.
28
     *
29
     * @return string HTML
30
     */
31
    public function render()
32
    {
33
        $ret = '';
34
        $ele_name = $this->getName();
35
        $ele_title = $this->getTitle();
36
        $ele_value = $this->getValue();
37
        $ele_options = $this->getOptions();
38
        $ele_extra = $this->getExtra();
39
        $ele_delimeter = empty($this->columns) ? $this->getDelimeter() : '';
40
        if (!empty($this->columns)) {
41
            $ret .= '<table class="table table-bordered"><tr>';
42
        }
43
        $i = 0;
44
        $id_ele = 0;
45
        foreach ($ele_options as $value => $name) {
46
            ++$id_ele;
47
            if (!empty($this->columns)) {
48
                if (0 == $i % $this->columns) {
49
                    $ret .= '<tr>';
50
                }
51
                $ret .= '<td class="radio">';
52
            }
53
            $ret .= '<input type="radio" name="'.$ele_name.'" id="'.$ele_name.'['.$value.']'.$id_ele.'" title = "'.htmlspecialchars($ele_title, ENT_QUOTES).'" value="'.htmlspecialchars($value, ENT_QUOTES).'"';
54
            if (isset($ele_value) && $value == $ele_value) {
55
                $ret .= ' checked';
56
            }
57
            $ret .= $ele_extra.' />'."<label name='xolb_{$ele_name}' for='".$ele_name.'['.$value.']'.$id_ele."'><span><span></span></span>".$name.'</label>'.$ele_delimeter;
58
            if (!empty($this->columns)) {
59
                $ret .= '</td>';
60
                if (0 == ++$i % $this->columns) {
61
                    $ret .= '</tr>';
62
                }
63
            }
64
        }
65
        if (!empty($this->columns)) {
66
            if ($span = $i % $this->columns) {
67
                $ret .= '<td colspan="'.($this->columns - $span).'"></td></tr>';
68
            }
69
            $ret .= '</table>';
70
        }
71
72
        return $ret;
73
    }
74
}
75