|
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
|
|
|
|
|
16
|
|
|
namespace mrcnpdlk\Grandstream\XMLApp\Application\Model; |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
use mrcnpdlk\Grandstream\XMLApp\MyXML; |
|
20
|
|
|
|
|
21
|
|
|
class Select implements ModelInterface |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* A unique id for the select field |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
private $sName; |
|
29
|
|
|
/** |
|
30
|
|
|
* @var \mrcnpdlk\Grandstream\XMLApp\Application\Model\Styles |
|
31
|
|
|
*/ |
|
32
|
|
|
private $oStyles; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var array |
|
36
|
|
|
*/ |
|
37
|
|
|
private $tItems; |
|
38
|
|
|
|
|
39
|
|
|
public function __construct(string $sName) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->sName = $sName; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return \mrcnpdlk\Grandstream\XMLApp\MyXML |
|
46
|
|
|
*/ |
|
47
|
|
|
public function getXml(): MyXML |
|
48
|
|
|
{ |
|
49
|
|
|
$oXml = new MyXML('select'); |
|
50
|
|
|
$oXml->setName($this->sName); |
|
51
|
|
|
if ($this->oStyles) { |
|
52
|
|
|
$oXml->insertChild($this->oStyles->getXml()->asObject()); |
|
53
|
|
|
} |
|
54
|
|
|
$oItems = new MyXML('items'); |
|
55
|
|
|
foreach ($this->tItems as $item) { |
|
56
|
|
|
$oItem = new MyXML('item'); |
|
57
|
|
|
$oItem->asObject()->addAttribute('value', $item['value']); |
|
58
|
|
|
$oItem->asObject()[0] = $item['name']; |
|
59
|
|
|
$oItems->insertChild($oItem->asObject()); |
|
60
|
|
|
} |
|
61
|
|
|
$oXml->insertChild($oItems->asObject()); |
|
62
|
|
|
|
|
63
|
|
|
return $oXml; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param \mrcnpdlk\Grandstream\XMLApp\Application\Model\Styles $oStyles |
|
68
|
|
|
* |
|
69
|
|
|
* @return \mrcnpdlk\Grandstream\XMLApp\Application\Model\Select |
|
70
|
|
|
*/ |
|
71
|
|
|
public function setStyles(Styles $oStyles) |
|
72
|
|
|
{ |
|
73
|
|
|
$this->oStyles = $oStyles; |
|
74
|
|
|
|
|
75
|
|
|
return $this; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param string $sName |
|
80
|
|
|
* @param string $sValue |
|
81
|
|
|
* |
|
82
|
|
|
* @return \mrcnpdlk\Grandstream\XMLApp\Application\Model\Select |
|
83
|
|
|
*/ |
|
84
|
|
|
public function addItem(string $sName, string $sValue) |
|
85
|
|
|
{ |
|
86
|
|
|
$this->tItems[] = [ |
|
87
|
|
|
'name' => $sName, |
|
88
|
|
|
'value' => $sValue, |
|
89
|
|
|
]; |
|
90
|
|
|
|
|
91
|
|
|
return $this; |
|
92
|
|
|
} |
|
93
|
|
|
} |