Conditions | 93 |
Paths | > 20000 |
Total Lines | 399 |
Code Lines | 306 |
Lines | 54 |
Ratio | 13.53 % |
Changes | 6 | ||
Bugs | 0 | Features | 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 |
||
202 | protected function setArrayToTable($aElements, $ftrs = null, $bKpFlPge = true) |
||
203 | { |
||
204 | $rows = count($aElements); |
||
205 | if ($rows == 0) { |
||
206 | $divTab = [ |
||
207 | 'start' => '', |
||
208 | 'end' => '', |
||
209 | ]; |
||
210 | if (array_key_exists('showGroupingCounter', $ftrs)) { |
||
211 | if (array_key_exists('grouping_cell_type', $ftrs) && ($ftrs['grouping_cell_type'] == 'tab')) { |
||
212 | $ditTitle = 'No data found'; |
||
213 | if (isset($ftrs['showGroupingCounter'])) { |
||
214 | $ditTitle .= ' (0)'; |
||
215 | } |
||
216 | $divTab = [ |
||
217 | 'start' => '<div class="tabbertab tabbertabdefault" id="tab_NoData" title="' . $ditTitle . '">', |
||
218 | 'end' => '</div><!-- from tab_NoData -->', |
||
219 | ]; |
||
220 | if (!isset($ftrs['noGlobalTab'])) { |
||
221 | $divTab = [ |
||
222 | 'start' => '<div class="tabber" id="tab">' . $divTab['start'], |
||
223 | 'end' => $divTab['end'] . '</div><!-- from global Tab -->', |
||
224 | ]; |
||
225 | } |
||
226 | } |
||
227 | } |
||
228 | return $divTab['start'] |
||
229 | . $this->setFeedbackModern('error', 'Error', $this->lclMsgCmn('i18n_NoData')) |
||
230 | . $divTab['end']; |
||
231 | } |
||
232 | if (isset($ftrs['limits'])) { |
||
233 | $ftrs['limits'][1] = min($ftrs['limits'][1], $ftrs['limits'][2]); |
||
234 | if ($ftrs['limits'][2] > $ftrs['limits'][1]) { |
||
235 | $iStartingPageRecord = 1; |
||
236 | } |
||
237 | } |
||
238 | $sReturn = ''; |
||
239 | if (isset($ftrs['hidden_columns'])) { |
||
240 | $hdClmns = $this->setArrayValuesAsKey($ftrs['hidden_columns']); |
||
241 | } else { |
||
242 | $hdClmns = ['']; |
||
243 | } |
||
244 | if ((isset($ftrs['actions']['checkbox_inlineEdit'])) || (isset($ftrs['actions']['checkbox']))) { |
||
245 | $checkboxFormId = 'frm' . date('YmdHis'); |
||
246 | $sReturn .= '<form id="' . $checkboxFormId . '" ' . 'name="' . $checkboxFormId |
||
247 | . '" method="post" ' . ' action="' . $_SERVER['PHP_SELF'] . '" >'; |
||
248 | } |
||
249 | $tbl['Def'] = '<table' |
||
250 | . (isset($ftrs['table_style']) ? ' style="' . $ftrs['table_style'] . '"' : '') |
||
251 | . (isset($ftrs['table_class']) ? ' class="' . $ftrs['table_class'] . '"' : '') |
||
252 | . '>'; |
||
253 | if (!isset($ftrs['grouping_cell_type'])) { |
||
254 | $ftrs['grouping_cell_type'] = 'row'; |
||
255 | } |
||
256 | switch ($ftrs['grouping_cell_type']) { |
||
257 | case 'row': |
||
258 | $sReturn .= $tbl['Def']; |
||
259 | break; |
||
260 | case 'tab': |
||
261 | if (!isset($ftrs['noGlobalTab'])) { |
||
262 | $sReturn .= '<div class="tabber" id="tab">'; |
||
263 | } |
||
264 | break; |
||
265 | } |
||
266 | $iTableColumns = 0; |
||
267 | $remebered_value = -1; |
||
268 | $remindGroupValue = null; |
||
269 | $color_no = null; |
||
270 | if (!isset($ftrs['headers_breaked'])) { |
||
271 | $ftrs['headers_breaked'] = true; |
||
272 | } |
||
273 | for ($rCntr = 0; $rCntr < $rows; $rCntr++) { |
||
274 | if ($rCntr == 0) { |
||
275 | $header = array_diff_key($aElements[$rCntr], $hdClmns); |
||
276 | $iTableColumns = count($header); |
||
277 | if (isset($ftrs['computed_columns'])) { |
||
278 | $iTableColumns += count($ftrs['computed_columns']); |
||
279 | } |
||
280 | if (isset($ftrs['actions'])) { |
||
281 | $iTableColumns += 1; |
||
282 | } |
||
283 | if (isset($ftrs['grouping_cell'])) { |
||
284 | $iTableColumns -= 1; |
||
285 | } |
||
286 | $tbl['Head'] = '<thead>'; |
||
287 | if ($ftrs['grouping_cell_type'] == 'row') { |
||
288 | $sReturn .= $tbl['Head']; |
||
289 | } |
||
290 | View Code Duplication | if (isset($iStartingPageRecord)) { |
|
291 | $pgn = $this->setPagination($ftrs['limits'][0], $ftrs['limits'][1], $ftrs['limits'][2], $bKpFlPge); |
||
292 | $sReturn .= $this->setStringIntoTag($this->setStringIntoTag($pgn, 'th', [ |
||
293 | 'colspan' => $iTableColumns |
||
294 | ]), 'tr'); |
||
295 | } |
||
296 | $tbl['Header'] = '<tr>'; |
||
297 | if (isset($ftrs['grouping_cell'])) { // Grouping columns |
||
298 | $header = array_diff_key($header, [$ftrs['grouping_cell'] => '']); |
||
299 | } |
||
300 | if (isset($ftrs['actions'])) { // Action column |
||
301 | $tbl['Header'] .= '<th> </th>'; |
||
302 | } |
||
303 | if (isset($ftrs['RowStyle'])) { //Exclude style columns from displaying |
||
304 | $tmpClmns = $this->setArrayValuesAsKey([$ftrs['RowStyle']]); |
||
305 | $header = array_diff_key($header, $tmpClmns); |
||
306 | $hdClmns = array_merge($hdClmns, $tmpClmns); |
||
307 | unset($tmpClmns); |
||
308 | } |
||
309 | $tbl['Header'] .= $this->setTableHeader($header, $ftrs['headers_breaked']); // Regular columns |
||
310 | if (isset($ftrs['computed_columns'])) { // Computed columns |
||
311 | $tbl['Header'] .= $this->setTableHeader($ftrs['computed_columns'], $ftrs['headers_breaked']); |
||
312 | } |
||
313 | $tbl['Header'] .= '</tr></thead><tbody>'; |
||
314 | if ($ftrs['grouping_cell_type'] == 'row') { |
||
315 | $sReturn .= $tbl['Header']; |
||
316 | } |
||
317 | } |
||
318 | $row_current = array_diff_key($aElements[$rCntr], $hdClmns); |
||
319 | if (isset($ftrs['row_colored_alternated'])) { |
||
320 | if ($ftrs['row_colored_alternated'][0] == '#') { |
||
321 | $color_column_value = $rCntr; |
||
322 | } else { |
||
323 | $color_column_value = $row_current[$ftrs['row_colored_alternated'][0]]; |
||
324 | } |
||
325 | if ($remebered_value != $color_column_value) { |
||
326 | if (isset($color_no)) { |
||
327 | $color_no = 1; |
||
328 | } else { |
||
329 | $color_no = 2; |
||
330 | } |
||
331 | $remebered_value = $color_column_value; |
||
332 | } |
||
333 | $color = ' style="background-color: ' . $ftrs['row_colored_alternated'][$color_no] . ';"'; |
||
334 | } else { |
||
335 | if (isset($ftrs['RowStyle'])) { |
||
336 | $color = ' style="' . $aElements[$rCntr][$ftrs['RowStyle']] . '"'; |
||
337 | } else { |
||
338 | $color = ''; |
||
339 | } |
||
340 | } |
||
341 | $tbl['tr_Color'] = '<tr' . $color . '>'; |
||
342 | // Grouping column |
||
343 | if (isset($ftrs['grouping_cell'])) { |
||
344 | foreach ($aElements[$rCntr] as $key => $value) { |
||
345 | if (($ftrs['grouping_cell'] == $key) && ($remindGroupValue != $value)) { |
||
346 | switch ($ftrs['grouping_cell_type']) { |
||
347 | case 'row': |
||
348 | $sReturn .= $tbl['tr_Color'] . '<td ' . 'colspan="' . $iTableColumns . '">' |
||
349 | . $this->setStringIntoTag($value, 'div', ['class' => 'rowGroup rounded']) |
||
350 | . '</td></tr>'; |
||
351 | break; |
||
352 | case 'tab': |
||
353 | if (is_null($remindGroupValue)) { |
||
354 | if (isset($ftrs['showGroupingCounter'])) { |
||
355 | $groupCounter = 0; |
||
356 | } |
||
357 | } else { |
||
358 | $sReturn .= '</tbody></table>'; |
||
359 | if (isset($ftrs['showGroupingCounter'])) { |
||
360 | $sReturn .= $this->updateDivTitleName($remindGroupValue, $groupCounter); |
||
361 | $groupCounter = 0; |
||
362 | } |
||
363 | $sReturn .= '</div>'; |
||
364 | } |
||
365 | $sReturn .= '<div class="tabbertab'; |
||
366 | if (isset($ftrs['grouping_default_tab'])) { |
||
367 | $sReturn .= ($ftrs['grouping_default_tab'] == $value ? ' tabbertabdefault' : ''); |
||
368 | } |
||
369 | $sReturn .= '" id="tab_' . $this->cleanStringForId($value) . '" ' |
||
370 | . 'title="' . $value . '">' |
||
371 | . $tbl['Def'] . $tbl['Head'] . $tbl['Header']; |
||
372 | break; |
||
373 | } |
||
374 | $remindGroupValue = $value; |
||
375 | } |
||
376 | } |
||
377 | } |
||
378 | if (isset($ftrs['grouping_cell'])) { |
||
379 | if ($ftrs['grouping_cell_type'] == 'tab') { |
||
380 | if (isset($ftrs['showGroupingCounter'])) { |
||
381 | $groupCounter++; |
||
382 | } |
||
383 | } |
||
384 | } |
||
385 | $sReturn .= $tbl['tr_Color']; |
||
386 | // Action column |
||
387 | if (isset($ftrs['actions'])) { |
||
388 | $sReturn .= '<td style="white-space:nowrap;">'; |
||
389 | $action_argument = 0; |
||
390 | if (isset($ftrs['actions']['key'])) { |
||
391 | $action_key = $ftrs['actions']['key']; |
||
392 | } else { |
||
393 | $action_key = 'view'; |
||
394 | } |
||
395 | if (isset($ftrs['action_prefix'])) { |
||
396 | $actPrfx = $ftrs['action_prefix'] . '&'; |
||
397 | $action_key = 'view2'; |
||
398 | } else { |
||
399 | $actPrfx = ''; |
||
400 | } |
||
401 | foreach ($ftrs['actions'] as $key => $value) { |
||
402 | if ($action_argument != 0) { |
||
403 | $sReturn .= ' '; |
||
404 | } |
||
405 | switch ($key) { |
||
406 | case 'checkbox': |
||
407 | $checkboxName = $value . '[]'; |
||
408 | $checkboxNameS = $value; |
||
409 | $sReturn .= ' <input type="checkbox" name="' . $checkboxName |
||
410 | . '" id="n' . $aElements[$rCntr][$value] |
||
411 | . '" value="' . $aElements[$rCntr][$value] . '" '; |
||
412 | if (isset($_REQUEST[$checkboxNameS])) { |
||
413 | if (is_array($_REQUEST[$checkboxNameS])) { |
||
414 | if (in_array($aElements[$rCntr][$value], $_REQUEST[$checkboxNameS])) { |
||
415 | $sReturn .= 'checked="checked" '; |
||
416 | } |
||
417 | } else { |
||
418 | if ($aElements[$rCntr][$value] == $_REQUEST[$checkboxNameS]) { |
||
419 | $sReturn .= 'checked="checked" '; |
||
420 | } |
||
421 | } |
||
422 | } |
||
423 | if (strpos($_REQUEST['view'], 'multiEdit') !== false) { |
||
424 | $sReturn .= 'disabled="disabled" '; |
||
425 | } |
||
426 | $sReturn .= '/>'; |
||
427 | break; |
||
428 | case 'checkbox_inlineEdit': |
||
429 | $checkboxName = $value . '[]'; |
||
430 | $checkboxNameS = $value; |
||
431 | $sReturn .= ' <input type="checkbox" name="' . $checkboxName |
||
432 | . '" id="n' . $aElements[$rCntr][$value] . '" value="' |
||
433 | . $aElements[$rCntr][$value] . '"/>'; |
||
434 | break; |
||
435 | case 'edit': |
||
436 | $edt = ''; |
||
437 | if (isset($ftrs['NoAjaxEditing'])) { |
||
438 | $edt .= $_SERVER['PHP_SELF'] . '?' . $actPrfx |
||
439 | . $action_key . '=' . $value[0] . '&'; |
||
440 | $iActArgs = count($value[1]); |
||
441 | for ($cntr2 = 0; $cntr2 < $iActArgs; $cntr2++) { |
||
442 | $edt .= $value[1][$cntr2] . '=' . $aElements[$rCntr][$value[1][$cntr2]]; |
||
443 | } |
||
444 | $sReturn .= '<a href="' . $edt . '"><i class="fa fa-pencil"> </i></a>'; |
||
445 | View Code Duplication | } else { |
|
446 | $edt .= 'javascript:loadAE(\'' . $_SERVER['PHP_SELF'] . '?' |
||
447 | . $actPrfx . $action_key . '=' . $value[0] . '&'; |
||
448 | $iActArgs = count($value[1]); |
||
449 | for ($cntr2 = 0; $cntr2 < $iActArgs; $cntr2++) { |
||
450 | $edt .= $value[1][$cntr2] . '=' . $aElements[$rCntr][$value[1][$cntr2]]; |
||
451 | } |
||
452 | $edt .= '\');'; |
||
453 | $sReturn .= '<a href="#" onclick="' . $edt . '">' |
||
454 | . '<i class="fa fa-pencil"> </i></a>'; |
||
455 | } |
||
456 | break; |
||
457 | case 'list2': |
||
458 | $edt = ''; |
||
459 | if (isset($ftrs['NoAjaxEditing'])) { |
||
460 | $sReturn .= '<a href="?' . $actPrfx . $action_key . '=' . $value[0] . '&'; |
||
461 | $iActArgs = count($value[1]); |
||
462 | for ($cntr2 = 0; $cntr2 < $iActArgs; $cntr2++) { |
||
463 | $sReturn .= $value[1][$cntr2] . '=' . $aElements[$rCntr][$value[1][$cntr2]]; |
||
464 | } |
||
465 | $sReturn .= '"><i class="fa fa-list"> </i></a>'; |
||
466 | View Code Duplication | } else { |
|
467 | $edt .= 'javascript:loadAE(\'' . $_SERVER['PHP_SELF'] . '?' |
||
468 | . $actPrfx . $action_key . '=' . $value[0] . '&'; |
||
469 | $iActArgs = count($value[1]); |
||
470 | for ($cntr2 = 0; $cntr2 < $iActArgs; $cntr2++) { |
||
471 | $edt .= $value[1][$cntr2] . '=' . $aElements[$rCntr][$value[1][$cntr2]]; |
||
472 | } |
||
473 | $edt .= '\');'; |
||
474 | $sReturn .= '<a href="#" onclick="' . $edt . '">' |
||
475 | . '<i class="fa fa-list"> </i></a>'; |
||
476 | } |
||
477 | break; |
||
478 | case 'delete': |
||
479 | $sReturn .= '<a href="javascript:setQuest(\'' . $value[0] . '\',\''; |
||
480 | $iActArgs = count($value[1]); |
||
481 | for ($cntr2 = 0; $cntr2 < $iActArgs; $cntr2++) { |
||
482 | $sReturn .= $value[1][$cntr2] . '=' . $aElements[$rCntr][$value[1][$cntr2]]; |
||
483 | } |
||
484 | $sReturn .= '\');"><i class="fa fa-times"> </i></a>'; |
||
485 | break; |
||
486 | } |
||
487 | $action_argument += 1; |
||
488 | } |
||
489 | $sReturn .= '</td>'; |
||
490 | } |
||
491 | // Regular columns |
||
492 | $sReturn .= $this->setTableCell($row_current, $ftrs); |
||
493 | // Computed columns |
||
494 | if (isset($ftrs['computed_columns'])) { |
||
495 | foreach ($ftrs['computed_columns'] as $key => $value) { |
||
496 | if ($value[0] == '%') { |
||
497 | $dec = $value[2] + 2; |
||
498 | } else { |
||
499 | $dec = $value[2]; |
||
500 | } |
||
501 | switch ($value[1]) { |
||
502 | case '/': |
||
503 | // next variable is only to avoid a long line |
||
504 | $shorter = [ |
||
505 | $aElements[$rCntr][$value[3]], |
||
506 | $aElements[$rCntr][$value[4]], |
||
507 | ]; |
||
508 | $aElements[$rCntr][$key] = $this->setDividedResult($shorter[0], $shorter[1], $dec); |
||
509 | break; |
||
510 | case '+': |
||
511 | // next variable is only to avoid a long line |
||
512 | $iTemp = $this->setArrayValuesAsKey([ |
||
513 | $value[0], |
||
514 | $value[1], |
||
515 | $value[2] |
||
516 | ]); |
||
517 | $aTemp = array_diff($value, $iTemp); |
||
518 | $aElements[$rCntr][$key] = 0; |
||
519 | foreach ($aTemp as $sValue) { |
||
520 | $aElements[$rCntr][$key] += $aElements[$rCntr][$sValue]; |
||
521 | } |
||
522 | break; |
||
523 | default: |
||
524 | $row_computed[$key] = ''; |
||
525 | break; |
||
526 | } |
||
527 | if ($value[0] == '%') { |
||
528 | $row_computed[$key] = ($aElements[$rCntr][$key] * 100); |
||
529 | $dec -= 2; |
||
530 | } else { |
||
531 | $row_computed[$key] = $aElements[$rCntr][$key]; |
||
532 | } |
||
533 | $decimals[$key] = $dec; |
||
534 | } |
||
535 | // displaying them |
||
536 | $sReturn .= $this->setTableCell($row_computed, ['decimals' => $decimals]); |
||
537 | } |
||
538 | $sReturn .= '</tr>'; |
||
539 | } |
||
540 | View Code Duplication | if (isset($iStartingPageRecord)) { |
|
541 | $pgn = $this->setPagination($ftrs['limits'][0], $ftrs['limits'][1], $ftrs['limits'][2]); |
||
542 | $sReturn .= '<tr>' . $this->setStringIntoTag($pgn, 'th', ['colspan' => $iTableColumns]) . '</tr>'; |
||
543 | } |
||
544 | $sReturn .= '</tbody></table>'; |
||
545 | if ($ftrs['grouping_cell_type'] == 'tab') { |
||
546 | if (isset($ftrs['showGroupingCounter'])) { |
||
547 | $sReturn .= $this->updateDivTitleName($remindGroupValue, $groupCounter); |
||
548 | } |
||
549 | $sReturn .= '</div><!-- from ' . $remindGroupValue . ' -->'; |
||
550 | if (!isset($ftrs['noGlobalTab'])) { |
||
551 | $sReturn .= '</div><!-- from global tab -->'; |
||
552 | } |
||
553 | } |
||
554 | if (isset($ftrs['actions']['checkbox'])) { |
||
555 | if (strpos($_REQUEST['view'], 'multiEdit') === false) { |
||
556 | $sReturn .= '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
||
557 | . '\',\'' . $checkboxName . '\',true);">Check All</a> ' |
||
558 | . '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
||
559 | . '\',\'' . $checkboxName . '\',false);">Uncheck All</a> ' |
||
560 | . '<input type="hidden" name="action" value="multiEdit_' . $checkboxNameS . '" />'; |
||
561 | View Code Duplication | if (isset($ftrs['hiddenInput'])) { |
|
562 | if (is_array($ftrs['hiddenInput'])) { |
||
563 | foreach ($ftrs['hiddenInput'] as $valueF) { |
||
564 | $sReturn .= '<input type="hidden" name="' . $valueF |
||
565 | . '" value="' . $_REQUEST[$valueF] . '" />'; |
||
566 | } |
||
567 | } else { |
||
568 | $sReturn .= '<input type="hidden" name="' . $ftrs['hiddenInput'] |
||
569 | . '" value="' . $_REQUEST[$ftrs['hiddenInput']] . '" />'; |
||
570 | } |
||
571 | } |
||
572 | $sReturn .= '<input style="margin: 0 3em 0 3em;" type="submit" ' . 'value="Edit selected" />'; |
||
573 | } |
||
574 | $sReturn .= '</form>'; |
||
575 | } |
||
576 | if (isset($ftrs['actions']['checkbox_inlineEdit'])) { |
||
577 | $sReturn .= '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
||
578 | . '\',\'' . $checkboxName . '\',true);">Check All</a> ' |
||
579 | . '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
||
580 | . '\',\'' . $checkboxName . '\',false);">Uncheck All</a> '; |
||
581 | if (isset($ftrs['visibleInput'])) { |
||
582 | $sReturn .= $ftrs['visibleInput']; |
||
583 | } |
||
584 | $sReturn .= '<input type="hidden" name="view" value="save_' . $checkboxNameS . '" />'; |
||
585 | View Code Duplication | if (isset($ftrs['hiddenInput'])) { |
|
586 | if (is_array($ftrs['hiddenInput'])) { |
||
587 | foreach ($ftrs['hiddenInput'] as $valueF) { |
||
588 | $sReturn .= '<input type="hidden" name="' . $valueF |
||
589 | . '" value="' . $_REQUEST[$valueF] . '" />'; |
||
590 | } |
||
591 | } else { |
||
592 | $sReturn .= '<input type="hidden" name="' . $ftrs['hiddenInput'] |
||
593 | . '" value="' . $_REQUEST[$ftrs['hiddenInput']] . '" />'; |
||
594 | } |
||
595 | } |
||
596 | $sReturn .= '<input style="margin: 0 3em 0 3em;" type="submit" value="Store the modification" />'; |
||
597 | $sReturn .= '</form>'; |
||
598 | } |
||
599 | return $sReturn; |
||
600 | } |
||
601 | |||
1221 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.