Conditions | 90 |
Paths | > 20000 |
Total Lines | 377 |
Code Lines | 289 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
50 | protected function setArrayToTable($aElements, $ftrs = [], $bKpFlPge = true) |
||
51 | { |
||
52 | $rows = count($aElements); |
||
53 | if ($rows == 0) { |
||
54 | $divTab = [ |
||
55 | 'start' => '', |
||
56 | 'end' => '', |
||
57 | ]; |
||
58 | if (array_key_exists('showGroupingCounter', $ftrs)) { |
||
59 | if (array_key_exists('grouping_cell_type', $ftrs) && ($ftrs['grouping_cell_type'] == 'tab')) { |
||
60 | $ditTitle = 'No data found'; |
||
61 | if (isset($ftrs['showGroupingCounter'])) { |
||
62 | $ditTitle .= ' (0)'; |
||
63 | } |
||
64 | $divTab = [ |
||
65 | 'start' => '<div class="tabbertab tabbertabdefault" id="tab_NoData" title="' . $ditTitle . '">', |
||
66 | 'end' => '</div><!-- from tab_NoData -->', |
||
67 | ]; |
||
68 | if (!isset($ftrs['noGlobalTab'])) { |
||
69 | $divTab = [ |
||
70 | 'start' => '<div class="tabber" id="tab">' . $divTab['start'], |
||
71 | 'end' => $divTab['end'] . '</div><!-- from global Tab -->', |
||
72 | ]; |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 | return $divTab['start'] |
||
77 | . $this->setFeedbackModern('error', 'Error', $this->lclMsgCmn('i18n_NoData')) |
||
78 | . $divTab['end']; |
||
79 | } |
||
80 | if (isset($ftrs['limits'])) { |
||
81 | $ftrs['limits'][1] = min($ftrs['limits'][1], $ftrs['limits'][2]); |
||
82 | if ($ftrs['limits'][2] > $ftrs['limits'][1]) { |
||
83 | $iStartingPageRecord = 1; |
||
84 | } |
||
85 | } |
||
86 | $sReturn = ''; |
||
87 | if (isset($ftrs['hidden_columns'])) { |
||
88 | $hdClmns = $this->setArrayValuesAsKey($ftrs['hidden_columns']); |
||
89 | } else { |
||
90 | $hdClmns = ['']; |
||
91 | } |
||
92 | $checkboxFormId = ''; |
||
93 | if ((isset($ftrs['actions']['checkbox_inlineEdit'])) || (isset($ftrs['actions']['checkbox']))) { |
||
94 | $checkboxFormId = 'frm' . date('YmdHis'); |
||
95 | $sReturn .= '<form id="' . $checkboxFormId . '" name="' . $checkboxFormId |
||
96 | . '" method="post" ' . ' action="' . $this->tCmnRequest->server->get('PHP_SELF') . '" >'; |
||
97 | } |
||
98 | $tbl = []; |
||
99 | $tbl['Def'] = '<table' |
||
100 | . (isset($ftrs['table_style']) ? ' style="' . $ftrs['table_style'] . '"' : '') |
||
101 | . (isset($ftrs['table_class']) ? ' class="' . $ftrs['table_class'] . '"' : '') |
||
102 | . '>'; |
||
103 | if (!isset($ftrs['grouping_cell_type'])) { |
||
104 | $ftrs['grouping_cell_type'] = 'row'; |
||
105 | } |
||
106 | switch ($ftrs['grouping_cell_type']) { |
||
107 | case 'row': |
||
108 | $sReturn .= $tbl['Def']; |
||
109 | break; |
||
110 | case 'tab': |
||
111 | if (!isset($ftrs['noGlobalTab'])) { |
||
112 | $sReturn .= '<div class="tabber" id="tab">'; |
||
113 | } |
||
114 | break; |
||
115 | } |
||
116 | $groupCounter = 0; |
||
117 | $iTableColumns = 0; |
||
118 | $remebered_value = -1; |
||
119 | $remindGroupValue = null; |
||
120 | $color_no = null; |
||
121 | if (!isset($ftrs['headers_breaked'])) { |
||
122 | $ftrs['headers_breaked'] = true; |
||
123 | } |
||
124 | for ($rCntr = 0; $rCntr < $rows; $rCntr++) { |
||
125 | if ($rCntr == 0) { |
||
126 | $header = array_diff_key($aElements[$rCntr], $hdClmns); |
||
127 | $iTableColumns = count($header); |
||
128 | if (isset($ftrs['computed_columns'])) { |
||
129 | $iTableColumns += count($ftrs['computed_columns']); |
||
130 | } |
||
131 | if (isset($ftrs['actions'])) { |
||
132 | $iTableColumns += 1; |
||
133 | } |
||
134 | if (isset($ftrs['grouping_cell'])) { |
||
135 | $iTableColumns -= 1; |
||
136 | } |
||
137 | $tbl['Head'] = '<thead>'; |
||
138 | if ($ftrs['grouping_cell_type'] == 'row') { |
||
139 | $sReturn .= $tbl['Head']; |
||
140 | } |
||
141 | if (isset($iStartingPageRecord)) { |
||
142 | $pgn = '' |
||
143 | . $this->setPagination($ftrs['limits'][0], $ftrs['limits'][1], $ftrs['limits'][2], $bKpFlPge); |
||
144 | $sReturn .= $this->setStringIntoTag($this->setStringIntoTag($pgn, 'th', [ |
||
145 | 'colspan' => $iTableColumns |
||
146 | ]), 'tr'); |
||
147 | } |
||
148 | $tbl['Header'] = '<tr>'; |
||
149 | if (isset($ftrs['grouping_cell'])) { // Grouping columns |
||
150 | $header = array_diff_key($header, [$ftrs['grouping_cell'] => '']); |
||
151 | } |
||
152 | if (isset($ftrs['actions'])) { // Action column |
||
153 | $tbl['Header'] .= '<th> </th>'; |
||
154 | } |
||
155 | if (isset($ftrs['RowStyle'])) { //Exclude style columns from displaying |
||
156 | $tmpClmns = $this->setArrayValuesAsKey([$ftrs['RowStyle']]); |
||
157 | $header = array_diff_key($header, $tmpClmns); |
||
158 | $hdClmns = array_merge($hdClmns, $tmpClmns); |
||
159 | unset($tmpClmns); |
||
160 | } |
||
161 | $tbl['Header'] .= $this->setTableHeader($header, $ftrs['headers_breaked']); // Regular columns |
||
162 | if (isset($ftrs['computed_columns'])) { // Computed columns |
||
163 | $tbl['Header'] .= $this->setTableHeader($ftrs['computed_columns'], $ftrs['headers_breaked']); |
||
164 | } |
||
165 | $tbl['Header'] .= '</tr></thead><tbody>'; |
||
166 | if ($ftrs['grouping_cell_type'] == 'row') { |
||
167 | $sReturn .= $tbl['Header']; |
||
168 | } |
||
169 | } |
||
170 | $row_current = array_diff_key($aElements[$rCntr], $hdClmns); |
||
171 | if (isset($ftrs['row_colored_alternated'])) { |
||
172 | if ($ftrs['row_colored_alternated'][0] == '#') { |
||
173 | $color_column_value = $rCntr; |
||
174 | } else { |
||
175 | $color_column_value = $row_current[$ftrs['row_colored_alternated'][0]]; |
||
176 | } |
||
177 | if ($remebered_value != $color_column_value) { |
||
178 | if (isset($color_no)) { |
||
179 | $color_no = 1; |
||
180 | } else { |
||
181 | $color_no = 2; |
||
182 | } |
||
183 | $remebered_value = $color_column_value; |
||
184 | } |
||
185 | $color = ' style="background-color: ' . $ftrs['row_colored_alternated'][$color_no] . ';"'; |
||
186 | } else { |
||
187 | if (isset($ftrs['RowStyle'])) { |
||
188 | $color = ' style="' . $aElements[$rCntr][$ftrs['RowStyle']] . '"'; |
||
189 | } else { |
||
190 | $color = ''; |
||
191 | } |
||
192 | } |
||
193 | $tbl['tr_Color'] = '<tr' . $color . '>'; |
||
194 | // Grouping column |
||
195 | if (isset($ftrs['grouping_cell'])) { |
||
196 | foreach ($aElements[$rCntr] as $key => $value) { |
||
197 | if (($ftrs['grouping_cell'] == $key) && ($remindGroupValue != $value)) { |
||
198 | switch ($ftrs['grouping_cell_type']) { |
||
199 | case 'row': |
||
200 | $sReturn .= $tbl['tr_Color'] . '<td ' . 'colspan="' . $iTableColumns . '">' |
||
201 | . $this->setStringIntoTag($value, 'div', ['class' => 'rowGroup rounded']) |
||
202 | . '</td></tr>'; |
||
203 | break; |
||
204 | case 'tab': |
||
205 | if (is_null($remindGroupValue)) { |
||
206 | if (isset($ftrs['showGroupingCounter'])) { |
||
207 | $groupCounter = 0; |
||
208 | } |
||
209 | } else { |
||
210 | $sReturn .= '</tbody></table>'; |
||
211 | if (isset($ftrs['showGroupingCounter'])) { |
||
212 | $sReturn .= $this->updateDivTitleName($remindGroupValue, $groupCounter); |
||
213 | $groupCounter = 0; |
||
214 | } |
||
215 | $sReturn .= '</div>'; |
||
216 | } |
||
217 | $sReturn .= '<div class="tabbertab'; |
||
218 | if (isset($ftrs['grouping_default_tab'])) { |
||
219 | $sReturn .= ($ftrs['grouping_default_tab'] == $value ? ' tabbertabdefault' : ''); |
||
220 | } |
||
221 | $sReturn .= '" id="tab_' . $this->cleanStringForId($value) . '" ' |
||
222 | . 'title="' . $value . '">' |
||
223 | . $tbl['Def'] . $tbl['Head'] . $tbl['Header']; |
||
224 | break; |
||
225 | } |
||
226 | $remindGroupValue = $value; |
||
227 | } |
||
228 | } |
||
229 | } |
||
230 | if (isset($ftrs['grouping_cell'])) { |
||
231 | if ($ftrs['grouping_cell_type'] == 'tab') { |
||
232 | if (isset($ftrs['showGroupingCounter'])) { |
||
233 | $groupCounter++; |
||
234 | } |
||
235 | } |
||
236 | } |
||
237 | $sReturn .= $tbl['tr_Color']; |
||
238 | // Action column |
||
239 | $checkboxName = ''; |
||
240 | $checkboxNameS = ''; |
||
241 | if (isset($ftrs['actions'])) { |
||
242 | $sReturn .= '<td style="white-space:nowrap;">'; |
||
243 | $action_argument = 0; |
||
244 | if (isset($ftrs['actions']['key'])) { |
||
245 | $actionKey = $ftrs['actions']['key']; |
||
246 | } else { |
||
247 | $actionKey = 'view'; |
||
248 | } |
||
249 | if (isset($ftrs['action_prefix'])) { |
||
250 | $actPrfx = $ftrs['action_prefix'] . '&'; |
||
251 | $actionKey = 'view2'; |
||
252 | } else { |
||
253 | $actPrfx = ''; |
||
254 | } |
||
255 | foreach ($ftrs['actions'] as $key => $value) { |
||
256 | if ($action_argument != 0) { |
||
257 | $sReturn .= ' '; |
||
258 | } |
||
259 | switch ($key) { |
||
260 | case 'checkbox': |
||
261 | $checkboxName = $value . '[]'; |
||
262 | $checkboxNameS = $value; |
||
263 | $sReturn .= ' <input type="checkbox" name="' . $checkboxName |
||
264 | . '" id="n' . $aElements[$rCntr][$value] |
||
265 | . '" value="' . $aElements[$rCntr][$value] . '" '; |
||
266 | if (!is_null($this->tCmnSuperGlobals->get($checkboxNameS))) { |
||
267 | $inputToCheck = $this->tCmnSuperGlobals->get($checkboxNameS); |
||
268 | if (is_array($inputToCheck)) { |
||
269 | if (in_array($aElements[$rCntr][$value], $inputToCheck)) { |
||
270 | $sReturn .= 'checked="checked" '; |
||
271 | } |
||
272 | } else { |
||
273 | if ($aElements[$rCntr][$value] == $inputToCheck) { |
||
274 | $sReturn .= 'checked="checked" '; |
||
275 | } |
||
276 | } |
||
277 | } |
||
278 | if (strpos($this->tCmnSuperGlobals->get('view'), 'multiEdit') !== false) { |
||
279 | $sReturn .= 'disabled="disabled" '; |
||
280 | } |
||
281 | $sReturn .= '/>'; |
||
282 | break; |
||
283 | case 'checkbox_inlineEdit': |
||
284 | $checkboxName = $value . '[]'; |
||
285 | $checkboxNameS = $value; |
||
286 | $sReturn .= ' <input type="checkbox" name="' . $checkboxName |
||
287 | . '" id="n' . $aElements[$rCntr][$value] . '" value="' |
||
288 | . $aElements[$rCntr][$value] . '"/>'; |
||
289 | break; |
||
290 | case 'delete': |
||
291 | $sReturn .= '<a href="#" onclick="javascript:setQuest(\'' . $value[0] . '\',\''; |
||
292 | $iActArgs = count($value[1]); |
||
293 | for ($cntr2 = 0; $cntr2 < $iActArgs; $cntr2++) { |
||
294 | $sReturn .= $value[1][$cntr2] . '=' . $aElements[$rCntr][$value[1][$cntr2]]; |
||
295 | } |
||
296 | $sReturn .= '\');" id="' . $key . $rCntr . '"><i class="fa fa-times"> </i></a>'; |
||
297 | break; |
||
298 | case 'edit': |
||
299 | case 'list2': |
||
300 | case 'schedule': |
||
301 | $vIc = ($key == 'edit' ? 'pencil' : ($key == 'list2' ? 'list' : 'hourglass-half')); |
||
302 | $sReturn .= $this->setDynamicActionToSpecialCell($value, $aElements, [ |
||
303 | 'vIcon' => 'fa fa-' . $vIc, |
||
304 | 'aPrefix' => $actPrfx, |
||
305 | 'aKey' => $actionKey, |
||
306 | 'rCounter' => $rCntr, |
||
307 | 'Features' => $ftrs, |
||
308 | 'key' => $key, |
||
309 | ]); |
||
310 | break; |
||
311 | } |
||
312 | $action_argument += 1; |
||
313 | } |
||
314 | $sReturn .= '</td>'; |
||
315 | } |
||
316 | // Regular columns |
||
317 | $sReturn .= $this->setTableCell($row_current, $ftrs); |
||
318 | // Computed columns |
||
319 | if (isset($ftrs['computed_columns'])) { |
||
320 | $rowComputed = []; |
||
321 | $decimals = []; |
||
322 | foreach ($ftrs['computed_columns'] as $key => $value) { |
||
323 | if ($value[0] == '%') { |
||
324 | $dec = $value[2] + 2; |
||
325 | } else { |
||
326 | $dec = $value[2]; |
||
327 | } |
||
328 | switch ($value[1]) { |
||
329 | case '/': |
||
330 | // next variable is only to avoid a long line |
||
331 | $shorter = [ |
||
332 | $aElements[$rCntr][$value[3]], |
||
333 | $aElements[$rCntr][$value[4]], |
||
334 | ]; |
||
335 | $aElements[$rCntr][$key] = $this->setDividedResult($shorter[0], $shorter[1], $dec); |
||
336 | break; |
||
337 | case '+': |
||
338 | // next variable is only to avoid a long line |
||
339 | $iTemp = $this->setArrayValuesAsKey([ |
||
340 | $value[0], |
||
341 | $value[1], |
||
342 | $value[2] |
||
343 | ]); |
||
344 | $aTemp = array_diff($value, $iTemp); |
||
345 | $aElements[$rCntr][$key] = 0; |
||
346 | foreach ($aTemp as $sValue) { |
||
347 | $aElements[$rCntr][$key] += $aElements[$rCntr][$sValue]; |
||
348 | } |
||
349 | break; |
||
350 | default: |
||
351 | $rowComputed[$key] = ''; |
||
352 | break; |
||
353 | } |
||
354 | if ($value[0] == '%') { |
||
355 | $rowComputed[$key] = ($aElements[$rCntr][$key] * 100); |
||
356 | $dec -= 2; |
||
357 | } else { |
||
358 | $rowComputed[$key] = $aElements[$rCntr][$key]; |
||
359 | } |
||
360 | $decimals[$key] = $dec; |
||
361 | } |
||
362 | // displaying them |
||
363 | $sReturn .= $this->setTableCell($rowComputed, ['decimals' => $decimals]); |
||
364 | } |
||
365 | $sReturn .= '</tr>'; |
||
366 | } |
||
367 | if (isset($iStartingPageRecord)) { |
||
368 | $pgn = $this->setPagination($ftrs['limits'][0], $ftrs['limits'][1], $ftrs['limits'][2]); |
||
369 | $sReturn .= '<tr>' . $this->setStringIntoTag($pgn, 'th', ['colspan' => $iTableColumns]) . '</tr>'; |
||
370 | } |
||
371 | $sReturn .= '</tbody></table>'; |
||
372 | if ($ftrs['grouping_cell_type'] == 'tab') { |
||
373 | if (isset($ftrs['showGroupingCounter'])) { |
||
374 | $sReturn .= $this->updateDivTitleName($remindGroupValue, $groupCounter); |
||
375 | } |
||
376 | $sReturn .= '</div><!-- from ' . $remindGroupValue . ' -->'; |
||
377 | if (!isset($ftrs['noGlobalTab'])) { |
||
378 | $sReturn .= '</div><!-- from global tab -->'; |
||
379 | } |
||
380 | } |
||
381 | if (isset($ftrs['actions']['checkbox'])) { |
||
382 | if (strpos($this->tCmnSuperGlobals->get('view'), 'multiEdit') === false) { |
||
383 | $sReturn .= '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
||
384 | . '\',\'' . $checkboxName . '\',true);">Check All</a> ' |
||
|
|||
385 | . '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
||
386 | . '\',\'' . $checkboxName . '\',false);">Uncheck All</a> ' |
||
387 | . '<input type="hidden" name="action" value="multiEdit_' . $checkboxNameS . '" />'; |
||
388 | if (isset($ftrs['hiddenInput'])) { |
||
389 | if (is_array($ftrs['hiddenInput'])) { |
||
390 | foreach ($ftrs['hiddenInput'] as $valueF) { |
||
391 | $sReturn .= '<input type="hidden" name="' . $valueF |
||
392 | . '" value="' . $this->tCmnSuperGlobals->get($valueF) . '" />'; |
||
393 | } |
||
394 | } else { |
||
395 | $sReturn .= '<input type="hidden" name="' . $ftrs['hiddenInput'] |
||
396 | . '" value="' . $this->tCmnSuperGlobals->get($ftrs['hiddenInput']) . '" />'; |
||
397 | } |
||
398 | } |
||
399 | $sReturn .= '<input style="margin: 0 3em 0 3em;" type="submit" ' . 'value="Edit selected" />'; |
||
400 | } |
||
401 | $sReturn .= '</form>'; |
||
402 | } |
||
403 | if (isset($ftrs['actions']['checkbox_inlineEdit'])) { |
||
404 | $sReturn .= '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
||
405 | . '\',\'' . $checkboxName . '\',true);">Check All</a> ' |
||
406 | . '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
||
407 | . '\',\'' . $checkboxName . '\',false);">Uncheck All</a> '; |
||
408 | if (isset($ftrs['visibleInput'])) { |
||
409 | $sReturn .= $ftrs['visibleInput']; |
||
410 | } |
||
411 | $sReturn .= '<input type="hidden" name="view" value="save_' . $checkboxNameS . '" />'; |
||
412 | if (isset($ftrs['hiddenInput'])) { |
||
413 | if (is_array($ftrs['hiddenInput'])) { |
||
414 | foreach ($ftrs['hiddenInput'] as $valueF) { |
||
415 | $sReturn .= '<input type="hidden" name="' . $valueF . '" value="' |
||
416 | . $this->tCmnSuperGlobals->get($valueF) . '" />'; |
||
417 | } |
||
418 | } else { |
||
419 | $sReturn .= '<input type="hidden" name="' . $ftrs['hiddenInput'] |
||
420 | . '" value="' . $this->tCmnSuperGlobals->get($ftrs['hiddenInput']) . '" />'; |
||
421 | } |
||
422 | } |
||
423 | $sReturn .= '<input style="margin: 0 3em 0 3em;" type="submit" value="Store the modification" />'; |
||
424 | $sReturn .= '</form>'; |
||
425 | } |
||
426 | return $sReturn; |
||
427 | } |
||
540 |