TableForm::getAddBaliseTable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace XoopsModules\Extcal;
4
5
\xoops_load('XoopsForm');
6
7
/**
8
 * Form that will output as a theme-enabled HTML table.
9
 *
10
 * Also adds JavaScript to validate required fields
11
 */
12
class TableForm extends \XoopsForm
13
{
14
    /**
15
     * ad the balise html "table" to render.
16
     *
17
     * @var bool|string
18
     */
19
    public $_addBaliseTable = '';
20
21
    /**
22
     * Gets the "value" attribute of a form element.
23
     *
24
     * @param $addBaliseTable
25
     *
26
     * @return string the "value" attribute assigned to a form element, null if not set
27
     * @internal param bool $encode To sanitizer the text?
28
     *
29
     * @internal param string $name the "name" attribute of a form element
30
     */
31
    public function setAddBaliseTable($addBaliseTable)
32
    {
33
        $this->_addBaliseTable = $addBaliseTable;
34
    }
35
36
    /**
37
     * gets the "value" attribute of all form elements.
38
     *
39
     * @return bool|string array of name/value pairs assigned to form elements
40
     * @internal param bool $encode To sanitizer the text?
41
     *
42
     */
43
    public function getAddBaliseTable()
44
    {
45
        return $this->_addBaliseTable;
46
    }
47
48
    /**
49
     * Insert an empty row in the table to serve as a seperator.
50
     *
51
     * @param string $extra HTML to be displayed in the empty row.
52
     * @param string $class CSS class name for <td> tag
53
     */
54
    public function insertBreak($extra = '', $class = '')
55
    {
56
        $class = ('' != $class) ? " class='" . \preg_replace('/[^A-Za-z0-9\s\s_-]/i', '', $class) . "'" : '';
57
        // Fix for $extra tag not showing
58
        if ($extra) {
59
            $extra = '<tr><td colspan="2" ' . $class . '>' . $extra . '</td></tr>';
60
            $this->addElement($extra);
61
        } else {
62
            $extra = '<tr><td colspan="2" ' . $class . '>&nbsp;</td></tr>';
63
            $this->addElement($extra);
64
        }
65
    }
66
67
    /**
68
     * create HTML to output the form as a theme-enabled table with validation.
69
     *
70
     * YOU SHOULD AVOID TO USE THE FOLLOWING Nocolspan METHOD, IT WILL BE REMOVED
71
     *
72
     * To use the noColspan simply use the following example:
73
     *
74
     * $colspan = new \XoopsFormDhtmlTextArea( '', 'key', $value, '100%', '100%' );
75
     * $colspan->setNocolspan();
76
     * $form->addElement( $colspan );
77
     *
78
     * @return string
79
     */
80
    public function render()
81
    {
82
        $addBaliseTable = $this->_addBaliseTable;
83
        $title          = $this->getTitle();
84
        $ret            = '';
85
86
        if ($addBaliseTable) {
87
            $ret .= '<table width="100%" class="outer" cellspacing="1"> ';
88
        }
89
90
        if ('' != $title) {
91
            $ret .= '<tr><th colspan="2">' . $title . '</th></tr>';
92
        }
93
94
        $hidden = '';
95
        $class  = 'even';
96
        foreach ($this->getElements() as $ele) {
97
            if (!\is_object($ele)) {
98
                $ret .= $ele;
99
            } elseif (!$ele->isHidden()) {
100
                if (!$ele->getNocolspan()) {
0 ignored issues
show
Deprecated Code introduced by
The function XoopsFormElement::getNocolspan() has been deprecated: PLEASE AVOID USING THIS METHOD ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

100
                if (!/** @scrutinizer ignore-deprecated */ $ele->getNocolspan()) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
101
                    $ret .= '<tr valign="top" align="left"><td class="head">';
102
                    if ('' != ($caption = $ele->getCaption())) {
103
                        $ret .= '<div class="xoops-form-element-caption' . ($ele->isRequired() ? '-required' : '') . '">';
104
                        $ret .= '<span class="caption-text">' . $caption . '</span>';
105
                        $ret .= '<span class="caption-marker">*</span>';
106
                        $ret .= '</div>';
107
                    }
108
                    if ('' != ($desc = $ele->getDescription())) {
109
                        $ret .= '<div class="xoops-form-element-help">' . $desc . '</div>';
110
                    }
111
                    $ret .= '</td><td class="' . $class . '">' . $ele->render() . '</td></tr>' . NWLINE;
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...
112
                } else {
113
                    $ret .= '<tr valign="top" align="left"><td class="head" colspan="2">';
114
                    if ('' != ($caption = $ele->getCaption())) {
115
                        $ret .= '<div class="xoops-form-element-caption' . ($ele->isRequired() ? '-required' : '') . '">';
116
                        $ret .= '<span class="caption-text">' . $caption . '</span>';
117
                        $ret .= '<span class="caption-marker">*</span>';
118
                        $ret .= '</div>';
119
                    }
120
                    $ret .= '</td></tr><tr valign="top" align="left"><td class="' . $class . '" colspan="2">' . $ele->render() . '</td></tr>';
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...
121
                }
122
            } else {
123
                $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...
124
            }
125
        }
126
127
        if ($addBaliseTable) {
128
            $ret .= '</table>';
129
        }
130
131
        $ret .= NWLINE . ' ' . $hidden . NWLINE;
132
133
        return $ret;
134
    }
135
} // fin de la classe
136