|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Nip\Form\Elements\AbstractElement; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class Nip_Form_Element_Input_Group |
|
7
|
|
|
*/ |
|
8
|
|
|
abstract class Nip_Form_Element_Input_Group extends AbstractElement |
|
9
|
|
|
{ |
|
10
|
|
|
protected $_type = 'input_group'; |
|
11
|
|
|
protected $_elements = []; |
|
12
|
|
|
protected $_values = []; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @return bool |
|
16
|
|
|
*/ |
|
17
|
|
|
public function isGroup() |
|
18
|
|
|
{ |
|
19
|
|
|
return true; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @return bool |
|
24
|
|
|
*/ |
|
25
|
|
|
public function isRequestArray() |
|
26
|
|
|
{ |
|
27
|
|
|
return false; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param $options |
|
32
|
|
|
* @param $valueKey |
|
33
|
|
|
* @param $labelKey |
|
34
|
|
|
* |
|
35
|
|
|
* @return $this |
|
36
|
|
|
*/ |
|
37
|
|
|
public function addOptionsArray($options, $valueKey, $labelKey) |
|
38
|
|
|
{ |
|
39
|
|
|
foreach ($options as $key => $option) { |
|
40
|
|
|
$option = (object)$option; |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
$oValue = $option->{$valueKey}; |
|
44
|
|
|
$oLabel = $option->{$labelKey}; |
|
45
|
|
|
$oDisabled = $option->disabled; |
|
46
|
|
|
|
|
47
|
|
|
if ($oDisabled) { |
|
48
|
|
|
$atribs['disabled'] = 'disabled'; |
|
49
|
|
|
} |
|
50
|
|
|
$this->addOption($oValue, $oLabel, $atribs); |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return $this; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param $value |
|
58
|
|
|
* @param $label |
|
59
|
|
|
* @param array $attribs |
|
60
|
|
|
* |
|
61
|
|
|
* @return Nip_Form_Element_Input_Group |
|
62
|
|
|
*/ |
|
63
|
3 |
|
public function addOption($value, $label, $attribs = []) |
|
64
|
|
|
{ |
|
65
|
3 |
|
$element = $this->getNewElement(); |
|
66
|
3 |
|
$element->setValue($value); |
|
67
|
3 |
|
$element->setLabel($label); |
|
68
|
3 |
|
$element->addAttribs($attribs); |
|
69
|
|
|
|
|
70
|
3 |
|
return $this->addElement($element); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return AbstractElement |
|
75
|
|
|
*/ |
|
76
|
|
|
abstract public function getNewElement(); |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param Nip_Form_Element_Input_Abstract $element |
|
80
|
|
|
* |
|
81
|
|
|
* @return $this |
|
82
|
|
|
*/ |
|
83
|
3 |
|
public function addElement(AbstractElement $element) |
|
84
|
|
|
{ |
|
85
|
3 |
|
$key = $element->getValue(); |
|
|
|
|
|
|
86
|
3 |
|
$this->_elements[$key] = $element; |
|
87
|
3 |
|
$this->_values[] = $key; |
|
88
|
|
|
|
|
89
|
3 |
|
return $this; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param $key |
|
94
|
|
|
* |
|
95
|
|
|
* @return mixed |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getElement($key) |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->_elements[$key]; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @return array |
|
104
|
|
|
*/ |
|
105
|
5 |
|
public function getElements() |
|
106
|
|
|
{ |
|
107
|
5 |
|
return $this->_elements; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @return array |
|
112
|
|
|
*/ |
|
113
|
|
|
public function getValues() |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->_values; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|