project_csv.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. $field_names = [
  3. "Project ID", "Project Name",
  4. "Template Name",
  5. "Test ID", "Test Status", "Test Result",
  6. "Location Name", "Legal Entity", "Address", "Email", "Phone", "Region", "Internal ID", "Area Manager",
  7. "Tester Age", "Tester Gender", "Travel Costs",
  8. "Date", "Start Time", "End Time", "Duration",
  9. ];
  10. foreach($fields as $field) {
  11. $field_names[] = $field->label;
  12. }
  13. fputcsv($handle, $field_names);
  14. foreach($tests as $test) {
  15. $project = $test->getProject();
  16. $location = $test->getLocation();
  17. $tester = $test->getTester();
  18. $values = $test->getValues(true);
  19. $test_date = "";
  20. $test_start = "";
  21. $test_end = "";
  22. $test_duration = "";
  23. $result = "Pending";
  24. $age = "";
  25. $gender = "";
  26. $travel_costs = "";
  27. $output = [];
  28. $output[] = $project->id;
  29. $output[] = $project->name;
  30. $output[] = $template->name;
  31. $output[] = $test->id;
  32. $output[] = $test->getStatusText();
  33. if(!is_null($test->pass)) {
  34. $result = $test->pass ? "Pass" : "Fail";
  35. $test_start_dt = new DateTime($test->dts_start);
  36. $test_end_dt = new DateTime($test->dts_end);
  37. $test_duration_diff = $test_start_dt->diff($test_end_dt, true);
  38. $test_date = $test_start_dt->format("d/m/Y");
  39. $test_start = $test_start_dt->format("H:i:s");
  40. $test_end = $test_end_dt->format("H:i:s");
  41. $test_duration = $test_duration_diff->h . ":" . $test_duration_diff->i . ":" . $test_duration_diff->s;
  42. if($tester) {
  43. $tester_dob_dt = new DateTime($tester->date_of_birth);
  44. $dob_diff = $test_start_dt->diff($tester_dob_dt, true);
  45. $age = $dob_diff->y;
  46. $gender = $tester->gender;
  47. $travel_costs = $test->test_travel_costs;
  48. }
  49. }
  50. $output[] = $result;
  51. $output[] = $location->name;
  52. $output[] = $location->legal_entity_name;
  53. $output[] = $location->getDisplayAddress();
  54. $output[] = $location->email;
  55. $output[] = $location->phone;
  56. $output[] = $location->region;
  57. $output[] = $location->internal_id;
  58. $output[] = $location->area_manager;
  59. $output[] = $age;
  60. $output[] = $gender;
  61. $output[] = $travel_costs;
  62. $output[] = $test_date;
  63. $output[] = $test_start;
  64. $output[] = $test_end;
  65. $output[] = $test_duration;
  66. foreach($fields as $field) {
  67. $field_name = $field->name;
  68. $value = isset($test->$field_name) ? $test->$field_name : ($values[$field->name] ?? "");
  69. if(!empty($field->displayStrings)) {
  70. $index = array_search($value, $field->values);
  71. $value = $field->displayStrings[$index];
  72. }
  73. $output[] = $value;
  74. }
  75. fputcsv($handle, $output);
  76. }
  77. ?>