| Conditions | 90 | 
| Paths | > 20000 | 
| Total Lines | 374 | 
| 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 = $this->setPagination($ftrs['limits'][0], $ftrs['limits'][1], $ftrs['limits'][2], $bKpFlPge); | ||
| 143 | $sReturn .= $this->setStringIntoTag($this->setStringIntoTag($pgn, 'th', [ | ||
| 144 | 'colspan' => $iTableColumns | ||
| 145 | ]), 'tr'); | ||
| 146 | } | ||
| 147 | $tbl['Header'] = '<tr>'; | ||
| 148 |                 if (isset($ftrs['grouping_cell'])) { // Grouping columns | ||
| 149 | $header = array_diff_key($header, [$ftrs['grouping_cell'] => '']); | ||
| 150 | } | ||
| 151 |                 if (isset($ftrs['actions'])) { // Action column | ||
| 152 | $tbl['Header'] .= '<th> </th>'; | ||
| 153 | } | ||
| 154 |                 if (isset($ftrs['RowStyle'])) { //Exclude style columns from displaying | ||
| 155 | $tmpClmns = $this->setArrayValuesAsKey([$ftrs['RowStyle']]); | ||
| 156 | $header = array_diff_key($header, $tmpClmns); | ||
| 157 | $hdClmns = array_merge($hdClmns, $tmpClmns); | ||
| 158 | unset($tmpClmns); | ||
| 159 | } | ||
| 160 | $tbl['Header'] .= $this->setTableHeader($header, $ftrs['headers_breaked']); // Regular columns | ||
| 161 |                 if (isset($ftrs['computed_columns'])) { // Computed columns | ||
| 162 | $tbl['Header'] .= $this->setTableHeader($ftrs['computed_columns'], $ftrs['headers_breaked']); | ||
| 163 | } | ||
| 164 | $tbl['Header'] .= '</tr></thead><tbody>'; | ||
| 165 |                 if ($ftrs['grouping_cell_type'] == 'row') { | ||
| 166 | $sReturn .= $tbl['Header']; | ||
| 167 | } | ||
| 168 | } | ||
| 169 | $row_current = array_diff_key($aElements[$rCntr], $hdClmns); | ||
| 170 |             if (isset($ftrs['row_colored_alternated'])) { | ||
| 171 |                 if ($ftrs['row_colored_alternated'][0] == '#') { | ||
| 172 | $color_column_value = $rCntr; | ||
| 173 |                 } else { | ||
| 174 | $color_column_value = $row_current[$ftrs['row_colored_alternated'][0]]; | ||
| 175 | } | ||
| 176 |                 if ($remebered_value != $color_column_value) { | ||
| 177 |                     if (isset($color_no)) { | ||
| 178 | $color_no = 1; | ||
| 179 |                     } else { | ||
| 180 | $color_no = 2; | ||
| 181 | } | ||
| 182 | $remebered_value = $color_column_value; | ||
| 183 | } | ||
| 184 | $color = ' style="background-color: ' . $ftrs['row_colored_alternated'][$color_no] . ';"'; | ||
| 185 |             } else { | ||
| 186 |                 if (isset($ftrs['RowStyle'])) { | ||
| 187 | $color = ' style="' . $aElements[$rCntr][$ftrs['RowStyle']] . '"'; | ||
| 188 |                 } else { | ||
| 189 | $color = ''; | ||
| 190 | } | ||
| 191 | } | ||
| 192 | $tbl['tr_Color'] = '<tr' . $color . '>'; | ||
| 193 | // Grouping column | ||
| 194 |             if (isset($ftrs['grouping_cell'])) { | ||
| 195 |                 foreach ($aElements[$rCntr] as $key => $value) { | ||
| 196 |                     if (($ftrs['grouping_cell'] == $key) && ($remindGroupValue != $value)) { | ||
| 197 |                         switch ($ftrs['grouping_cell_type']) { | ||
| 198 | case 'row': | ||
| 199 | $sReturn .= $tbl['tr_Color'] . '<td ' . 'colspan="' . $iTableColumns . '">' | ||
| 200 | . $this->setStringIntoTag($value, 'div', ['class' => 'rowGroup rounded']) | ||
| 201 | . '</td></tr>'; | ||
| 202 | break; | ||
| 203 | case 'tab': | ||
| 204 |                                 if (is_null($remindGroupValue)) { | ||
| 205 |                                     if (isset($ftrs['showGroupingCounter'])) { | ||
| 206 | $groupCounter = 0; | ||
| 207 | } | ||
| 208 |                                 } else { | ||
| 209 | $sReturn .= '</tbody></table>'; | ||
| 210 |                                     if (isset($ftrs['showGroupingCounter'])) { | ||
| 211 | $sReturn .= $this->updateDivTitleName($remindGroupValue, $groupCounter); | ||
| 212 | $groupCounter = 0; | ||
| 213 | } | ||
| 214 | $sReturn .= '</div>'; | ||
| 215 | } | ||
| 216 | $sReturn .= '<div class="tabbertab'; | ||
| 217 |                                 if (isset($ftrs['grouping_default_tab'])) { | ||
| 218 | $sReturn .= ($ftrs['grouping_default_tab'] == $value ? ' tabbertabdefault' : ''); | ||
| 219 | } | ||
| 220 | $sReturn .= '" id="tab_' . $this->cleanStringForId($value) . '" ' | ||
| 221 | . 'title="' . $value . '">' | ||
| 222 | . $tbl['Def'] . $tbl['Head'] . $tbl['Header']; | ||
| 223 | break; | ||
| 224 | } | ||
| 225 | $remindGroupValue = $value; | ||
| 226 | } | ||
| 227 | } | ||
| 228 | } | ||
| 229 |             if (isset($ftrs['grouping_cell'])) { | ||
| 230 |                 if ($ftrs['grouping_cell_type'] == 'tab') { | ||
| 231 |                     if (isset($ftrs['showGroupingCounter'])) { | ||
| 232 | $groupCounter++; | ||
| 233 | } | ||
| 234 | } | ||
| 235 | } | ||
| 236 | $sReturn .= $tbl['tr_Color']; | ||
| 237 | // Action column | ||
| 238 | $checkboxName = ''; | ||
| 239 | $checkboxNameS = ''; | ||
| 240 |             if (isset($ftrs['actions'])) { | ||
| 241 | $sReturn .= '<td style="white-space:nowrap;">'; | ||
| 242 | $action_argument = 0; | ||
| 243 |                 if (isset($ftrs['actions']['key'])) { | ||
| 244 | $actionKey = $ftrs['actions']['key']; | ||
| 245 |                 } else { | ||
| 246 | $actionKey = 'view'; | ||
| 247 | } | ||
| 248 |                 if (isset($ftrs['action_prefix'])) { | ||
| 249 | $actPrfx = $ftrs['action_prefix'] . '&'; | ||
| 250 | $actionKey = 'view2'; | ||
| 251 |                 } else { | ||
| 252 | $actPrfx = ''; | ||
| 253 | } | ||
| 254 |                 foreach ($ftrs['actions'] as $key => $value) { | ||
| 255 |                     if ($action_argument != 0) { | ||
| 256 | $sReturn .= ' '; | ||
| 257 | } | ||
| 258 |                     switch ($key) { | ||
| 259 | case 'checkbox': | ||
| 260 | $checkboxName = $value . '[]'; | ||
| 261 | $checkboxNameS = $value; | ||
| 262 | $sReturn .= ' <input type="checkbox" name="' . $checkboxName | ||
| 263 | . '" id="n' . $aElements[$rCntr][$value] | ||
| 264 | . '" value="' . $aElements[$rCntr][$value] . '" '; | ||
| 265 |                             if (isset($_REQUEST[$checkboxNameS])) { | ||
| 266 |                                 if (is_array($_REQUEST[$checkboxNameS])) { | ||
| 267 |                                     if (in_array($aElements[$rCntr][$value], $_REQUEST[$checkboxNameS])) { | ||
| 268 | $sReturn .= 'checked="checked" '; | ||
| 269 | } | ||
| 270 |                                 } else { | ||
| 271 |                                     if ($aElements[$rCntr][$value] == $_REQUEST[$checkboxNameS]) { | ||
| 272 | $sReturn .= 'checked="checked" '; | ||
| 273 | } | ||
| 274 | } | ||
| 275 | } | ||
| 276 |                             if (strpos($_REQUEST['view'], 'multiEdit') !== false) { | ||
| 277 | $sReturn .= 'disabled="disabled" '; | ||
| 278 | } | ||
| 279 | $sReturn .= '/>'; | ||
| 280 | break; | ||
| 281 | case 'checkbox_inlineEdit': | ||
| 282 | $checkboxName = $value . '[]'; | ||
| 283 | $checkboxNameS = $value; | ||
| 284 | $sReturn .= ' <input type="checkbox" name="' . $checkboxName | ||
| 285 | . '" id="n' . $aElements[$rCntr][$value] . '" value="' | ||
| 286 | . $aElements[$rCntr][$value] . '"/>'; | ||
| 287 | break; | ||
| 288 | case 'delete': | ||
| 289 | $sReturn .= '<a href="#" onclick="javascript:setQuest(\'' . $value[0] . '\',\''; | ||
| 290 | $iActArgs = count($value[1]); | ||
| 291 |                             for ($cntr2 = 0; $cntr2 < $iActArgs; $cntr2++) { | ||
| 292 | $sReturn .= $value[1][$cntr2] . '=' . $aElements[$rCntr][$value[1][$cntr2]]; | ||
| 293 | } | ||
| 294 | $sReturn .= '\');" id="' . $key . $rCntr . '"><i class="fa fa-times"> </i></a>'; | ||
| 295 | break; | ||
| 296 | case 'edit': | ||
| 297 | case 'list2': | ||
| 298 | case 'schedule': | ||
| 299 | $vIc = ($key == 'edit' ? 'pencil' : ($key == 'list2' ? 'list' : 'hourglass-half')); | ||
| 300 | $sReturn .= $this->setDynamicActionToSpecialCell($value, $aElements, [ | ||
| 301 | 'vIcon' => 'fa fa-' . $vIc, | ||
| 302 | 'aPrefix' => $actPrfx, | ||
| 303 | 'aKey' => $actionKey, | ||
| 304 | 'rCounter' => $rCntr, | ||
| 305 | 'Features' => $ftrs, | ||
| 306 | 'key' => $key, | ||
| 307 | ]); | ||
| 308 | break; | ||
| 309 | } | ||
| 310 | $action_argument += 1; | ||
| 311 | } | ||
| 312 | $sReturn .= '</td>'; | ||
| 313 | } | ||
| 314 | // Regular columns | ||
| 315 | $sReturn .= $this->setTableCell($row_current, $ftrs); | ||
| 316 | // Computed columns | ||
| 317 |             if (isset($ftrs['computed_columns'])) { | ||
| 318 | $rowComputed = []; | ||
| 319 | $decimals = []; | ||
| 320 |                 foreach ($ftrs['computed_columns'] as $key => $value) { | ||
| 321 |                     if ($value[0] == '%') { | ||
| 322 | $dec = $value[2] + 2; | ||
| 323 |                     } else { | ||
| 324 | $dec = $value[2]; | ||
| 325 | } | ||
| 326 |                     switch ($value[1]) { | ||
| 327 | case '/': | ||
| 328 | // next variable is only to avoid a long line | ||
| 329 | $shorter = [ | ||
| 330 | $aElements[$rCntr][$value[3]], | ||
| 331 | $aElements[$rCntr][$value[4]], | ||
| 332 | ]; | ||
| 333 | $aElements[$rCntr][$key] = $this->setDividedResult($shorter[0], $shorter[1], $dec); | ||
| 334 | break; | ||
| 335 | case '+': | ||
| 336 | // next variable is only to avoid a long line | ||
| 337 | $iTemp = $this->setArrayValuesAsKey([ | ||
| 338 | $value[0], | ||
| 339 | $value[1], | ||
| 340 | $value[2] | ||
| 341 | ]); | ||
| 342 | $aTemp = array_diff($value, $iTemp); | ||
| 343 | $aElements[$rCntr][$key] = 0; | ||
| 344 |                             foreach ($aTemp as $sValue) { | ||
| 345 | $aElements[$rCntr][$key] += $aElements[$rCntr][$sValue]; | ||
| 346 | } | ||
| 347 | break; | ||
| 348 | default: | ||
| 349 | $rowComputed[$key] = ''; | ||
| 350 | break; | ||
| 351 | } | ||
| 352 |                     if ($value[0] == '%') { | ||
| 353 | $rowComputed[$key] = ($aElements[$rCntr][$key] * 100); | ||
| 354 | $dec -= 2; | ||
| 355 |                     } else { | ||
| 356 | $rowComputed[$key] = $aElements[$rCntr][$key]; | ||
| 357 | } | ||
| 358 | $decimals[$key] = $dec; | ||
| 359 | } | ||
| 360 | // displaying them | ||
| 361 | $sReturn .= $this->setTableCell($rowComputed, ['decimals' => $decimals]); | ||
| 362 | } | ||
| 363 | $sReturn .= '</tr>'; | ||
| 364 | } | ||
| 365 |         if (isset($iStartingPageRecord)) { | ||
| 366 | $pgn = $this->setPagination($ftrs['limits'][0], $ftrs['limits'][1], $ftrs['limits'][2]); | ||
| 367 | $sReturn .= '<tr>' . $this->setStringIntoTag($pgn, 'th', ['colspan' => $iTableColumns]) . '</tr>'; | ||
| 368 | } | ||
| 369 | $sReturn .= '</tbody></table>'; | ||
| 370 |         if ($ftrs['grouping_cell_type'] == 'tab') { | ||
| 371 |             if (isset($ftrs['showGroupingCounter'])) { | ||
| 372 | $sReturn .= $this->updateDivTitleName($remindGroupValue, $groupCounter); | ||
| 373 | } | ||
| 374 | $sReturn .= '</div><!-- from ' . $remindGroupValue . ' -->'; | ||
| 375 |             if (!isset($ftrs['noGlobalTab'])) { | ||
| 376 | $sReturn .= '</div><!-- from global tab -->'; | ||
| 377 | } | ||
| 378 | } | ||
| 379 |         if (isset($ftrs['actions']['checkbox'])) { | ||
| 380 |             if (strpos($_REQUEST['view'], 'multiEdit') === false) { | ||
| 381 | $sReturn .= '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId | ||
| 382 | . '\',\'' . $checkboxName . '\',true);">Check All</a>  ' | ||
|  | |||
| 383 | . '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId | ||
| 384 | . '\',\'' . $checkboxName . '\',false);">Uncheck All</a>  ' | ||
| 385 | . '<input type="hidden" name="action" value="multiEdit_' . $checkboxNameS . '" />'; | ||
| 386 |                 if (isset($ftrs['hiddenInput'])) { | ||
| 387 |                     if (is_array($ftrs['hiddenInput'])) { | ||
| 388 |                         foreach ($ftrs['hiddenInput'] as $valueF) { | ||
| 389 | $sReturn .= '<input type="hidden" name="' . $valueF | ||
| 390 | . '" value="' . $_REQUEST[$valueF] . '" />'; | ||
| 391 | } | ||
| 392 |                     } else { | ||
| 393 | $sReturn .= '<input type="hidden" name="' . $ftrs['hiddenInput'] | ||
| 394 | . '" value="' . $_REQUEST[$ftrs['hiddenInput']] . '" />'; | ||
| 395 | } | ||
| 396 | } | ||
| 397 | $sReturn .= '<input style="margin: 0 3em 0 3em;" type="submit" ' . 'value="Edit selected" />'; | ||
| 398 | } | ||
| 399 | $sReturn .= '</form>'; | ||
| 400 | } | ||
| 401 |         if (isset($ftrs['actions']['checkbox_inlineEdit'])) { | ||
| 402 | $sReturn .= '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId | ||
| 403 | . '\',\'' . $checkboxName . '\',true);">Check All</a>  ' | ||
| 404 | . '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId | ||
| 405 | . '\',\'' . $checkboxName . '\',false);">Uncheck All</a>  '; | ||
| 406 |             if (isset($ftrs['visibleInput'])) { | ||
| 407 | $sReturn .= $ftrs['visibleInput']; | ||
| 408 | } | ||
| 409 | $sReturn .= '<input type="hidden" name="view" value="save_' . $checkboxNameS . '" />'; | ||
| 410 |             if (isset($ftrs['hiddenInput'])) { | ||
| 411 |                 if (is_array($ftrs['hiddenInput'])) { | ||
| 412 |                     foreach ($ftrs['hiddenInput'] as $valueF) { | ||
| 413 | $sReturn .= '<input type="hidden" name="' . $valueF . '" value="' . $_REQUEST[$valueF] . '" />'; | ||
| 414 | } | ||
| 415 |                 } else { | ||
| 416 | $sReturn .= '<input type="hidden" name="' . $ftrs['hiddenInput'] | ||
| 417 | . '" value="' . $_REQUEST[$ftrs['hiddenInput']] . '" />'; | ||
| 418 | } | ||
| 419 | } | ||
| 420 | $sReturn .= '<input style="margin: 0 3em 0 3em;" type="submit" value="Store the modification" />'; | ||
| 421 | $sReturn .= '</form>'; | ||
| 422 | } | ||
| 423 | return $sReturn; | ||
| 424 | } | ||
| 538 |