project_customer_csv.php 1.8 KB

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