| Conditions | 23 |
| Paths | > 20000 |
| Total Lines | 169 |
| Code Lines | 110 |
| 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 |
||
| 340 | public function get_table_data( |
||
| 341 | $from = 1, |
||
| 342 | $per_page = null, |
||
| 343 | $column = null, |
||
| 344 | $direction = null, |
||
| 345 | $sort = null |
||
| 346 | ) { |
||
| 347 | $is_western_name_order = api_is_western_name_order(); |
||
| 348 | |||
| 349 | // create page navigation if needed |
||
| 350 | $totalitems = $this->datagen->get_total_items_count(); |
||
| 351 | |||
| 352 | if ($this->limit_enabled && $totalitems > GRADEBOOK_ITEM_LIMIT) { |
||
| 353 | $selectlimit = GRADEBOOK_ITEM_LIMIT; |
||
| 354 | } else { |
||
| 355 | $selectlimit = $totalitems; |
||
| 356 | } |
||
| 357 | |||
| 358 | $header = null; |
||
| 359 | if ($this->limit_enabled && $totalitems > GRADEBOOK_ITEM_LIMIT) { |
||
| 360 | $header .= '<table style="width: 100%; text-align: right; margin-left: auto; margin-right: auto;" border="0" cellpadding="2">' |
||
| 361 | .'<tbody>' |
||
| 362 | .'<tr>'; |
||
| 363 | |||
| 364 | // previous X |
||
| 365 | $header .= '<td style="width:100%;">'; |
||
| 366 | if ($this->offset >= GRADEBOOK_ITEM_LIMIT) { |
||
| 367 | $header .= '<a href="'.api_get_self() |
||
| 368 | .'?selectcat='.Security::remove_XSS($_GET['selectcat']) |
||
| 369 | .'&offset='.(($this->offset) - GRADEBOOK_ITEM_LIMIT) |
||
| 370 | .(isset($_GET['search']) ? '&search='.Security::remove_XSS($_GET['search']) : '').'">' |
||
| 371 | .Display::return_icon( |
||
| 372 | 'action_prev.png', |
||
| 373 | get_lang('PreviousPage'), |
||
| 374 | [], |
||
| 375 | ICON_SIZE_MEDIUM |
||
| 376 | ) |
||
| 377 | .'</a>'; |
||
| 378 | } else { |
||
| 379 | $header .= Display::return_icon( |
||
| 380 | 'action_prev_na.png', |
||
| 381 | get_lang('PreviousPage'), |
||
| 382 | [], |
||
| 383 | ICON_SIZE_MEDIUM |
||
| 384 | ); |
||
| 385 | } |
||
| 386 | $header .= ' '; |
||
| 387 | // next X |
||
| 388 | $calcnext = (($this->offset + (2 * GRADEBOOK_ITEM_LIMIT)) > $totalitems) ? |
||
| 389 | ($totalitems - (GRADEBOOK_ITEM_LIMIT + $this->offset)) : GRADEBOOK_ITEM_LIMIT; |
||
| 390 | |||
| 391 | if ($calcnext > 0) { |
||
| 392 | $header .= '<a href="'.api_get_self() |
||
| 393 | .'?selectcat='.Security::remove_XSS($_GET['selectcat']) |
||
| 394 | .'&offset='.($this->offset + GRADEBOOK_ITEM_LIMIT) |
||
| 395 | .(isset($_GET['search']) ? '&search='.Security::remove_XSS($_GET['search']) : '').'">' |
||
| 396 | .Display::return_icon('action_next.png', get_lang('NextPage'), [], ICON_SIZE_MEDIUM) |
||
| 397 | .'</a>'; |
||
| 398 | } else { |
||
| 399 | $header .= Display::return_icon( |
||
| 400 | 'action_next_na.png', |
||
| 401 | get_lang('NextPage'), |
||
| 402 | [], |
||
| 403 | ICON_SIZE_MEDIUM |
||
| 404 | ); |
||
| 405 | } |
||
| 406 | $header .= '</td>'; |
||
| 407 | $header .= '</tbody></table>'; |
||
| 408 | echo $header; |
||
| 409 | } |
||
| 410 | |||
| 411 | // retrieve sorting type |
||
| 412 | if ($is_western_name_order) { |
||
| 413 | $users_sorting = ($this->column == 0 ? FlatViewDataGenerator::FVDG_SORT_FIRSTNAME : FlatViewDataGenerator::FVDG_SORT_LASTNAME); |
||
| 414 | } else { |
||
| 415 | $users_sorting = ($this->column == 0 ? FlatViewDataGenerator::FVDG_SORT_LASTNAME : FlatViewDataGenerator::FVDG_SORT_FIRSTNAME); |
||
| 416 | } |
||
| 417 | |||
| 418 | if ($this->direction == 'DESC') { |
||
| 419 | $users_sorting |= FlatViewDataGenerator::FVDG_SORT_DESC; |
||
| 420 | } else { |
||
| 421 | $users_sorting |= FlatViewDataGenerator::FVDG_SORT_ASC; |
||
| 422 | } |
||
| 423 | |||
| 424 | // step 1: generate columns: evaluations and links |
||
| 425 | $header_names = $this->datagen->get_header_names($this->offset, $selectlimit); |
||
| 426 | $userRowSpan = false; |
||
| 427 | foreach ($header_names as $item) { |
||
| 428 | if (is_array($item)) { |
||
| 429 | $userRowSpan = true; |
||
| 430 | break; |
||
| 431 | } |
||
| 432 | } |
||
| 433 | |||
| 434 | $thAttributes = ''; |
||
| 435 | if ($userRowSpan) { |
||
| 436 | $thAttributes = 'rowspan=2'; |
||
| 437 | } |
||
| 438 | |||
| 439 | $this->set_header(0, $header_names[0], true, $thAttributes); |
||
| 440 | $this->set_header(1, $header_names[1], true, $thAttributes); |
||
| 441 | |||
| 442 | $column = 2; |
||
| 443 | $firstHeader = []; |
||
| 444 | while ($column < count($header_names)) { |
||
| 445 | $headerData = $header_names[$column]; |
||
| 446 | |||
| 447 | if (is_array($headerData)) { |
||
| 448 | $countItems = count($headerData['items']); |
||
| 449 | |||
| 450 | $this->set_header( |
||
| 451 | $column, |
||
| 452 | $headerData['header'], |
||
| 453 | false, |
||
| 454 | 'colspan="'.$countItems.'"' |
||
| 455 | ); |
||
| 456 | |||
| 457 | foreach ($headerData['items'] as $item) { |
||
| 458 | $firstHeader[] = '<center>'.$item.'</center>'; |
||
| 459 | } |
||
| 460 | } else { |
||
| 461 | $this->set_header($column, $headerData, false, $thAttributes); |
||
| 462 | } |
||
| 463 | $column++; |
||
| 464 | } |
||
| 465 | |||
| 466 | $data_array = $this->datagen->get_data( |
||
| 467 | $users_sorting, |
||
| 468 | $from, |
||
| 469 | $this->per_page, |
||
| 470 | $this->offset, |
||
| 471 | $selectlimit |
||
| 472 | ); |
||
| 473 | |||
| 474 | $table_data = []; |
||
| 475 | |||
| 476 | if (!empty($firstHeader)) { |
||
| 477 | $table_data[] = $firstHeader; |
||
| 478 | } |
||
| 479 | |||
| 480 | foreach ($data_array as $user_row) { |
||
| 481 | $user_id = $user_row[0]; |
||
| 482 | unset($user_row[0]); |
||
| 483 | $userInfo = api_get_user_info($user_id); |
||
| 484 | if ($is_western_name_order) { |
||
| 485 | $user_row[1] = $this->build_name_link( |
||
| 486 | $user_id, |
||
| 487 | $userInfo['firstname'] |
||
| 488 | ); |
||
| 489 | $user_row[2] = $this->build_name_link( |
||
| 490 | $user_id, |
||
| 491 | $userInfo['lastname'] |
||
| 492 | ); |
||
| 493 | } else { |
||
| 494 | $user_row[1] = $this->build_name_link( |
||
| 495 | $user_id, |
||
| 496 | $userInfo['lastname'] |
||
| 497 | ); |
||
| 498 | $user_row[2] = $this->build_name_link( |
||
| 499 | $user_id, |
||
| 500 | $userInfo['firstname'] |
||
| 501 | ); |
||
| 502 | } |
||
| 503 | $user_row = array_values($user_row); |
||
| 504 | |||
| 505 | $table_data[] = $user_row; |
||
| 506 | } |
||
| 507 | |||
| 508 | return $table_data; |
||
| 509 | } |
||
| 522 |