1 | <?php |
||
36 | trait DomDynamicSelectByDanielGP |
||
37 | { |
||
38 | |||
39 | protected function buildSelectId($selectName, $featArray) |
||
47 | |||
48 | /** |
||
49 | * Calculate the optimal for all options within a select tag |
||
50 | * |
||
51 | * @param array $aElements |
||
52 | * @param array $aFeatures |
||
53 | * @return string|int |
||
54 | */ |
||
55 | private function calculateSelectOptionsSize($aElements, $aFeatures = []) |
||
56 | { |
||
57 | $selectSize = $this->calculateSelectOptionsSizeForced($aElements, $aFeatures); |
||
58 | if ((in_array('include_null', $aFeatures)) && ($selectSize != '1')) { |
||
59 | $selectSize++; |
||
60 | } |
||
61 | return $selectSize; |
||
62 | } |
||
63 | |||
64 | private function calculateSelectOptionsSizeForced($aElements, $aFeatures = []) |
||
65 | { |
||
66 | if (isset($aFeatures['size'])) { |
||
67 | if ($aFeatures['size'] == 0) { |
||
68 | return count($aElements); |
||
69 | } |
||
70 | return min(count($aElements), $aFeatures['size']); |
||
71 | } |
||
72 | return 1; |
||
73 | } |
||
74 | |||
75 | private function eventOnChange($featArray) |
||
76 | { |
||
77 | $sReturn = null; |
||
78 | if (array_key_exists('additional_javascript_action', $featArray)) { |
||
79 | $sReturn[] = $featArray['additional_javascript_action']; |
||
80 | } |
||
81 | if (array_key_exists('autosubmit', $featArray)) { |
||
82 | $sReturn[] = 'submit();'; |
||
83 | } |
||
84 | if (is_array($sReturn)) { |
||
85 | return ' onchange="javascript:' . implode('', $sReturn) . '"'; |
||
86 | } |
||
87 | return $sReturn; |
||
88 | } |
||
89 | |||
90 | private function featureArraySimpleTranslated($featArray, $identifier) |
||
91 | { |
||
92 | $translation = [ |
||
93 | 'disabled' => ' disabled', |
||
94 | 'hidden' => ' style="visibility: hidden;', |
||
95 | 'include_null' => '<option value="NULL"> </option>', |
||
96 | 'multiselect' => ' multiple="multiple"', |
||
97 | 'style' => null, |
||
98 | 'styleForOption' => null, |
||
99 | ]; |
||
100 | if (array_key_exists($identifier, $featArray)) { |
||
101 | if (is_null($translation[$identifier])) { |
||
102 | return ' ' . $identifier . '="' . $featArray[$identifier] . '"'; |
||
103 | } |
||
104 | return $translation[$identifier]; |
||
105 | } |
||
106 | return ''; |
||
107 | } |
||
108 | |||
109 | private function normalizeFeatureArray($featArray) |
||
110 | { |
||
111 | $nonAsociative = ['autosubmit', 'disabled', 'hidden', 'include_null', 'multiselect']; |
||
112 | foreach ($featArray as $key => $value) { |
||
113 | if (in_array($value, $nonAsociative)) { |
||
114 | $featArray[$value] = $value; |
||
115 | unset($featArray[$key]); |
||
116 | } |
||
117 | } |
||
118 | return $featArray; |
||
119 | } |
||
120 | |||
121 | protected function setArrayToSelectNotReadOnly($aElements, $sDefaultValue, $selectName, $featArray = null) |
||
122 | { |
||
123 | if (!is_array($featArray)) { |
||
124 | $featArray = []; |
||
125 | } |
||
126 | $featArray = $this->normalizeFeatureArray($featArray); |
||
127 | return '<select name="' . $selectName . '" ' |
||
128 | . 'id="' . $this->buildSelectId($selectName, $featArray) . '" ' |
||
129 | . 'size="' . $this->calculateSelectOptionsSize($aElements, $featArray) . '"' |
||
130 | . $this->eventOnChange($featArray) |
||
131 | . $this->featureArraySimpleTranslated($featArray, 'disabled') |
||
132 | . $this->featureArraySimpleTranslated($featArray, 'hidden') |
||
133 | . $this->featureArraySimpleTranslated($featArray, 'multiselect') |
||
134 | . $this->featureArraySimpleTranslated($featArray, 'style') |
||
135 | . '>' . $this->setOptionsForSelect($aElements, $sDefaultValue, $featArray) . '</select>'; |
||
136 | } |
||
137 | |||
138 | private function setOptionGroupEnd($crtGroup, $featArray) |
||
147 | |||
148 | private function setOptionGroupFooterHeader($featArray, $crtValue, $crtGroup) |
||
149 | { |
||
150 | $sReturn = []; |
||
151 | if (isset($featArray['grouping'])) { |
||
152 | $tempString = substr($crtValue, 0, strpos($crtValue, $featArray['grouping']) + 1); |
||
153 | if ($crtGroup != $tempString) { |
||
161 | |||
162 | private function setOptionSelected($optionValue, $sDefaultValue, $featArray) |
||
173 | |||
174 | /** |
||
175 | * Creates all the child tags required to populate a SELECT tag |
||
176 | * |
||
177 | * @param array $aElements |
||
178 | * @param string|array $sDefaultValue |
||
179 | * @param array $featArray |
||
180 | * @return string |
||
181 | */ |
||
182 | private function setOptionsForSelect($aElements, $sDefaultValue, $featArray = null) |
||
201 | } |
||
202 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.