Passed
Push — master ( 3298e6...1af9f1 )
by Goffy
03:33
created

FormTextDouble::setVisible()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace XoopsModules\Wgevents\Forms;
4
5
/**
6
 * XOOPS button
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
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 *
15
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
16
 * @license             GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html)
17
 * @package             kernel
18
 * @subpackage          form
19
 * @since               2.0.0
20
 * @author              Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/
21
 */
22
23
use XoopsFormText;
24
25
\defined('XOOPS_ROOT_PATH') || exit('Restricted access');
26
27
/**
28
 * base class
29
 */
30
\xoops_load('\XoopsFormText');
31
32
/**
33
 * Create Line with two textboxes and an add/remove button
34
 */
35
class FormTextDouble extends \XoopsFormText
36
{
37
38
    /**
39
     * param for show/hide fee wrapper
40
     * @var bool
41
     */
42
    private $visible;
43
44
    /**
45
     * placeholder first textbox
46
     *
47
     * @var array
48
     */
49
    private $elements;
50
51
    /**
52
     * placeholder first textbox
53
     *
54
     * @var string
55
     */
56
    private $placeholder1;
57
58
    /**
59
     * placeholder second textbox
60
     *
61
     * @var string
62
     */
63
    private $placeholder2;
64
65
    /**
66
     * create HTML to output the group of text fields
67
     *
68
     * @return string
69
     */
70
    public function render()
71
    {
72
73
        $ret =  "<div id='wrapper_fee'";
74
        if (!$this->getVisible()) {
75
            $ret .=  " style='display:none'";
76
        }
77
        $ret .=  '>';
78
79
        foreach($this->getElements() as $key => $ele) {
80
            $ret .=  "<span><input class='form-control " . $this->getClass() . "' type='text' name='"
0 ignored issues
show
Bug introduced by
Are you sure $this->getClass() of type false|string can be used in concatenation? ( Ignorable by Annotation )

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

80
            $ret .=  "<span><input class='form-control " . /** @scrutinizer ignore-type */ $this->getClass() . "' type='text' name='"
Loading history...
81
                . $this->getName() . "[]' title='" . $this->getTitle() . "' style='width:15%' maxlength='20' 
82
            value='" . $ele[0] . "'" . $this->getExtra();
83
            $ret .= ' />';
84
            $ret .=  "&nbsp;<input class='form-control " . $this->getClass() . "' type='text' name='"
85
                . $this->getName() . "desc[]' title='" . $this->getTitle() . "' style='width:70%' maxlength='255' 
86
            value='" . $ele[1] . "'" . $this->getExtra();
87
            if ($ele['placeholder']) {
88
                $ret .= ' placeholder="' . $ele['placeholder'] . '"';
89
            }
90
            $ret .= ' />';
91
92
            if (0 === (int)$key) {
93
                // button to add new group
94
                $ret .= '<a class="btn_fee_add btn btn-xs" href="javascript:void(0);" ><img src="' . \WGEVENTS_ICONS_URL_32 . '/add.png"/></a>';
95
            } else {
96
                $ret .= '<a class="btn_fee_remove btn btn-xs" href="javascript:void(0);"><img src="' . \WGEVENTS_ICONS_URL_32 . '/remove.png"/></a>';
97
            }
98
99
            $ret .= '</span>';
100
        }
101
        $ret .= '</div>';
102
103
        // add one hidden group as template for new lines
104
        $ret .=  "<div id='hidden_group' class='hidden'><span><input class='form-control " . $this->getClass() . "' type='text' name='"
105
            . $this->getName() . "[]' title='" . $this->getTitle() . "' style='width:15%' maxlength='20' 
106
        value=''" . $this->getExtra();
107
        if ($this->placeholder1) {
108
            $ret .= ' placeholder="' . $this->getPlaceholder1() . '"';
109
        }
110
        $ret .= ' />';
111
        $ret .=  "&nbsp;<input class='form-control " . $this->getClass() . "' type='text' name='"
112
            . $this->getName() . "desc[]' title='" . $this->getTitle() . "' style='width:70%' maxlength='255' 
113
        value=''" . $this->getExtra();
114
        if ($this->placeholder2) {
115
            $ret .= ' placeholder="' . $this->getPlaceholder2() . '"';
116
        }
117
        $ret .= ' />';
118
        $ret .= '<a class="btn_fee_remove btn btn-xs" href="javascript:void(0);"><img src="' . \WGEVENTS_ICONS_URL_32 . '/remove.png"/></a>';
119
        $ret .= '</span></div>';
120
        // end hidden group
121
122
        return $ret;
123
124
    }
125
126
    /**
127
     * Get elements
128
     *
129
     * @return array
130
     */
131
    public function getElements() {
132
133
        return $this->elements;
134
135
    }
136
137
    /**
138
     * Set elements
139
     *
140
     * @param array $value
141
     */
142
    public function setElements($value) {
143
144
        $this->elements = $value;
145
146
    }
147
148
    /**
149
     * Get first placeholder value
150
     *
151
     * @return string
152
     */
153
    public function getPlaceholder1() {
154
155
        return $this->placeholder1;
156
157
    }
158
159
    /**
160
     * Set first placeholder value
161
     *
162
     * @param string $value
163
     */
164
    public function setPlaceholder1($value) {
165
166
        $this->placeholder1 = $value;
167
168
    }
169
170
    /**
171
     * Get second placeholder value
172
     *
173
     * @return string
174
     */
175
    public function getPlaceholder2() {
176
177
        return $this->placeholder2;
178
179
    }
180
181
    /**
182
     * Set second placeholder value
183
     *
184
     * @param string $value
185
     */
186
    public function setPlaceholder2($value) {
187
188
        $this->placeholder2 = $value;
189
190
    }
191
192
    /**
193
     * Set value for show/hide fee wrapper
194
     *
195
     * @param bool $value
196
     */
197
    public function setVisible($value) {
198
199
        $this->visible = $value;
200
201
    }
202
203
    /**
204
     * Get value for show/hide fee wrapper
205
     *
206
     * @return bool
207
     */
208
    public function getVisible() {
209
210
        return $this->visible;
211
212
    }
213
}
214