FormTabTray   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 43
dl 0
loc 83
rs 10
c 0
b 0
f 0
wmc 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B render() 0 52 9
1
<?php
2
3
namespace XoopsModules\Modulebuilder\Form;
4
5
use XoopsModules\Modulebuilder;
6
7
/*
8
 You may not change or alter any portion of this comment or credits
9
 of supporting developers from this source code or any supporting source code
10
 which is considered copyrighted (c) material of the original comment or credit authors.
11
12
 This program is distributed in the hope that it will be useful,
13
 but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
*/
16
/**
17
 * TabTray - a form tray for tabs.
18
 *
19
 * @category  XoopsFormTabTray
20
 *
21
 * @author    trabis <[email protected]>
22
 * @copyright 2012-2014 XOOPS Project (https://xoops.org)
23
 * @license   GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
24
 *
25
 * @link      https://xoops.org
26
 * @since     2.0.0
27
 */
28
\XoopsLoad::load('XoopsFormElementTray');
29
30
/**
31
 * Class Modulebuilder\FormTabTray.
32
 */
33
class FormTabTray extends \XoopsFormElementTray
34
{
35
    /**
36
     * Theme to use for jquery UI.
37
     *
38
     * @var string
39
     */
40
    private $uiTheme = '';
41
    private $delimiter;
42
43
    /**
44
     * __construct.
45
     *
46
     * @param string $caption   tray caption
47
     * @param string $name      Unique identifier for this tray
48
     * @param string $uiTheme   Theme to use for jquery UI (remove? now set by theme)
49
     * @param string $delimiter delimiter
50
     */
51
    public function __construct($caption, $name, $uiTheme = 'base', $delimiter = '&nbsp;')
52
    {
53
        $this->setName($name);
54
        $this->setCaption($caption);
55
        $this->delimiter = $delimiter;
56
        $this->uiTheme   = $uiTheme;
57
    }
58
59
    /**
60
     * create HTML to output the form as a table.
61
     *
62
     * @return string
63
     */
64
    public function render()
65
    {
66
        $GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/jquery.js');
67
        $GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/plugins/jquery.ui.js');
68
        $GLOBALS['xoTheme']->addStylesheet(\XOOPS_URL . '/modules/system/css/ui/' . $this->uiTheme . '/ui.all.css');
69
        $GLOBALS['xoTheme']->addScript('', ['type' => 'text/javascript'], '$(function() { $("#tabs_' . $this->getName() . '").tabs(); });');
70
71
        $ret = '<div id="tabs_' . $this->getName() . '">' . NWLINE;
72
        $ret .= '<ul>' . NWLINE;
73
        foreach ($this->getElements() as $ele) {
74
            if ($ele instanceof Modulebuilder\Form\FormTab) {
75
                $ret .= '<li><a href="#tab_' . $ele->getName() . '"><span>' . $ele->getCaption() . '</span></a></li>' . NWLINE;
76
            }
77
        }
78
        $ret .= '</ul>' . NWLINE;
79
80
        $hidden = '';
81
        $extras = [];
82
83
        foreach ($this->getElements() as $ele) {
84
            /* @var \XoopsFormElement $ele */
85
            if (!$ele->isHidden()) {
86
                if (!$ele instanceof Modulebuilder\Form\FormRaw) {
87
                    if ($ele instanceof Modulebuilder\Form\FormTab) {
88
                        $ret .= '<div id="tab_' . $ele->getName() . '">' . NWLINE;
89
                        $ret .= '<table class="outer" style="border-spacing:5px;">' . NWLINE;
90
                        $ret .= $ele->render();
91
                        $ret .= '</table>' . NWLINE;
92
                        $ret .= '</div>' . NWLINE;
93
                    } else {
94
                        $extras[] = $ele;
95
                    }
96
                } else {
97
                    $ret .= $ele->render();
98
                }
99
            } else {
100
                $hidden .= $ele->render();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $ele->render() targeting XoopsFormElement::render() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
101
            }
102
        }
103
        if (!empty($extras)) {
104
            $tray = new \XoopsFormElementTray('', $this->delimiter);
105
            foreach ($extras as $extra) {
106
                $tray->addElement($extra);
107
            }
108
            $ret .= $tray->render();
109
            $ret .= NWLINE;
110
        }
111
112
        $ret .= $hidden . NWLINE;
113
        $ret .= '</div>' . NWLINE;
114
115
        return $ret;
116
    }
117
}
118