| Conditions | 17 |
| Paths | 1260 |
| Total Lines | 256 |
| Code Lines | 183 |
| 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 |
||
| 443 | public function exportCompleteReportXLS( |
||
| 444 | $document_path = '', |
||
| 445 | $user_id = null, |
||
| 446 | $export_user_fields = false, |
||
| 447 | $export_filter = 0, |
||
| 448 | $exercise_id = 0, |
||
| 449 | $hotpotato_name = null |
||
| 450 | ) { |
||
| 451 | global $charset; |
||
| 452 | $this->getExercisesReporting( |
||
| 453 | $document_path, |
||
| 454 | $user_id, |
||
| 455 | $export_filter, |
||
| 456 | $exercise_id, |
||
| 457 | $hotpotato_name |
||
| 458 | ); |
||
| 459 | $now = api_get_local_time(); |
||
| 460 | $filename = 'exercise_results_'.$now.'.xlsx'; |
||
| 461 | if (!empty($user_id)) { |
||
| 462 | $filename = 'exercise_results_user_'.$user_id.'_'.$now.'.xlsx'; |
||
| 463 | } |
||
| 464 | |||
| 465 | $spreadsheet = new PHPExcel(); |
||
| 466 | $spreadsheet->setActiveSheetIndex(0); |
||
| 467 | $worksheet = $spreadsheet->getActiveSheet(); |
||
| 468 | |||
| 469 | $line = 1; // Skip first line |
||
| 470 | $column = 0; //skip the first column (row titles) |
||
| 471 | |||
| 472 | // check if exists column 'user' |
||
| 473 | $with_column_user = false; |
||
| 474 | foreach ($this->results as $result) { |
||
| 475 | if (!empty($result['last_name']) && !empty($result['first_name'])) { |
||
| 476 | $with_column_user = true; |
||
| 477 | break; |
||
| 478 | } |
||
| 479 | } |
||
| 480 | |||
| 481 | $officialCodeInList = api_get_setting('show_official_code_exercise_result_list'); |
||
| 482 | |||
| 483 | if ($with_column_user) { |
||
| 484 | if (api_is_western_name_order()) { |
||
| 485 | $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('FirstName')); |
||
| 486 | $column++; |
||
| 487 | $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('LastName')); |
||
| 488 | $column++; |
||
| 489 | } else { |
||
| 490 | $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('LastName')); |
||
| 491 | $column++; |
||
| 492 | $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('FirstName')); |
||
| 493 | $column++; |
||
| 494 | } |
||
| 495 | |||
| 496 | if ($officialCodeInList === 'true') { |
||
| 497 | $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('OfficialCode')); |
||
| 498 | $column++; |
||
| 499 | } |
||
| 500 | |||
| 501 | $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Email')); |
||
| 502 | $column++; |
||
| 503 | } |
||
| 504 | $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Groups')); |
||
| 505 | $column++; |
||
| 506 | |||
| 507 | if ($export_user_fields) { |
||
| 508 | //show user fields section with a big th colspan that spans over all fields |
||
| 509 | $extra_user_fields = UserManager::get_extra_fields( |
||
| 510 | 0, |
||
| 511 | 1000, |
||
| 512 | 5, |
||
| 513 | 'ASC', |
||
| 514 | false, |
||
| 515 | 1 |
||
| 516 | ); |
||
| 517 | |||
| 518 | //show the fields names for user fields |
||
| 519 | foreach ($extra_user_fields as $field) { |
||
| 520 | $worksheet->setCellValueByColumnAndRow( |
||
| 521 | $column, |
||
| 522 | $line, |
||
| 523 | api_html_entity_decode( |
||
| 524 | strip_tags($field[3]), |
||
| 525 | ENT_QUOTES, |
||
| 526 | $charset |
||
| 527 | ) |
||
| 528 | ); |
||
| 529 | $column++; |
||
| 530 | } |
||
| 531 | } |
||
| 532 | |||
| 533 | $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Title')); |
||
| 534 | $column++; |
||
| 535 | $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('StartDate')); |
||
| 536 | $column++; |
||
| 537 | $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('EndDate')); |
||
| 538 | $column++; |
||
| 539 | $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Duration').' ('.get_lang('MinMinutes').')'); |
||
| 540 | $column++; |
||
| 541 | $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Score')); |
||
| 542 | $column++; |
||
| 543 | $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Total')); |
||
| 544 | $column++; |
||
| 545 | $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Status')); |
||
| 546 | $column++; |
||
| 547 | $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('ToolLearnpath')); |
||
| 548 | $column++; |
||
| 549 | $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('UserIsCurrentlySubscribed')); |
||
| 550 | $line++; |
||
| 551 | |||
| 552 | foreach ($this->results as $row) { |
||
| 553 | $column = 0; |
||
| 554 | if ($with_column_user) { |
||
| 555 | if (api_is_western_name_order()) { |
||
| 556 | $worksheet->setCellValueByColumnAndRow( |
||
| 557 | $column, |
||
| 558 | $line, |
||
| 559 | api_html_entity_decode( |
||
| 560 | strip_tags($row['first_name']), |
||
| 561 | ENT_QUOTES, |
||
| 562 | $charset |
||
| 563 | ) |
||
| 564 | ); |
||
| 565 | $column++; |
||
| 566 | $worksheet->setCellValueByColumnAndRow( |
||
| 567 | $column, |
||
| 568 | $line, |
||
| 569 | api_html_entity_decode( |
||
| 570 | strip_tags($row['last_name']), |
||
| 571 | ENT_QUOTES, |
||
| 572 | $charset |
||
| 573 | ) |
||
| 574 | ); |
||
| 575 | $column++; |
||
| 576 | } else { |
||
| 577 | $worksheet->setCellValueByColumnAndRow( |
||
| 578 | $column, |
||
| 579 | $line, |
||
| 580 | api_html_entity_decode( |
||
| 581 | strip_tags($row['last_name']), |
||
| 582 | ENT_QUOTES, |
||
| 583 | $charset |
||
| 584 | ) |
||
| 585 | ); |
||
| 586 | $column++; |
||
| 587 | $worksheet->setCellValueByColumnAndRow( |
||
| 588 | $column, |
||
| 589 | $line, |
||
| 590 | api_html_entity_decode( |
||
| 591 | strip_tags($row['first_name']), |
||
| 592 | ENT_QUOTES, |
||
| 593 | $charset |
||
| 594 | ) |
||
| 595 | ); |
||
| 596 | $column++; |
||
| 597 | } |
||
| 598 | |||
| 599 | if ($officialCodeInList === 'true') { |
||
| 600 | $worksheet->setCellValueByColumnAndRow( |
||
| 601 | $column, |
||
| 602 | $line, |
||
| 603 | api_html_entity_decode( |
||
| 604 | strip_tags($row['official_code']), |
||
| 605 | ENT_QUOTES, |
||
| 606 | $charset |
||
| 607 | ) |
||
| 608 | ); |
||
| 609 | $column++; |
||
| 610 | } |
||
| 611 | |||
| 612 | $worksheet->setCellValueByColumnAndRow( |
||
| 613 | $column, |
||
| 614 | $line, |
||
| 615 | api_html_entity_decode( |
||
| 616 | strip_tags($row['email']), |
||
| 617 | ENT_QUOTES, |
||
| 618 | $charset |
||
| 619 | ) |
||
| 620 | ); |
||
| 621 | $column++; |
||
| 622 | } |
||
| 623 | |||
| 624 | $worksheet->setCellValueByColumnAndRow( |
||
| 625 | $column, |
||
| 626 | $line, |
||
| 627 | api_html_entity_decode( |
||
| 628 | strip_tags( |
||
| 629 | implode( |
||
| 630 | ", ", |
||
| 631 | GroupManager:: get_user_group_name($row['user_id']) |
||
| 632 | ) |
||
| 633 | ), |
||
| 634 | ENT_QUOTES, |
||
| 635 | $charset |
||
| 636 | ) |
||
| 637 | ); |
||
| 638 | $column++; |
||
| 639 | |||
| 640 | if ($export_user_fields) { |
||
| 641 | //show user fields data, if any, for this user |
||
| 642 | $user_fields_values = UserManager::get_extra_user_data( |
||
| 643 | $row['user_id'], |
||
| 644 | false, |
||
| 645 | false, |
||
| 646 | false, |
||
| 647 | true |
||
| 648 | ); |
||
| 649 | foreach ($user_fields_values as $value) { |
||
| 650 | $worksheet->setCellValueByColumnAndRow( |
||
| 651 | $column, |
||
| 652 | $line, |
||
| 653 | api_html_entity_decode( |
||
| 654 | strip_tags($value), |
||
| 655 | ENT_QUOTES, |
||
| 656 | $charset |
||
| 657 | ) |
||
| 658 | ); |
||
| 659 | $column++; |
||
| 660 | } |
||
| 661 | } |
||
| 662 | |||
| 663 | $worksheet->setCellValueByColumnAndRow( |
||
| 664 | $column, |
||
| 665 | $line, |
||
| 666 | api_html_entity_decode( |
||
| 667 | strip_tags($row['title']), |
||
| 668 | ENT_QUOTES, |
||
| 669 | $charset |
||
| 670 | ) |
||
| 671 | ); |
||
| 672 | |||
| 673 | $column++; |
||
| 674 | $worksheet->setCellValueByColumnAndRow($column, $line, $row['start_date']); |
||
| 675 | $column++; |
||
| 676 | $worksheet->setCellValueByColumnAndRow($column, $line, $row['end_date']); |
||
| 677 | $column++; |
||
| 678 | $duration = !empty($row['duration']) ? round($row['duration'] / 60) : 0; |
||
| 679 | $worksheet->setCellValueByColumnAndRow($column, $line, $duration); |
||
| 680 | $column++; |
||
| 681 | $worksheet->setCellValueByColumnAndRow($column, $line, $row['result']); |
||
| 682 | $column++; |
||
| 683 | $worksheet->setCellValueByColumnAndRow($column, $line, $row['max']); |
||
| 684 | $column++; |
||
| 685 | $worksheet->setCellValueByColumnAndRow($column, $line, $row['status']); |
||
| 686 | $column++; |
||
| 687 | $worksheet->setCellValueByColumnAndRow($column, $line, $row['lp_name']); |
||
| 688 | $column++; |
||
| 689 | $worksheet->setCellValueByColumnAndRow($column, $line, $row['is_user_subscribed']); |
||
| 690 | $line++; |
||
| 691 | } |
||
| 692 | |||
| 693 | $file = api_get_path(SYS_ARCHIVE_PATH).api_replace_dangerous_char($filename); |
||
| 694 | $writer = new PHPExcel_Writer_Excel2007($spreadsheet); |
||
| 695 | $writer->save($file); |
||
| 696 | DocumentManager::file_send_for_download($file, true, $filename); |
||
| 697 | |||
| 698 | return true; |
||
| 699 | } |
||
| 701 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.