project_customer_csv.php 1.8 KB

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