project_customer_csv.php 1.9 KB

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