1
0

project_csv.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. $location = $test->getLocation();
  16. $tester = $test->getTester();
  17. $values = $test->getValues(true);
  18. $test_date = "";
  19. $test_start = "";
  20. $test_end = "";
  21. $test_duration = "";
  22. $result = "Pending";
  23. $age = "";
  24. $gender = "";
  25. $travel_costs = "";
  26. $output = [];
  27. $output[] = $id;
  28. $output[] = $project->name;
  29. $output[] = $template->name;
  30. $output[] = $test->id;
  31. $output[] = $test->getStatusText();
  32. if(!is_null($test->pass)) {
  33. $result = $test->pass ? "Pass" : "Fail";
  34. $test_start_dt = new DateTime($test->dts_start);
  35. $test_end_dt = new DateTime($test->dts_end);
  36. $test_duration_diff = $test_start_dt->diff($test_end_dt, true);
  37. $test_date = $test_start_dt->format("d/m/Y");
  38. $test_start = $test_start_dt->format("H:i:s");
  39. $test_end = $test_end_dt->format("H:i:s");
  40. $test_duration = $test_duration_diff->h . ":" . $test_duration_diff->i . ":" . $test_duration_diff->s;
  41. if($tester) {
  42. $tester_dob_dt = new DateTime($tester->date_of_birth);
  43. $dob_diff = $test_start_dt->diff($tester_dob_dt, true);
  44. $age = $dob_diff->y;
  45. $gender = $tester->gender;
  46. $travel_costs = $test->test_travel_costs;
  47. }
  48. }
  49. $output[] = $result;
  50. $output[] = $location->name;
  51. $output[] = $location->legal_entity_name;
  52. $output[] = $location->getDisplayAddress();
  53. $output[] = $location->email;
  54. $output[] = $location->phone;
  55. $output[] = $location->region;
  56. $output[] = $location->internal_id;
  57. $output[] = $location->area_manager;
  58. $output[] = $age;
  59. $output[] = $gender;
  60. $output[] = $travel_costs;
  61. $output[] = $test_date;
  62. $output[] = $test_start;
  63. $output[] = $test_end;
  64. $output[] = $test_duration;
  65. foreach($fields as $field) {
  66. $field_name = $field->name;
  67. $value = isset($test->$field_name) ? $test->$field_name : ($values[$field->name] ?? "");
  68. if(!empty($field->displayStrings)) {
  69. $index = array_search($value, $field->values);
  70. $value = $field->displayStrings[$index];
  71. }
  72. $output[] = $value;
  73. }
  74. fputcsv($handle, $output);
  75. }
  76. ?>