project_csv.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. $field_names = [
  3. "Project ID", "Project Name",
  4. "Template Name",
  5. "Test ID", "Test Status",
  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. $age = "";
  23. $gender = "";
  24. $travel_costs = "";
  25. $output = [];
  26. $output[] = $id;
  27. $output[] = $project->name;
  28. $output[] = $template->name;
  29. $output[] = $test->id;
  30. $output[] = $test->getStatusText();
  31. if(!is_null($test->dts_end)) {
  32. $test_start_dt = new DateTime($test->dts_start);
  33. $test_end_dt = new DateTime($test->dts_end);
  34. $test_duration_diff = $test_start_dt->diff($test_end_dt, true);
  35. $test_date = $test_start_dt->format("d/m/Y");
  36. $test_start = $test_start_dt->format("H:i:s");
  37. $test_end = $test_end_dt->format("H:i:s");
  38. $test_duration = $test_duration_diff->h . ":" . $test_duration_diff->i . ":" . $test_duration_diff->s;
  39. if($tester) {
  40. $tester_dob_dt = new DateTime($tester->date_of_birth);
  41. $dob_diff = $test_start_dt->diff($tester_dob_dt, true);
  42. $age = $dob_diff->y;
  43. $gender = $tester->gender;
  44. $travel_costs = $test->test_travel_costs;
  45. }
  46. }
  47. $output[] = $location->name;
  48. $output[] = $location->legal_entity_name;
  49. $output[] = $location->getDisplayAddress();
  50. $output[] = $location->email;
  51. $output[] = $location->phone;
  52. $output[] = $location->region;
  53. $output[] = $location->internal_id;
  54. $output[] = $location->area_manager;
  55. $output[] = $age;
  56. $output[] = $gender;
  57. $output[] = $travel_costs;
  58. $output[] = $test_date;
  59. $output[] = $test_start;
  60. $output[] = $test_end;
  61. $output[] = $test_duration;
  62. foreach($fields as $field) {
  63. $field_name = $field->name;
  64. $value = isset($test->$field_name) ? $test->$field_name : ($values[$field->name] ?? "");
  65. if(!empty($field->displayStrings)) {
  66. $index = array_search($value, $field->values);
  67. $value = $field->displayStrings[$index];
  68. }
  69. $output[] = $value;
  70. }
  71. fputcsv($handle, $output);
  72. }