Conditions | 93 |
Paths | > 20000 |
Total Lines | 399 |
Code Lines | 306 |
Lines | 54 |
Ratio | 13.53 % |
Changes | 8 | ||
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 |
||
106 | protected function setArrayToTable($aElements, $ftrs = null, $bKpFlPge = true) |
||
107 | { |
||
108 | $rows = count($aElements); |
||
109 | if ($rows == 0) { |
||
110 | $divTab = [ |
||
111 | 'start' => '', |
||
112 | 'end' => '', |
||
113 | ]; |
||
114 | if (array_key_exists('showGroupingCounter', $ftrs)) { |
||
115 | if (array_key_exists('grouping_cell_type', $ftrs) && ($ftrs['grouping_cell_type'] == 'tab')) { |
||
116 | $ditTitle = 'No data found'; |
||
117 | if (isset($ftrs['showGroupingCounter'])) { |
||
118 | $ditTitle .= ' (0)'; |
||
119 | } |
||
120 | $divTab = [ |
||
121 | 'start' => '<div class="tabbertab tabbertabdefault" id="tab_NoData" title="' . $ditTitle . '">', |
||
122 | 'end' => '</div><!-- from tab_NoData -->', |
||
123 | ]; |
||
124 | if (!isset($ftrs['noGlobalTab'])) { |
||
125 | $divTab = [ |
||
126 | 'start' => '<div class="tabber" id="tab">' . $divTab['start'], |
||
127 | 'end' => $divTab['end'] . '</div><!-- from global Tab -->', |
||
128 | ]; |
||
129 | } |
||
130 | } |
||
131 | } |
||
132 | return $divTab['start'] |
||
133 | . $this->setFeedbackModern('error', 'Error', $this->lclMsgCmn('i18n_NoData')) |
||
134 | . $divTab['end']; |
||
135 | } |
||
136 | if (isset($ftrs['limits'])) { |
||
137 | $ftrs['limits'][1] = min($ftrs['limits'][1], $ftrs['limits'][2]); |
||
138 | if ($ftrs['limits'][2] > $ftrs['limits'][1]) { |
||
139 | $iStartingPageRecord = 1; |
||
140 | } |
||
141 | } |
||
142 | $sReturn = ''; |
||
143 | if (isset($ftrs['hidden_columns'])) { |
||
144 | $hdClmns = $this->setArrayValuesAsKey($ftrs['hidden_columns']); |
||
145 | } else { |
||
146 | $hdClmns = ['']; |
||
147 | } |
||
148 | if ((isset($ftrs['actions']['checkbox_inlineEdit'])) || (isset($ftrs['actions']['checkbox']))) { |
||
149 | $checkboxFormId = 'frm' . date('YmdHis'); |
||
150 | $sReturn .= '<form id="' . $checkboxFormId . '" ' . 'name="' . $checkboxFormId |
||
151 | . '" method="post" ' . ' action="' . $_SERVER['PHP_SELF'] . '" >'; |
||
152 | } |
||
153 | $tbl['Def'] = '<table' |
||
154 | . (isset($ftrs['table_style']) ? ' style="' . $ftrs['table_style'] . '"' : '') |
||
155 | . (isset($ftrs['table_class']) ? ' class="' . $ftrs['table_class'] . '"' : '') |
||
156 | . '>'; |
||
157 | if (!isset($ftrs['grouping_cell_type'])) { |
||
158 | $ftrs['grouping_cell_type'] = 'row'; |
||
159 | } |
||
160 | switch ($ftrs['grouping_cell_type']) { |
||
161 | case 'row': |
||
162 | $sReturn .= $tbl['Def']; |
||
163 | break; |
||
164 | case 'tab': |
||
165 | if (!isset($ftrs['noGlobalTab'])) { |
||
166 | $sReturn .= '<div class="tabber" id="tab">'; |
||
167 | } |
||
168 | break; |
||
169 | } |
||
170 | $iTableColumns = 0; |
||
171 | $remebered_value = -1; |
||
172 | $remindGroupValue = null; |
||
173 | $color_no = null; |
||
174 | if (!isset($ftrs['headers_breaked'])) { |
||
175 | $ftrs['headers_breaked'] = true; |
||
176 | } |
||
177 | for ($rCntr = 0; $rCntr < $rows; $rCntr++) { |
||
178 | if ($rCntr == 0) { |
||
179 | $header = array_diff_key($aElements[$rCntr], $hdClmns); |
||
180 | $iTableColumns = count($header); |
||
181 | if (isset($ftrs['computed_columns'])) { |
||
182 | $iTableColumns += count($ftrs['computed_columns']); |
||
183 | } |
||
184 | if (isset($ftrs['actions'])) { |
||
185 | $iTableColumns += 1; |
||
186 | } |
||
187 | if (isset($ftrs['grouping_cell'])) { |
||
188 | $iTableColumns -= 1; |
||
189 | } |
||
190 | $tbl['Head'] = '<thead>'; |
||
191 | if ($ftrs['grouping_cell_type'] == 'row') { |
||
192 | $sReturn .= $tbl['Head']; |
||
193 | } |
||
194 | View Code Duplication | if (isset($iStartingPageRecord)) { |
|
195 | $pgn = $this->setPagination($ftrs['limits'][0], $ftrs['limits'][1], $ftrs['limits'][2], $bKpFlPge); |
||
196 | $sReturn .= $this->setStringIntoTag($this->setStringIntoTag($pgn, 'th', [ |
||
197 | 'colspan' => $iTableColumns |
||
198 | ]), 'tr'); |
||
199 | } |
||
200 | $tbl['Header'] = '<tr>'; |
||
201 | if (isset($ftrs['grouping_cell'])) { // Grouping columns |
||
202 | $header = array_diff_key($header, [$ftrs['grouping_cell'] => '']); |
||
203 | } |
||
204 | if (isset($ftrs['actions'])) { // Action column |
||
205 | $tbl['Header'] .= '<th> </th>'; |
||
206 | } |
||
207 | if (isset($ftrs['RowStyle'])) { //Exclude style columns from displaying |
||
208 | $tmpClmns = $this->setArrayValuesAsKey([$ftrs['RowStyle']]); |
||
209 | $header = array_diff_key($header, $tmpClmns); |
||
210 | $hdClmns = array_merge($hdClmns, $tmpClmns); |
||
211 | unset($tmpClmns); |
||
212 | } |
||
213 | $tbl['Header'] .= $this->setTableHeader($header, $ftrs['headers_breaked']); // Regular columns |
||
214 | if (isset($ftrs['computed_columns'])) { // Computed columns |
||
215 | $tbl['Header'] .= $this->setTableHeader($ftrs['computed_columns'], $ftrs['headers_breaked']); |
||
216 | } |
||
217 | $tbl['Header'] .= '</tr></thead><tbody>'; |
||
218 | if ($ftrs['grouping_cell_type'] == 'row') { |
||
219 | $sReturn .= $tbl['Header']; |
||
220 | } |
||
221 | } |
||
222 | $row_current = array_diff_key($aElements[$rCntr], $hdClmns); |
||
223 | if (isset($ftrs['row_colored_alternated'])) { |
||
224 | if ($ftrs['row_colored_alternated'][0] == '#') { |
||
225 | $color_column_value = $rCntr; |
||
226 | } else { |
||
227 | $color_column_value = $row_current[$ftrs['row_colored_alternated'][0]]; |
||
228 | } |
||
229 | if ($remebered_value != $color_column_value) { |
||
230 | if (isset($color_no)) { |
||
231 | $color_no = 1; |
||
232 | } else { |
||
233 | $color_no = 2; |
||
234 | } |
||
235 | $remebered_value = $color_column_value; |
||
236 | } |
||
237 | $color = ' style="background-color: ' . $ftrs['row_colored_alternated'][$color_no] . ';"'; |
||
238 | } else { |
||
239 | if (isset($ftrs['RowStyle'])) { |
||
240 | $color = ' style="' . $aElements[$rCntr][$ftrs['RowStyle']] . '"'; |
||
241 | } else { |
||
242 | $color = ''; |
||
243 | } |
||
244 | } |
||
245 | $tbl['tr_Color'] = '<tr' . $color . '>'; |
||
246 | // Grouping column |
||
247 | if (isset($ftrs['grouping_cell'])) { |
||
248 | foreach ($aElements[$rCntr] as $key => $value) { |
||
249 | if (($ftrs['grouping_cell'] == $key) && ($remindGroupValue != $value)) { |
||
250 | switch ($ftrs['grouping_cell_type']) { |
||
251 | case 'row': |
||
252 | $sReturn .= $tbl['tr_Color'] . '<td ' . 'colspan="' . $iTableColumns . '">' |
||
253 | . $this->setStringIntoTag($value, 'div', ['class' => 'rowGroup rounded']) |
||
254 | . '</td></tr>'; |
||
255 | break; |
||
256 | case 'tab': |
||
257 | if (is_null($remindGroupValue)) { |
||
258 | if (isset($ftrs['showGroupingCounter'])) { |
||
259 | $groupCounter = 0; |
||
260 | } |
||
261 | } else { |
||
262 | $sReturn .= '</tbody></table>'; |
||
263 | if (isset($ftrs['showGroupingCounter'])) { |
||
264 | $sReturn .= $this->updateDivTitleName($remindGroupValue, $groupCounter); |
||
265 | $groupCounter = 0; |
||
266 | } |
||
267 | $sReturn .= '</div>'; |
||
268 | } |
||
269 | $sReturn .= '<div class="tabbertab'; |
||
270 | if (isset($ftrs['grouping_default_tab'])) { |
||
271 | $sReturn .= ($ftrs['grouping_default_tab'] == $value ? ' tabbertabdefault' : ''); |
||
272 | } |
||
273 | $sReturn .= '" id="tab_' . $this->cleanStringForId($value) . '" ' |
||
274 | . 'title="' . $value . '">' |
||
275 | . $tbl['Def'] . $tbl['Head'] . $tbl['Header']; |
||
276 | break; |
||
277 | } |
||
278 | $remindGroupValue = $value; |
||
279 | } |
||
280 | } |
||
281 | } |
||
282 | if (isset($ftrs['grouping_cell'])) { |
||
283 | if ($ftrs['grouping_cell_type'] == 'tab') { |
||
284 | if (isset($ftrs['showGroupingCounter'])) { |
||
285 | $groupCounter++; |
||
286 | } |
||
287 | } |
||
288 | } |
||
289 | $sReturn .= $tbl['tr_Color']; |
||
290 | // Action column |
||
291 | if (isset($ftrs['actions'])) { |
||
292 | $sReturn .= '<td style="white-space:nowrap;">'; |
||
293 | $action_argument = 0; |
||
294 | if (isset($ftrs['actions']['key'])) { |
||
295 | $action_key = $ftrs['actions']['key']; |
||
296 | } else { |
||
297 | $action_key = 'view'; |
||
298 | } |
||
299 | if (isset($ftrs['action_prefix'])) { |
||
300 | $actPrfx = $ftrs['action_prefix'] . '&'; |
||
301 | $action_key = 'view2'; |
||
302 | } else { |
||
303 | $actPrfx = ''; |
||
304 | } |
||
305 | foreach ($ftrs['actions'] as $key => $value) { |
||
306 | if ($action_argument != 0) { |
||
307 | $sReturn .= ' '; |
||
308 | } |
||
309 | switch ($key) { |
||
310 | case 'checkbox': |
||
311 | $checkboxName = $value . '[]'; |
||
312 | $checkboxNameS = $value; |
||
313 | $sReturn .= ' <input type="checkbox" name="' . $checkboxName |
||
314 | . '" id="n' . $aElements[$rCntr][$value] |
||
315 | . '" value="' . $aElements[$rCntr][$value] . '" '; |
||
316 | if (isset($_REQUEST[$checkboxNameS])) { |
||
317 | if (is_array($_REQUEST[$checkboxNameS])) { |
||
318 | if (in_array($aElements[$rCntr][$value], $_REQUEST[$checkboxNameS])) { |
||
319 | $sReturn .= 'checked="checked" '; |
||
320 | } |
||
321 | } else { |
||
322 | if ($aElements[$rCntr][$value] == $_REQUEST[$checkboxNameS]) { |
||
323 | $sReturn .= 'checked="checked" '; |
||
324 | } |
||
325 | } |
||
326 | } |
||
327 | if (strpos($_REQUEST['view'], 'multiEdit') !== false) { |
||
328 | $sReturn .= 'disabled="disabled" '; |
||
329 | } |
||
330 | $sReturn .= '/>'; |
||
331 | break; |
||
332 | case 'checkbox_inlineEdit': |
||
333 | $checkboxName = $value . '[]'; |
||
334 | $checkboxNameS = $value; |
||
335 | $sReturn .= ' <input type="checkbox" name="' . $checkboxName |
||
336 | . '" id="n' . $aElements[$rCntr][$value] . '" value="' |
||
337 | . $aElements[$rCntr][$value] . '"/>'; |
||
338 | break; |
||
339 | case 'edit': |
||
340 | $edt = ''; |
||
341 | if (isset($ftrs['NoAjaxEditing'])) { |
||
342 | $edt .= $_SERVER['PHP_SELF'] . '?' . $actPrfx |
||
343 | . $action_key . '=' . $value[0] . '&'; |
||
344 | $iActArgs = count($value[1]); |
||
345 | for ($cntr2 = 0; $cntr2 < $iActArgs; $cntr2++) { |
||
346 | $edt .= $value[1][$cntr2] . '=' . $aElements[$rCntr][$value[1][$cntr2]]; |
||
347 | } |
||
348 | $sReturn .= '<a href="' . $edt . '"><i class="fa fa-pencil"> </i></a>'; |
||
349 | View Code Duplication | } else { |
|
350 | $edt .= 'javascript:loadAE(\'' . $_SERVER['PHP_SELF'] . '?' |
||
351 | . $actPrfx . $action_key . '=' . $value[0] . '&'; |
||
352 | $iActArgs = count($value[1]); |
||
353 | for ($cntr2 = 0; $cntr2 < $iActArgs; $cntr2++) { |
||
354 | $edt .= $value[1][$cntr2] . '=' . $aElements[$rCntr][$value[1][$cntr2]]; |
||
355 | } |
||
356 | $edt .= '\');'; |
||
357 | $sReturn .= '<a href="#" onclick="' . $edt . '">' |
||
358 | . '<i class="fa fa-pencil"> </i></a>'; |
||
359 | } |
||
360 | break; |
||
361 | case 'list2': |
||
362 | $edt = ''; |
||
363 | if (isset($ftrs['NoAjaxEditing'])) { |
||
364 | $sReturn .= '<a href="?' . $actPrfx . $action_key . '=' . $value[0] . '&'; |
||
365 | $iActArgs = count($value[1]); |
||
366 | for ($cntr2 = 0; $cntr2 < $iActArgs; $cntr2++) { |
||
367 | $sReturn .= $value[1][$cntr2] . '=' . $aElements[$rCntr][$value[1][$cntr2]]; |
||
368 | } |
||
369 | $sReturn .= '"><i class="fa fa-list"> </i></a>'; |
||
370 | View Code Duplication | } else { |
|
371 | $edt .= 'javascript:loadAE(\'' . $_SERVER['PHP_SELF'] . '?' |
||
372 | . $actPrfx . $action_key . '=' . $value[0] . '&'; |
||
373 | $iActArgs = count($value[1]); |
||
374 | for ($cntr2 = 0; $cntr2 < $iActArgs; $cntr2++) { |
||
375 | $edt .= $value[1][$cntr2] . '=' . $aElements[$rCntr][$value[1][$cntr2]]; |
||
376 | } |
||
377 | $edt .= '\');'; |
||
378 | $sReturn .= '<a href="#" onclick="' . $edt . '">' |
||
379 | . '<i class="fa fa-list"> </i></a>'; |
||
380 | } |
||
381 | break; |
||
382 | case 'delete': |
||
383 | $sReturn .= '<a href="javascript:setQuest(\'' . $value[0] . '\',\''; |
||
384 | $iActArgs = count($value[1]); |
||
385 | for ($cntr2 = 0; $cntr2 < $iActArgs; $cntr2++) { |
||
386 | $sReturn .= $value[1][$cntr2] . '=' . $aElements[$rCntr][$value[1][$cntr2]]; |
||
387 | } |
||
388 | $sReturn .= '\');"><i class="fa fa-times"> </i></a>'; |
||
389 | break; |
||
390 | } |
||
391 | $action_argument += 1; |
||
392 | } |
||
393 | $sReturn .= '</td>'; |
||
394 | } |
||
395 | // Regular columns |
||
396 | $sReturn .= $this->setTableCell($row_current, $ftrs); |
||
397 | // Computed columns |
||
398 | if (isset($ftrs['computed_columns'])) { |
||
399 | foreach ($ftrs['computed_columns'] as $key => $value) { |
||
400 | if ($value[0] == '%') { |
||
401 | $dec = $value[2] + 2; |
||
402 | } else { |
||
403 | $dec = $value[2]; |
||
404 | } |
||
405 | switch ($value[1]) { |
||
406 | case '/': |
||
407 | // next variable is only to avoid a long line |
||
408 | $shorter = [ |
||
409 | $aElements[$rCntr][$value[3]], |
||
410 | $aElements[$rCntr][$value[4]], |
||
411 | ]; |
||
412 | $aElements[$rCntr][$key] = $this->setDividedResult($shorter[0], $shorter[1], $dec); |
||
413 | break; |
||
414 | case '+': |
||
415 | // next variable is only to avoid a long line |
||
416 | $iTemp = $this->setArrayValuesAsKey([ |
||
417 | $value[0], |
||
418 | $value[1], |
||
419 | $value[2] |
||
420 | ]); |
||
421 | $aTemp = array_diff($value, $iTemp); |
||
422 | $aElements[$rCntr][$key] = 0; |
||
423 | foreach ($aTemp as $sValue) { |
||
424 | $aElements[$rCntr][$key] += $aElements[$rCntr][$sValue]; |
||
425 | } |
||
426 | break; |
||
427 | default: |
||
428 | $row_computed[$key] = ''; |
||
429 | break; |
||
430 | } |
||
431 | if ($value[0] == '%') { |
||
432 | $row_computed[$key] = ($aElements[$rCntr][$key] * 100); |
||
433 | $dec -= 2; |
||
434 | } else { |
||
435 | $row_computed[$key] = $aElements[$rCntr][$key]; |
||
436 | } |
||
437 | $decimals[$key] = $dec; |
||
438 | } |
||
439 | // displaying them |
||
440 | $sReturn .= $this->setTableCell($row_computed, ['decimals' => $decimals]); |
||
441 | } |
||
442 | $sReturn .= '</tr>'; |
||
443 | } |
||
444 | View Code Duplication | if (isset($iStartingPageRecord)) { |
|
445 | $pgn = $this->setPagination($ftrs['limits'][0], $ftrs['limits'][1], $ftrs['limits'][2]); |
||
446 | $sReturn .= '<tr>' . $this->setStringIntoTag($pgn, 'th', ['colspan' => $iTableColumns]) . '</tr>'; |
||
447 | } |
||
448 | $sReturn .= '</tbody></table>'; |
||
449 | if ($ftrs['grouping_cell_type'] == 'tab') { |
||
450 | if (isset($ftrs['showGroupingCounter'])) { |
||
451 | $sReturn .= $this->updateDivTitleName($remindGroupValue, $groupCounter); |
||
452 | } |
||
453 | $sReturn .= '</div><!-- from ' . $remindGroupValue . ' -->'; |
||
454 | if (!isset($ftrs['noGlobalTab'])) { |
||
455 | $sReturn .= '</div><!-- from global tab -->'; |
||
456 | } |
||
457 | } |
||
458 | if (isset($ftrs['actions']['checkbox'])) { |
||
459 | if (strpos($_REQUEST['view'], 'multiEdit') === false) { |
||
460 | $sReturn .= '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
||
461 | . '\',\'' . $checkboxName . '\',true);">Check All</a> ' |
||
462 | . '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
||
463 | . '\',\'' . $checkboxName . '\',false);">Uncheck All</a> ' |
||
464 | . '<input type="hidden" name="action" value="multiEdit_' . $checkboxNameS . '" />'; |
||
465 | View Code Duplication | if (isset($ftrs['hiddenInput'])) { |
|
466 | if (is_array($ftrs['hiddenInput'])) { |
||
467 | foreach ($ftrs['hiddenInput'] as $valueF) { |
||
468 | $sReturn .= '<input type="hidden" name="' . $valueF |
||
469 | . '" value="' . $_REQUEST[$valueF] . '" />'; |
||
470 | } |
||
471 | } else { |
||
472 | $sReturn .= '<input type="hidden" name="' . $ftrs['hiddenInput'] |
||
473 | . '" value="' . $_REQUEST[$ftrs['hiddenInput']] . '" />'; |
||
474 | } |
||
475 | } |
||
476 | $sReturn .= '<input style="margin: 0 3em 0 3em;" type="submit" ' . 'value="Edit selected" />'; |
||
477 | } |
||
478 | $sReturn .= '</form>'; |
||
479 | } |
||
480 | if (isset($ftrs['actions']['checkbox_inlineEdit'])) { |
||
481 | $sReturn .= '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
||
482 | . '\',\'' . $checkboxName . '\',true);">Check All</a> ' |
||
483 | . '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
||
484 | . '\',\'' . $checkboxName . '\',false);">Uncheck All</a> '; |
||
485 | if (isset($ftrs['visibleInput'])) { |
||
486 | $sReturn .= $ftrs['visibleInput']; |
||
487 | } |
||
488 | $sReturn .= '<input type="hidden" name="view" value="save_' . $checkboxNameS . '" />'; |
||
489 | View Code Duplication | if (isset($ftrs['hiddenInput'])) { |
|
490 | if (is_array($ftrs['hiddenInput'])) { |
||
491 | foreach ($ftrs['hiddenInput'] as $valueF) { |
||
492 | $sReturn .= '<input type="hidden" name="' . $valueF |
||
493 | . '" value="' . $_REQUEST[$valueF] . '" />'; |
||
494 | } |
||
495 | } else { |
||
496 | $sReturn .= '<input type="hidden" name="' . $ftrs['hiddenInput'] |
||
497 | . '" value="' . $_REQUEST[$ftrs['hiddenInput']] . '" />'; |
||
498 | } |
||
499 | } |
||
500 | $sReturn .= '<input style="margin: 0 3em 0 3em;" type="submit" value="Store the modification" />'; |
||
501 | $sReturn .= '</form>'; |
||
502 | } |
||
503 | return $sReturn; |
||
504 | } |
||
505 | |||
774 |
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.