Completed
Push — master ( 593857...cd1c2d )
by Michael
29s queued 20s
created

Tab   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 45
rs 10
c 0
b 0
f 0
ccs 20
cts 22
cp 0.9091
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A defaultRender() 0 21 5
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
namespace Xoops\Form;
13
14
/**
15
 * Tab - a form tab
16
 *
17
 * @category  Xoops\Form\Tab
18
 * @package   Xoops\Form
19
 * @author    trabis <[email protected]>
20
 * @copyright 2012-2016 XOOPS Project (http://xoops.org)
21
 * @license   GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
22
 * @link      http://xoops.org
23
 */
24
class Tab extends ElementTray
25
{
26
    /**
27
     * __construct
28
     *
29
     * @param string|array $caption Caption or array of all attributes
30
     * @param string       $name    unique identifier for this tab
31
     */
32 1
    public function __construct($caption, $name = null)
33
    {
34 1
        if (is_array($caption)) {
35
            parent::__construct($caption);
36
        } else {
37 1
            parent::__construct([]);
38 1
            $this->setName($name);
39 1
            $this->setCaption($caption);
40
        }
41 1
    }
42
43
    /**
44
     * defaultRender
45
     *
46
     * @return string rendered form element
47
     */
48 1
    public function defaultRender()
49
    {
50 1
        $ret = '';
51
        /* @var $ele Element */
52 1
        foreach ($this->getElements() as $ele) {
53 1
            if ($ele->has('datalist')) {
54
                $ret .= $ele->renderDatalist();
55
            }
56 1
            if (!$ele->isHidden()) {
57 1
                $ret .= '<div class="form-group">';
58 1
                $ret .= '<label>' . $ele->getCaption();
59 1
                $ret .= ($ele->isRequired() ? '<span class="caption-required">*</span>' : '') . '</label>';
60 1
                $ret .= $ele->render();
61 1
                $ret .= '<small class="text-muted">' . $ele->getDescription() . '</small>';
62 1
                $ret .= '<p class="dsc_pattern_vertical">' . $ele->getPatternDescription() . '</p>';
63 1
                $ret .= '</div>' . "\n";
64
            } else {
65 1
                $ret .= $ele->render(). "\n";
66
            }
67
        }
68 1
        return $ret;
69
    }
70
}
71