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

TabTray   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Test Coverage

Coverage 83.72%

Importance

Changes 0
Metric Value
eloc 45
dl 0
loc 78
rs 10
c 0
b 0
f 0
ccs 36
cts 43
cp 0.8372
wmc 11

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
B defaultRender() 0 54 9
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
 * TabTray - a form tray for tabs
16
 *
17
 * @category  Xoops\Form\TabTray
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 TabTray 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 tray
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
     * create HTML to output the form as a table
45
     *
46
     * @return string
47
     */
48 1
    public function defaultRender()
49
    {
50 1
        $xoops = \Xoops::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $xoops is dead and can be removed.
Loading history...
51
52 1
        $ret = '<div id="tabs_' . $this->getName() . '">' . "\n";
53 1
        $ret .= '<ul class="nav nav-tabs">' . "\n";
54 1
        $active = ' active';
55 1
        foreach ($this->getElements() as $ele) {
56 1
            if ($ele instanceof Tab) {
57
                $ret .= '<li class="nav' . $active . '"><a href="#tab_' . $ele->getName()
58
                    . '" data-toggle="tab">' . $ele->getCaption() . '</a></li>' . "\n";
59 1
                $active = '';
60
            }
61
        }
62 1
        $ret .= '</ul><br>' . "\n";
63
64 1
        $hidden = '';
65 1
        $extras = array();
66
67 1
        $ret .= '<div class="tab-content">';
68 1
        $active = ' in active';
69
70 1
        foreach ($this->getElements() as $ele) {
71
            /* @var $ele Element */
72 1
            if (!$ele->isHidden()) {
73 1
                if (!$ele instanceof Raw) {
74 1
                    if ($ele instanceof Tab) {
75
                        $ret .= '<div class="tab-pane fade' . $active .'" id="tab_'. $ele->getName() . '">';
76
                        $ret .= $ele->render();
77
                        $ret .= '</div>' . "\n";
78
                        $active = '';
79
                    } else {
80 1
                        $extras[] = $ele;
81
                    }
82
                } else {
83 1
                    $ret .= $ele->render();
84
                }
85
            } else {
86 1
                $hidden .= $ele->render();
87
            }
88
        }
89 1
        if (!empty($extras)) {
90 1
            $tray = new ElementTray('', $this->getJoiner());
91 1
            foreach ($extras as $extra) {
92 1
                $tray->addElement($extra);
93
            }
94 1
            $ret .= $tray->render();
95 1
            $ret .= "\n";
96
        }
97
98 1
        $ret .= $hidden . "\n";
99 1
        $ret .= '</div>' . "\n";
100 1
        $ret .= '</div>' . "\n";
101 1
        return $ret;
102
    }
103
}
104