project_customer_csv.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. $field_names = [
  3. "Test Result",
  4. "Location Name", "Address", "Region", "Internal ID", "Area Manager",
  5. "Date",
  6. ];
  7. foreach($fields as $field) {
  8. $customer_export = $field->customerExport ?? true;
  9. if(!$customer_export) continue;
  10. $field_names[] = $field->label;
  11. }
  12. fputcsv($handle, $field_names);
  13. foreach($tests as $test) {
  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. $result = "Pending";
  22. $age = "";
  23. $gender = "";
  24. $travel_costs = "";
  25. $output = [];
  26. if(!is_null($test->pass)) {
  27. $result = $test->pass ? "Pass" : "Fail";
  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[] = $result;
  44. $output[] = $location->name;
  45. $output[] = $location->getDisplayAddress();
  46. $output[] = $location->region;
  47. $output[] = $location->internal_id;
  48. $output[] = $location->area_manager;
  49. $output[] = $test_date;
  50. foreach($fields as $field) {
  51. $customer_export = $field->customerExport ?? true;
  52. if(!$customer_export) continue;
  53. $field_name = $field->name;
  54. $value = isset($test->$field_name) ? $test->$field_name : ($values[$field->name] ?? "");
  55. if(!empty($field->displayStrings)) {
  56. $index = array_search($value, $field->values);
  57. $value = $field->displayStrings[$index];
  58. }
  59. $output[] = $value;
  60. }
  61. fputcsv($handle, $output);
  62. }
  63. ?>