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