1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Grandstream-XMLApp |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2017 pudelek.org.pl |
6
|
|
|
* |
7
|
|
|
* @license MIT License (MIT) |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view source file |
10
|
|
|
* that is bundled with this package in the file LICENSE |
11
|
|
|
* |
12
|
|
|
* @author Marcin Pudełek <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace mrcnpdlk\Grandstream\XMLApp\Application\Model\Components; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
use mrcnpdlk\Grandstream\XMLApp\Application\Model\Styles; |
19
|
|
|
use mrcnpdlk\Grandstream\XMLApp\Application\ModelConstant; |
20
|
|
|
use mrcnpdlk\Grandstream\XMLApp\Application\ModelInterface; |
21
|
|
|
use mrcnpdlk\Grandstream\XMLApp\MyXML; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class ElemInput |
25
|
|
|
* |
26
|
|
|
* This element is to render input fields on screen so that users could enter necessary information to submit |
27
|
|
|
* or proceed |
28
|
|
|
* |
29
|
|
|
* @package mrcnpdlk\Grandstream\XMLApp\Application\Model |
30
|
|
|
*/ |
31
|
|
|
class ElemInput implements ModelInterface, ElemInterface |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
private $sName; |
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
private $sValue; |
41
|
|
|
/** |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
private $sType; |
45
|
|
|
/** |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
private $sDataType; |
49
|
|
|
/** |
50
|
|
|
* @var integer |
51
|
|
|
*/ |
52
|
|
|
private $iMaxLength; |
53
|
|
|
/** |
54
|
|
|
* @var \mrcnpdlk\Grandstream\XMLApp\Application\Model\Styles |
55
|
|
|
*/ |
56
|
|
|
private $oStyles; |
57
|
|
|
/** |
58
|
|
|
* Only for Radio |
59
|
|
|
* |
60
|
|
|
* @var string |
61
|
|
|
*/ |
62
|
|
|
private $sGroupName; |
63
|
|
|
/** |
64
|
|
|
* Only for Radio |
65
|
|
|
* |
66
|
|
|
* @var boolean |
67
|
|
|
*/ |
68
|
|
|
private $isSelected; |
69
|
|
|
/** |
70
|
|
|
* Only for Radio & CheckBox |
71
|
|
|
* |
72
|
|
|
* @var string |
73
|
|
|
*/ |
74
|
|
|
private $sLabel; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* ElemInput constructor. |
78
|
|
|
* |
79
|
|
|
* @param string $sName |
80
|
|
|
* @param string|null $sValue |
81
|
|
|
* @param string $sType |
82
|
|
|
*/ |
83
|
1 |
|
public function __construct(string $sName, string $sValue = null, string $sType = ModelConstant::TYPE_TEXT) |
84
|
|
|
{ |
85
|
1 |
|
$this->sName = $sName; |
86
|
1 |
|
$this->sValue = $sValue; |
87
|
1 |
|
$this->sType = $sType; |
88
|
1 |
|
$this->setDataType(); |
89
|
1 |
|
$this->setStyles(); |
90
|
1 |
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param string $sDataType |
94
|
|
|
* |
95
|
|
|
* @return ElemInput |
96
|
|
|
*/ |
97
|
1 |
|
public function setDataType(string $sDataType = ModelConstant::DATATYPE_STRING) |
98
|
|
|
{ |
99
|
1 |
|
$this->sDataType = $sDataType; |
100
|
|
|
|
101
|
1 |
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param Styles $oStyles |
106
|
|
|
* |
107
|
|
|
* @return ElemInput |
108
|
|
|
*/ |
109
|
1 |
View Code Duplication |
public function setStyles(Styles $oStyles = null) |
|
|
|
|
110
|
|
|
{ |
111
|
1 |
|
if (is_null($oStyles)) { |
112
|
1 |
|
$oStyles = new Styles(); |
113
|
|
|
} |
114
|
1 |
|
$this->oStyles = $oStyles; |
115
|
|
|
|
116
|
1 |
|
return $this; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param int $iMaxLength |
121
|
|
|
* |
122
|
|
|
* @return ElemInput |
123
|
|
|
*/ |
124
|
|
|
public function setMaxLength(int $iMaxLength) |
125
|
|
|
{ |
126
|
|
|
$this->iMaxLength = $iMaxLength; |
127
|
|
|
|
128
|
|
|
return $this; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param string $sGroupName |
133
|
|
|
* |
134
|
|
|
* @return ElemInput |
135
|
|
|
*/ |
136
|
|
|
public function setGroupName(string $sGroupName) |
137
|
|
|
{ |
138
|
|
|
$this->sGroupName = $sGroupName; |
139
|
|
|
|
140
|
|
|
return $this; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @param string $sLabel |
145
|
|
|
* |
146
|
|
|
* @return ElemInput |
147
|
|
|
*/ |
148
|
|
|
public function setLabel(string $sLabel) |
149
|
|
|
{ |
150
|
|
|
$this->sLabel = $sLabel; |
151
|
|
|
|
152
|
|
|
return $this; |
153
|
|
|
|
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @param bool $isSelected |
158
|
|
|
* |
159
|
|
|
* @return ElemInput |
160
|
|
|
*/ |
161
|
|
|
public function setSelected(bool $isSelected = true) |
162
|
|
|
{ |
163
|
|
|
$this->isSelected = $isSelected; |
164
|
|
|
|
165
|
|
|
return $this; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @return \mrcnpdlk\Grandstream\XMLApp\MyXML |
170
|
|
|
*/ |
171
|
1 |
|
public function getXml(): MyXML |
172
|
|
|
{ |
173
|
1 |
|
$oXml = new MyXML('input'); |
174
|
1 |
|
$oXml->asObject()->addAttribute('name', $this->sName); |
175
|
1 |
|
$oXml->asObject()->addAttribute('value', $this->sValue); |
176
|
1 |
|
$oXml->asObject()->addAttribute('type', $this->sType); |
177
|
1 |
|
if ($this->oStyles) { |
178
|
1 |
|
$oXml->insertChild($this->getStyles()->getXml()->asObject()); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
|
182
|
1 |
|
return $oXml; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @return \mrcnpdlk\Grandstream\XMLApp\Application\Model\Styles |
187
|
|
|
*/ |
188
|
1 |
|
public function getStyles() |
189
|
|
|
{ |
190
|
1 |
|
return $this->oStyles; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @param int $iX |
195
|
|
|
* @param int $iY |
196
|
|
|
* |
197
|
|
|
* @return $this |
198
|
|
|
*/ |
199
|
|
|
public function move(int $iX, int $iY) |
200
|
|
|
{ |
201
|
|
|
$this->getStyles()->move($iX, $iY); |
202
|
|
|
|
203
|
|
|
return $this; |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.