Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like DomComponentsByDanielGP often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DomComponentsByDanielGP, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 36 | trait DomComponentsByDanielGP |
||
| 37 | { |
||
| 38 | |||
| 39 | use CommonBasic, |
||
| 40 | DomCssAndJavascriptByDanielGP, |
||
| 41 | DomDynamicSelectByDanielGP; |
||
| 42 | |||
| 43 | private function normalizeArrayForUrl($featArray) |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Builds a <select> based on a given array |
||
| 58 | * |
||
| 59 | * @version 20080618 |
||
| 60 | * @param array $aElements |
||
| 61 | * @param mixed $sDefaultValue |
||
| 62 | * @param string $selectName |
||
| 63 | * @param array $featArray |
||
| 64 | * @return string |
||
| 65 | */ |
||
| 66 | protected function setArrayToSelect($aElements, $sDefaultValue, $selectName, $featArray = null) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Converts an array to string |
||
| 86 | * |
||
| 87 | * @param string $sSeparator |
||
| 88 | * @param array $aElements |
||
| 89 | * @return string |
||
| 90 | */ |
||
| 91 | protected function setArrayToStringForUrl($sSeparator, $aElements, $aExceptedElements = ['']) |
||
| 92 | { |
||
| 93 | $outArray = $this->normalizeArrayForUrl($aElements); |
||
| 94 | if (count($outArray) < 1) { |
||
| 95 | return ''; |
||
| 96 | } |
||
| 97 | $xptArray = $this->normalizeArrayForUrl($aExceptedElements); |
||
| 98 | $finalArray = array_diff_key($outArray, $xptArray); |
||
| 99 | return http_build_query($finalArray, '', $sSeparator); |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Returns a table from an query |
||
| 104 | * |
||
| 105 | * @param array $aElements |
||
| 106 | * @param array $ftrs |
||
| 107 | * @param boolean $bKpFlPge |
||
| 108 | * @return string |
||
| 109 | */ |
||
| 110 | protected function setArrayToTable($aElements, $ftrs = null, $bKpFlPge = true) |
||
|
|
|||
| 111 | { |
||
| 112 | $rows = count($aElements); |
||
| 113 | if ($rows == 0) { |
||
| 114 | $divTab = [ |
||
| 115 | 'start' => '', |
||
| 116 | 'end' => '', |
||
| 117 | ]; |
||
| 118 | if (array_key_exists('showGroupingCounter', $ftrs)) { |
||
| 119 | if (array_key_exists('grouping_cell_type', $ftrs) && ($ftrs['grouping_cell_type'] == 'tab')) { |
||
| 120 | $ditTitle = 'No data found'; |
||
| 121 | if (isset($ftrs['showGroupingCounter'])) { |
||
| 122 | $ditTitle .= ' (0)'; |
||
| 123 | } |
||
| 124 | $divTab = [ |
||
| 125 | 'start' => '<div class="tabbertab tabbertabdefault" id="tab_NoData" title="' . $ditTitle . '">', |
||
| 126 | 'end' => '</div><!-- from tab_NoData -->', |
||
| 127 | ]; |
||
| 128 | if (!isset($ftrs['noGlobalTab'])) { |
||
| 129 | $divTab = [ |
||
| 130 | 'start' => '<div class="tabber" id="tab">' . $divTab['start'], |
||
| 131 | 'end' => $divTab['end'] . '</div><!-- from global Tab -->', |
||
| 132 | ]; |
||
| 133 | } |
||
| 134 | } |
||
| 135 | } |
||
| 136 | return $divTab['start'] |
||
| 137 | . $this->setFeedbackModern('error', 'Error', $this->lclMsgCmn('i18n_NoData')) |
||
| 138 | . $divTab['end']; |
||
| 139 | } |
||
| 140 | if (isset($ftrs['limits'])) { |
||
| 141 | $ftrs['limits'][1] = min($ftrs['limits'][1], $ftrs['limits'][2]); |
||
| 142 | if ($ftrs['limits'][2] > $ftrs['limits'][1]) { |
||
| 143 | $iStartingPageRecord = 1; |
||
| 144 | } |
||
| 145 | } |
||
| 146 | $sReturn = ''; |
||
| 147 | if (isset($ftrs['hidden_columns'])) { |
||
| 148 | $hdClmns = $this->setArrayValuesAsKey($ftrs['hidden_columns']); |
||
| 149 | } else { |
||
| 150 | $hdClmns = ['']; |
||
| 151 | } |
||
| 152 | if ((isset($ftrs['actions']['checkbox_inlineEdit'])) || (isset($ftrs['actions']['checkbox']))) { |
||
| 153 | $checkboxFormId = 'frm' . date('YmdHis'); |
||
| 154 | $sReturn .= '<form id="' . $checkboxFormId . '" ' . 'name="' . $checkboxFormId |
||
| 155 | . '" method="post" ' . ' action="' . $this->tCmnRequest->server->get('PHP_SELF') . '" >'; |
||
| 156 | } |
||
| 157 | $tbl['Def'] = '<table' |
||
| 158 | . (isset($ftrs['table_style']) ? ' style="' . $ftrs['table_style'] . '"' : '') |
||
| 159 | . (isset($ftrs['table_class']) ? ' class="' . $ftrs['table_class'] . '"' : '') |
||
| 160 | . '>'; |
||
| 161 | if (!isset($ftrs['grouping_cell_type'])) { |
||
| 162 | $ftrs['grouping_cell_type'] = 'row'; |
||
| 163 | } |
||
| 164 | switch ($ftrs['grouping_cell_type']) { |
||
| 165 | case 'row': |
||
| 166 | $sReturn .= $tbl['Def']; |
||
| 167 | break; |
||
| 168 | case 'tab': |
||
| 169 | if (!isset($ftrs['noGlobalTab'])) { |
||
| 170 | $sReturn .= '<div class="tabber" id="tab">'; |
||
| 171 | } |
||
| 172 | break; |
||
| 173 | } |
||
| 174 | $iTableColumns = 0; |
||
| 175 | $remebered_value = -1; |
||
| 176 | $remindGroupValue = null; |
||
| 177 | $color_no = null; |
||
| 178 | if (!isset($ftrs['headers_breaked'])) { |
||
| 179 | $ftrs['headers_breaked'] = true; |
||
| 180 | } |
||
| 181 | for ($rCntr = 0; $rCntr < $rows; $rCntr++) { |
||
| 182 | if ($rCntr == 0) { |
||
| 183 | $header = array_diff_key($aElements[$rCntr], $hdClmns); |
||
| 184 | $iTableColumns = count($header); |
||
| 185 | if (isset($ftrs['computed_columns'])) { |
||
| 186 | $iTableColumns += count($ftrs['computed_columns']); |
||
| 187 | } |
||
| 188 | if (isset($ftrs['actions'])) { |
||
| 189 | $iTableColumns += 1; |
||
| 190 | } |
||
| 191 | if (isset($ftrs['grouping_cell'])) { |
||
| 192 | $iTableColumns -= 1; |
||
| 193 | } |
||
| 194 | $tbl['Head'] = '<thead>'; |
||
| 195 | if ($ftrs['grouping_cell_type'] == 'row') { |
||
| 196 | $sReturn .= $tbl['Head']; |
||
| 197 | } |
||
| 198 | View Code Duplication | if (isset($iStartingPageRecord)) { |
|
| 199 | $pgn = $this->setPagination($ftrs['limits'][0], $ftrs['limits'][1], $ftrs['limits'][2], $bKpFlPge); |
||
| 200 | $sReturn .= $this->setStringIntoTag($this->setStringIntoTag($pgn, 'th', [ |
||
| 201 | 'colspan' => $iTableColumns |
||
| 202 | ]), 'tr'); |
||
| 203 | } |
||
| 204 | $tbl['Header'] = '<tr>'; |
||
| 205 | if (isset($ftrs['grouping_cell'])) { // Grouping columns |
||
| 206 | $header = array_diff_key($header, [$ftrs['grouping_cell'] => '']); |
||
| 207 | } |
||
| 208 | if (isset($ftrs['actions'])) { // Action column |
||
| 209 | $tbl['Header'] .= '<th> </th>'; |
||
| 210 | } |
||
| 211 | if (isset($ftrs['RowStyle'])) { //Exclude style columns from displaying |
||
| 212 | $tmpClmns = $this->setArrayValuesAsKey([$ftrs['RowStyle']]); |
||
| 213 | $header = array_diff_key($header, $tmpClmns); |
||
| 214 | $hdClmns = array_merge($hdClmns, $tmpClmns); |
||
| 215 | unset($tmpClmns); |
||
| 216 | } |
||
| 217 | $tbl['Header'] .= $this->setTableHeader($header, $ftrs['headers_breaked']); // Regular columns |
||
| 218 | if (isset($ftrs['computed_columns'])) { // Computed columns |
||
| 219 | $tbl['Header'] .= $this->setTableHeader($ftrs['computed_columns'], $ftrs['headers_breaked']); |
||
| 220 | } |
||
| 221 | $tbl['Header'] .= '</tr></thead><tbody>'; |
||
| 222 | if ($ftrs['grouping_cell_type'] == 'row') { |
||
| 223 | $sReturn .= $tbl['Header']; |
||
| 224 | } |
||
| 225 | } |
||
| 226 | $row_current = array_diff_key($aElements[$rCntr], $hdClmns); |
||
| 227 | if (isset($ftrs['row_colored_alternated'])) { |
||
| 228 | if ($ftrs['row_colored_alternated'][0] == '#') { |
||
| 229 | $color_column_value = $rCntr; |
||
| 230 | } else { |
||
| 231 | $color_column_value = $row_current[$ftrs['row_colored_alternated'][0]]; |
||
| 232 | } |
||
| 233 | if ($remebered_value != $color_column_value) { |
||
| 234 | if (isset($color_no)) { |
||
| 235 | $color_no = 1; |
||
| 236 | } else { |
||
| 237 | $color_no = 2; |
||
| 238 | } |
||
| 239 | $remebered_value = $color_column_value; |
||
| 240 | } |
||
| 241 | $color = ' style="background-color: ' . $ftrs['row_colored_alternated'][$color_no] . ';"'; |
||
| 242 | } else { |
||
| 243 | if (isset($ftrs['RowStyle'])) { |
||
| 244 | $color = ' style="' . $aElements[$rCntr][$ftrs['RowStyle']] . '"'; |
||
| 245 | } else { |
||
| 246 | $color = ''; |
||
| 247 | } |
||
| 248 | } |
||
| 249 | $tbl['tr_Color'] = '<tr' . $color . '>'; |
||
| 250 | // Grouping column |
||
| 251 | if (isset($ftrs['grouping_cell'])) { |
||
| 252 | foreach ($aElements[$rCntr] as $key => $value) { |
||
| 253 | if (($ftrs['grouping_cell'] == $key) && ($remindGroupValue != $value)) { |
||
| 254 | switch ($ftrs['grouping_cell_type']) { |
||
| 255 | case 'row': |
||
| 256 | $sReturn .= $tbl['tr_Color'] . '<td ' . 'colspan="' . $iTableColumns . '">' |
||
| 257 | . $this->setStringIntoTag($value, 'div', ['class' => 'rowGroup rounded']) |
||
| 258 | . '</td></tr>'; |
||
| 259 | break; |
||
| 260 | case 'tab': |
||
| 261 | if (is_null($remindGroupValue)) { |
||
| 262 | if (isset($ftrs['showGroupingCounter'])) { |
||
| 263 | $groupCounter = 0; |
||
| 264 | } |
||
| 265 | } else { |
||
| 266 | $sReturn .= '</tbody></table>'; |
||
| 267 | if (isset($ftrs['showGroupingCounter'])) { |
||
| 268 | $sReturn .= $this->updateDivTitleName($remindGroupValue, $groupCounter); |
||
| 269 | $groupCounter = 0; |
||
| 270 | } |
||
| 271 | $sReturn .= '</div>'; |
||
| 272 | } |
||
| 273 | $sReturn .= '<div class="tabbertab'; |
||
| 274 | if (isset($ftrs['grouping_default_tab'])) { |
||
| 275 | $sReturn .= ($ftrs['grouping_default_tab'] == $value ? ' tabbertabdefault' : ''); |
||
| 276 | } |
||
| 277 | $sReturn .= '" id="tab_' . $this->cleanStringForId($value) . '" ' |
||
| 278 | . 'title="' . $value . '">' |
||
| 279 | . $tbl['Def'] . $tbl['Head'] . $tbl['Header']; |
||
| 280 | break; |
||
| 281 | } |
||
| 282 | $remindGroupValue = $value; |
||
| 283 | } |
||
| 284 | } |
||
| 285 | } |
||
| 286 | if (isset($ftrs['grouping_cell'])) { |
||
| 287 | if ($ftrs['grouping_cell_type'] == 'tab') { |
||
| 288 | if (isset($ftrs['showGroupingCounter'])) { |
||
| 289 | $groupCounter++; |
||
| 290 | } |
||
| 291 | } |
||
| 292 | } |
||
| 293 | $sReturn .= $tbl['tr_Color']; |
||
| 294 | // Action column |
||
| 295 | if (isset($ftrs['actions'])) { |
||
| 296 | $sReturn .= '<td style="white-space:nowrap;">'; |
||
| 297 | $action_argument = 0; |
||
| 298 | if (isset($ftrs['actions']['key'])) { |
||
| 299 | $action_key = $ftrs['actions']['key']; |
||
| 300 | } else { |
||
| 301 | $action_key = 'view'; |
||
| 302 | } |
||
| 303 | if (isset($ftrs['action_prefix'])) { |
||
| 304 | $actPrfx = $ftrs['action_prefix'] . '&'; |
||
| 305 | $action_key = 'view2'; |
||
| 306 | } else { |
||
| 307 | $actPrfx = ''; |
||
| 308 | } |
||
| 309 | foreach ($ftrs['actions'] as $key => $value) { |
||
| 310 | if ($action_argument != 0) { |
||
| 311 | $sReturn .= ' '; |
||
| 312 | } |
||
| 313 | switch ($key) { |
||
| 314 | case 'checkbox': |
||
| 315 | $checkboxName = $value . '[]'; |
||
| 316 | $checkboxNameS = $value; |
||
| 317 | $sReturn .= ' <input type="checkbox" name="' . $checkboxName |
||
| 318 | . '" id="n' . $aElements[$rCntr][$value] |
||
| 319 | . '" value="' . $aElements[$rCntr][$value] . '" '; |
||
| 320 | if (isset($_REQUEST[$checkboxNameS])) { |
||
| 321 | if (is_array($_REQUEST[$checkboxNameS])) { |
||
| 322 | if (in_array($aElements[$rCntr][$value], $_REQUEST[$checkboxNameS])) { |
||
| 323 | $sReturn .= 'checked="checked" '; |
||
| 324 | } |
||
| 325 | } else { |
||
| 326 | if ($aElements[$rCntr][$value] == $_REQUEST[$checkboxNameS]) { |
||
| 327 | $sReturn .= 'checked="checked" '; |
||
| 328 | } |
||
| 329 | } |
||
| 330 | } |
||
| 331 | if (strpos($_REQUEST['view'], 'multiEdit') !== false) { |
||
| 332 | $sReturn .= 'disabled="disabled" '; |
||
| 333 | } |
||
| 334 | $sReturn .= '/>'; |
||
| 335 | break; |
||
| 336 | case 'checkbox_inlineEdit': |
||
| 337 | $checkboxName = $value . '[]'; |
||
| 338 | $checkboxNameS = $value; |
||
| 339 | $sReturn .= ' <input type="checkbox" name="' . $checkboxName |
||
| 340 | . '" id="n' . $aElements[$rCntr][$value] . '" value="' |
||
| 341 | . $aElements[$rCntr][$value] . '"/>'; |
||
| 342 | break; |
||
| 343 | case 'delete': |
||
| 344 | $sReturn .= '<a href="javascript:setQuest(\'' . $value[0] . '\',\''; |
||
| 345 | $iActArgs = count($value[1]); |
||
| 346 | for ($cntr2 = 0; $cntr2 < $iActArgs; $cntr2++) { |
||
| 347 | $sReturn .= $value[1][$cntr2] . '=' . $aElements[$rCntr][$value[1][$cntr2]]; |
||
| 348 | } |
||
| 349 | $sReturn .= '\');"><i class="fa fa-times"> </i></a>'; |
||
| 350 | break; |
||
| 351 | View Code Duplication | case 'edit': |
|
| 352 | $sReturn .= $this->setDynamicActionToSpecialCell($value, $aElements, [ |
||
| 353 | 'vIcon' => 'fa fa-pencil', |
||
| 354 | 'aPrefix' => $actPrfx, |
||
| 355 | 'aKey' => $action_key, |
||
| 356 | 'rCounter' => $rCntr, |
||
| 357 | 'Features' => $ftrs, |
||
| 358 | ]); |
||
| 359 | break; |
||
| 360 | View Code Duplication | case 'list2': |
|
| 361 | $sReturn .= $this->setDynamicActionToSpecialCell($value, $aElements, [ |
||
| 362 | 'vIcon' => 'fa fa-list', |
||
| 363 | 'aPrefix' => $actPrfx, |
||
| 364 | 'aKey' => $action_key, |
||
| 365 | 'rCounter' => $rCntr, |
||
| 366 | 'Features' => $ftrs, |
||
| 367 | ]); |
||
| 368 | break; |
||
| 369 | View Code Duplication | case 'schedule': |
|
| 370 | $sReturn .= $this->setDynamicActionToSpecialCell($value, $aElements, [ |
||
| 371 | 'vIcon' => 'fa fa-hourglass-half', |
||
| 372 | 'aPrefix' => $actPrfx, |
||
| 373 | 'aKey' => $action_key, |
||
| 374 | 'rCounter' => $rCntr, |
||
| 375 | 'Features' => $ftrs, |
||
| 376 | ]); |
||
| 377 | break; |
||
| 378 | } |
||
| 379 | $action_argument += 1; |
||
| 380 | } |
||
| 381 | $sReturn .= '</td>'; |
||
| 382 | } |
||
| 383 | // Regular columns |
||
| 384 | $sReturn .= $this->setTableCell($row_current, $ftrs); |
||
| 385 | // Computed columns |
||
| 386 | if (isset($ftrs['computed_columns'])) { |
||
| 387 | foreach ($ftrs['computed_columns'] as $key => $value) { |
||
| 388 | if ($value[0] == '%') { |
||
| 389 | $dec = $value[2] + 2; |
||
| 390 | } else { |
||
| 391 | $dec = $value[2]; |
||
| 392 | } |
||
| 393 | switch ($value[1]) { |
||
| 394 | case '/': |
||
| 395 | // next variable is only to avoid a long line |
||
| 396 | $shorter = [ |
||
| 397 | $aElements[$rCntr][$value[3]], |
||
| 398 | $aElements[$rCntr][$value[4]], |
||
| 399 | ]; |
||
| 400 | $aElements[$rCntr][$key] = $this->setDividedResult($shorter[0], $shorter[1], $dec); |
||
| 401 | break; |
||
| 402 | case '+': |
||
| 403 | // next variable is only to avoid a long line |
||
| 404 | $iTemp = $this->setArrayValuesAsKey([ |
||
| 405 | $value[0], |
||
| 406 | $value[1], |
||
| 407 | $value[2] |
||
| 408 | ]); |
||
| 409 | $aTemp = array_diff($value, $iTemp); |
||
| 410 | $aElements[$rCntr][$key] = 0; |
||
| 411 | foreach ($aTemp as $sValue) { |
||
| 412 | $aElements[$rCntr][$key] += $aElements[$rCntr][$sValue]; |
||
| 413 | } |
||
| 414 | break; |
||
| 415 | default: |
||
| 416 | $row_computed[$key] = ''; |
||
| 417 | break; |
||
| 418 | } |
||
| 419 | if ($value[0] == '%') { |
||
| 420 | $row_computed[$key] = ($aElements[$rCntr][$key] * 100); |
||
| 421 | $dec -= 2; |
||
| 422 | } else { |
||
| 423 | $row_computed[$key] = $aElements[$rCntr][$key]; |
||
| 424 | } |
||
| 425 | $decimals[$key] = $dec; |
||
| 426 | } |
||
| 427 | // displaying them |
||
| 428 | $sReturn .= $this->setTableCell($row_computed, ['decimals' => $decimals]); |
||
| 429 | } |
||
| 430 | $sReturn .= '</tr>'; |
||
| 431 | } |
||
| 432 | View Code Duplication | if (isset($iStartingPageRecord)) { |
|
| 433 | $pgn = $this->setPagination($ftrs['limits'][0], $ftrs['limits'][1], $ftrs['limits'][2]); |
||
| 434 | $sReturn .= '<tr>' . $this->setStringIntoTag($pgn, 'th', ['colspan' => $iTableColumns]) . '</tr>'; |
||
| 435 | } |
||
| 436 | $sReturn .= '</tbody></table>'; |
||
| 437 | if ($ftrs['grouping_cell_type'] == 'tab') { |
||
| 438 | if (isset($ftrs['showGroupingCounter'])) { |
||
| 439 | $sReturn .= $this->updateDivTitleName($remindGroupValue, $groupCounter); |
||
| 440 | } |
||
| 441 | $sReturn .= '</div><!-- from ' . $remindGroupValue . ' -->'; |
||
| 442 | if (!isset($ftrs['noGlobalTab'])) { |
||
| 443 | $sReturn .= '</div><!-- from global tab -->'; |
||
| 444 | } |
||
| 445 | } |
||
| 446 | if (isset($ftrs['actions']['checkbox'])) { |
||
| 447 | if (strpos($_REQUEST['view'], 'multiEdit') === false) { |
||
| 448 | $sReturn .= '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
||
| 449 | . '\',\'' . $checkboxName . '\',true);">Check All</a> ' |
||
| 450 | . '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
||
| 451 | . '\',\'' . $checkboxName . '\',false);">Uncheck All</a> ' |
||
| 452 | . '<input type="hidden" name="action" value="multiEdit_' . $checkboxNameS . '" />'; |
||
| 453 | View Code Duplication | if (isset($ftrs['hiddenInput'])) { |
|
| 454 | if (is_array($ftrs['hiddenInput'])) { |
||
| 455 | foreach ($ftrs['hiddenInput'] as $valueF) { |
||
| 456 | $sReturn .= '<input type="hidden" name="' . $valueF |
||
| 457 | . '" value="' . $_REQUEST[$valueF] . '" />'; |
||
| 458 | } |
||
| 459 | } else { |
||
| 460 | $sReturn .= '<input type="hidden" name="' . $ftrs['hiddenInput'] |
||
| 461 | . '" value="' . $_REQUEST[$ftrs['hiddenInput']] . '" />'; |
||
| 462 | } |
||
| 463 | } |
||
| 464 | $sReturn .= '<input style="margin: 0 3em 0 3em;" type="submit" ' . 'value="Edit selected" />'; |
||
| 465 | } |
||
| 466 | $sReturn .= '</form>'; |
||
| 467 | } |
||
| 468 | if (isset($ftrs['actions']['checkbox_inlineEdit'])) { |
||
| 469 | $sReturn .= '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
||
| 470 | . '\',\'' . $checkboxName . '\',true);">Check All</a> ' |
||
| 471 | . '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
||
| 472 | . '\',\'' . $checkboxName . '\',false);">Uncheck All</a> '; |
||
| 473 | if (isset($ftrs['visibleInput'])) { |
||
| 474 | $sReturn .= $ftrs['visibleInput']; |
||
| 475 | } |
||
| 476 | $sReturn .= '<input type="hidden" name="view" value="save_' . $checkboxNameS . '" />'; |
||
| 477 | View Code Duplication | if (isset($ftrs['hiddenInput'])) { |
|
| 478 | if (is_array($ftrs['hiddenInput'])) { |
||
| 479 | foreach ($ftrs['hiddenInput'] as $valueF) { |
||
| 480 | $sReturn .= '<input type="hidden" name="' . $valueF |
||
| 481 | . '" value="' . $_REQUEST[$valueF] . '" />'; |
||
| 482 | } |
||
| 483 | } else { |
||
| 484 | $sReturn .= '<input type="hidden" name="' . $ftrs['hiddenInput'] |
||
| 485 | . '" value="' . $_REQUEST[$ftrs['hiddenInput']] . '" />'; |
||
| 486 | } |
||
| 487 | } |
||
| 488 | $sReturn .= '<input style="margin: 0 3em 0 3em;" type="submit" value="Store the modification" />'; |
||
| 489 | $sReturn .= '</form>'; |
||
| 490 | } |
||
| 491 | return $sReturn; |
||
| 492 | } |
||
| 493 | |||
| 494 | /** |
||
| 495 | * Set a control to a user-friendly calendar |
||
| 496 | * |
||
| 497 | * @param string $controlName |
||
| 498 | * @param string $additionalStyle |
||
| 499 | * @return string |
||
| 500 | */ |
||
| 501 | View Code Duplication | public function setCalendarControl($controlName, $additionalStyle = '') |
|
| 502 | { |
||
| 503 | return $this->setStringIntoTag(' ', 'span', [ |
||
| 504 | 'onclick' => implode('', [ |
||
| 505 | 'javascript:NewCssCal(\'' . $controlName, |
||
| 506 | '\',\'yyyyMMdd\',\'dropdown\',false,\'24\',false);', |
||
| 507 | ]), |
||
| 508 | 'class' => 'fa fa-calendar', |
||
| 509 | 'id' => $controlName . '_picker', |
||
| 510 | 'style' => 'cursor:pointer;' . $additionalStyle, |
||
| 511 | ]); |
||
| 512 | } |
||
| 513 | |||
| 514 | /** |
||
| 515 | * Set a control to a user-friendly calendar with time included |
||
| 516 | * |
||
| 517 | * @param string $controlName |
||
| 518 | * @param string $additionalStyle |
||
| 519 | * @return string |
||
| 520 | */ |
||
| 521 | View Code Duplication | public function setCalendarControlWithTime($controlName, $additionalStyle = '') |
|
| 522 | { |
||
| 523 | return $this->setStringIntoTag(' ', 'span', [ |
||
| 524 | 'onclick' => implode('', [ |
||
| 525 | 'javascript:NewCssCal(\'' . $controlName, |
||
| 526 | '\',\'yyyyMMdd\',\'dropdown\',true,\'24\',true);', |
||
| 527 | ]), |
||
| 528 | 'class' => 'fa fa-calendar', |
||
| 529 | 'id' => $controlName . '_picker', |
||
| 530 | 'style' => 'cursor:pointer;' . $additionalStyle, |
||
| 531 | ]); |
||
| 532 | } |
||
| 533 | |||
| 534 | private function setDynamicActionToSpecialCell($value, $aElements, $inP) |
||
| 535 | { |
||
| 536 | $aArgumemts = []; |
||
| 537 | $aArgumemts[] = $this->tCmnRequest->server->get('PHP_SELF') |
||
| 538 | . '?' . $inP['aPrefix'] . $inP['aKey'] . '=' . $value[0]; |
||
| 539 | $iActArgs = count($value[1]); |
||
| 540 | for ($counter = 0; $counter < $iActArgs; $counter++) { |
||
| 541 | $aArgumemts[] = $value[1][$counter] . '=' . $aElements[$inP['rCounter']][$value[1][$counter]]; |
||
| 542 | } |
||
| 543 | if (isset($inP['Features']['NoAjaxEditing'])) { |
||
| 544 | return '<a href="' . implode('&', $aArgumemts) . '"><i class="' . $inP['vIcon'] . '"> </i></a>'; |
||
| 545 | } |
||
| 546 | return '<a href="#" onclick="javascript:loadAE(\'' . implode('&', $aArgumemts) . '\');">' |
||
| 547 | . '<i class="' . $inP['vIcon'] . '"> </i></a>'; |
||
| 548 | } |
||
| 549 | |||
| 550 | /** |
||
| 551 | * Outputs an HTML footer |
||
| 552 | * |
||
| 553 | * @param array $footerInjected |
||
| 554 | * @return string |
||
| 555 | */ |
||
| 556 | protected function setFooterCommon($footerInjected = null) |
||
| 557 | { |
||
| 558 | if (isset($_REQUEST['specialHook']) && (in_array('noFooter', $_REQUEST['specialHook']))) { |
||
| 559 | return ''; |
||
| 560 | } |
||
| 561 | return $this->setFooterCommonInjected($footerInjected) . '</body></html>'; |
||
| 562 | } |
||
| 563 | |||
| 564 | protected function setFooterCommonInjected($footerInjected = null) |
||
| 575 | |||
| 576 | /** |
||
| 577 | * Outputs an HTML header |
||
| 578 | * |
||
| 579 | * @param array $headerFeatures |
||
| 580 | * @return string |
||
| 581 | */ |
||
| 582 | protected function setHeaderCommon($headerFeatures = null) |
||
| 650 | |||
| 651 | /** |
||
| 652 | * Generates a table cell |
||
| 653 | * |
||
| 654 | * @param array $aElements |
||
| 655 | * @param array $features |
||
| 656 | * @return string |
||
| 657 | */ |
||
| 658 | private function setTableCell($aElements, $features = null) |
||
| 659 | { |
||
| 660 | $sReturn = null; |
||
| 661 | foreach ($aElements as $key => $value) { |
||
| 662 | $value = str_replace(['& ', '\"', "\'"], ['& ', '"', "'"], $value); |
||
| 663 | if ((isset($features['grouping_cell'])) && ($features['grouping_cell'] == $key)) { |
||
| 664 | // just skip |
||
| 665 | } else { |
||
| 666 | $sReturn .= '<td '; |
||
| 667 | if (isset($features['column_formatting'][$key])) { |
||
| 668 | switch ($features['column_formatting'][$key]) { |
||
| 669 | case '@': |
||
| 670 | $sReturn .= 'style="text-align:left;">' . $value; |
||
| 671 | break; |
||
| 672 | case 'right': |
||
| 673 | $sReturn .= 'style="text-align:right;">' . $value; |
||
| 674 | break; |
||
| 675 | default: |
||
| 676 | $sReturn .= '???'; |
||
| 677 | break; |
||
| 678 | } |
||
| 679 | } else { |
||
| 680 | if (is_numeric($value)) { |
||
| 681 | $sReturn .= $this->setTableCellNumeric($key, $value, $features); |
||
| 682 | } else { |
||
| 683 | $outputet = false; |
||
| 684 | if ((strpos($value, '-') !== false) && (strlen($value) == 10)) { |
||
| 685 | if (preg_match("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $value, $regs)) { |
||
| 686 | $outputet = true; |
||
| 687 | $sReturn .= 'style="text-align:right;width: 10px;">' |
||
| 688 | . $regs[3] . '.' . $regs[2] . '.' . $regs[1]; |
||
| 689 | } |
||
| 690 | } |
||
| 691 | if (!$outputet) { |
||
| 692 | $sReturn .= 'style="text-align:left;">' . $value; |
||
| 693 | } |
||
| 694 | } |
||
| 695 | } |
||
| 696 | $sReturn .= '</td>'; |
||
| 697 | } |
||
| 698 | } |
||
| 699 | return $sReturn; |
||
| 700 | } |
||
| 701 | |||
| 702 | private function setTableCellDecimals($key, $features) |
||
| 713 | |||
| 714 | private function setTableCellNumeric($key, $value, $features) |
||
| 724 | |||
| 725 | /** |
||
| 726 | * Generates a table header |
||
| 727 | * |
||
| 728 | * @param array $aElements |
||
| 729 | * @param boolean $bHeadersBreaked |
||
| 730 | * @return string |
||
| 731 | */ |
||
| 732 | private function setTableHeader($aElements, $bHeadersBreaked) |
||
| 733 | { |
||
| 734 | $aTableHeader = $aElements; |
||
| 735 | if ($bHeadersBreaked) { |
||
| 736 | $aTableHeader = $this->setArrayToArrayKbr($aElements); |
||
| 737 | } |
||
| 738 | $sReturn[] = null; |
||
| 739 | foreach (array_keys($aTableHeader) as $value) { |
||
| 740 | $sReturn[] = $this->setStringIntoTag($value, 'th'); |
||
| 741 | } |
||
| 742 | return implode('', $sReturn); |
||
| 743 | } |
||
| 744 | |||
| 745 | /** |
||
| 746 | * Create an upper right box with choices for languages |
||
| 747 | * (requires flag-icon.min.css to be loaded) |
||
| 748 | * (makes usage of custom class "upperRightBox" and id = "visibleOnHover", provided here as scss file) |
||
| 749 | * |
||
| 750 | * @param array $aAvailableLanguages |
||
| 751 | * @return string |
||
| 752 | */ |
||
| 753 | protected function setUpperRightBoxLanguages($aAvailableLanguages) |
||
| 765 | |||
| 766 | private function setUpperRightVisibleOnHoverLanguages($aAvailableLanguages) |
||
| 783 | } |
||
| 784 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: