1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class Nip_Form_Element_Input_Group |
5
|
|
|
*/ |
6
|
|
|
abstract class Nip_Form_Element_Input_Group extends Nip_Form_Element_Abstract |
|
|
|
|
7
|
|
|
{ |
8
|
|
|
protected $_type = 'input_group'; |
9
|
|
|
protected $_elements = []; |
10
|
|
|
protected $_values = []; |
11
|
|
|
|
12
|
|
|
public function isGroup() |
13
|
|
|
{ |
14
|
|
|
return true; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function isRequestArray() |
18
|
|
|
{ |
19
|
|
|
return false; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function addOptionsArray($options, $valueKey, $labelKey) |
23
|
|
|
{ |
24
|
|
|
foreach ($options as $key => $option) { |
25
|
|
|
$option = (object) $option; |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
$oValue = $option->{$valueKey}; |
29
|
|
|
$oLabel = $option->{$labelKey}; |
30
|
|
|
$oDisabled = $option->disabled; |
31
|
|
|
|
32
|
|
|
if ($oDisabled) { |
33
|
|
|
$atribs['disabled'] = 'disabled'; |
34
|
|
|
} |
35
|
|
|
$this->addOption($oValue, $oLabel, $atribs); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
return $this; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return Nip_Form_Element_Input_Group |
43
|
|
|
*/ |
44
|
3 |
|
public function addOption($value, $label, $attribs = []) |
45
|
|
|
{ |
46
|
3 |
|
$element = $this->getNewElement(); |
47
|
3 |
|
$element->setValue($value); |
48
|
3 |
|
$element->setLabel($label); |
49
|
3 |
|
$element->addAttribs($attribs); |
50
|
|
|
|
51
|
3 |
|
return $this->addElement($element); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return Nip_Form_Element_Abstract |
56
|
|
|
*/ |
57
|
|
|
public function getNewElement() |
58
|
|
|
{ |
59
|
|
|
trigger_error('No new element funtion defined for this group', E_USER_ERROR); |
60
|
|
|
} |
61
|
|
|
|
62
|
3 |
|
public function addElement(Nip_Form_Element_Input_Abstract $element) |
63
|
|
|
{ |
64
|
3 |
|
$key = $element->getValue(); |
|
|
|
|
65
|
3 |
|
$this->_elements[$key] = $element; |
66
|
3 |
|
$this->_values[] = $key; |
67
|
3 |
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getElement($key) |
71
|
|
|
{ |
72
|
|
|
return $this->_elements[$key]; |
73
|
|
|
} |
74
|
|
|
|
75
|
5 |
|
public function getElements() |
76
|
|
|
{ |
77
|
5 |
|
return $this->_elements; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getValues() |
81
|
|
|
{ |
82
|
|
|
return $this->_values; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.