1
0

project_csv.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. /**
  3. * @var resource $handle
  4. * @var object[] $fields
  5. * @var Test[] $tests
  6. * @var Template $template
  7. */
  8. $config = $template->getConfiguration();
  9. $customer = $template->getCustomer();
  10. $brand_label = $customer->getBrandLabel(1);
  11. $region_label = $customer->getRegionLabel(1);
  12. $area_manager_label = $customer->getAreaManagerLabel(1);
  13. $field_names = [
  14. "Project ID", "Project Name",
  15. "Template Name",
  16. "Test ID", "Test Status", "Test Void", "Gaming Void", "Alcohol Void", "Test Result",
  17. "Location Name", "Legal Entity", "Address", "Email", "Phone", $brand_label, $region_label, "Internal ID", $area_manager_label,
  18. "Tester Age", "Tester Gender", "Travel Costs",
  19. "Date", "Start Time", "End Time", "Duration",
  20. ];
  21. if($config->hasAlcohol ?? false) {
  22. array_splice($field_names, 6, 0, ["Gaming Void", "Alcohol Void"]);
  23. }
  24. foreach($fields as $field) {
  25. $field_names[] = $field->label;
  26. }
  27. fputcsv($handle, $field_names);
  28. foreach($tests as $test) {
  29. $project = $test->getProject();
  30. $location = $test->getLocation();
  31. $tester = $test->getTester();
  32. $values = $test->getValues(true);
  33. $test_date = "";
  34. $test_start = "";
  35. $test_end = "";
  36. $test_duration = "";
  37. $result = "Pending";
  38. $age = "";
  39. $gender = "";
  40. $travel_costs = "";
  41. if($test->isVoid()) {
  42. $gaming_void = "Y";
  43. $alcohol_void = "Y";
  44. }
  45. else {
  46. $gaming_void = $test->void_primary ? "Y" : "N";
  47. $alcohol_void = $test->void_secondary ? "Y" : "N";
  48. }
  49. $output = [];
  50. $output[] = $project->id;
  51. $output[] = $project->name;
  52. $output[] = $template->name;
  53. $output[] = $test->id;
  54. $output[] = $test->getStatusText();
  55. $output[] = $test->isVoid() ? "Y" : "N";
  56. if($config->hasAlcohol ?? false) {
  57. $output[] = $gaming_void;
  58. $output[] = $alcohol_void;
  59. }
  60. if(!is_null($test->pass)) {
  61. $result = $test->pass ? "Pass" : "Fail";
  62. $test_start_dt = new DateTime($test->dts_start);
  63. $test_end_dt = new DateTime($test->dts_end);
  64. $test_duration_diff = $test_start_dt->diff($test_end_dt, true);
  65. $test_date = $test_start_dt->format("d/m/Y");
  66. $test_start = $test_start_dt->format("H:i:s");
  67. $test_end = $test_end_dt->format("H:i:s");
  68. $test_duration = $test_duration_diff->h . ":" . $test_duration_diff->i . ":" . $test_duration_diff->s;
  69. if($tester) {
  70. $tester_dob_dt = new DateTime($tester->date_of_birth);
  71. $dob_diff = $test_start_dt->diff($tester_dob_dt, true);
  72. $age = $dob_diff->y;
  73. $gender = $tester->gender;
  74. $travel_costs = $test->test_travel_costs;
  75. }
  76. }
  77. $output[] = $result;
  78. $output[] = $location->name;
  79. $output[] = $location->legal_entity_name;
  80. $output[] = $location->getDisplayAddress();
  81. $output[] = $location->email;
  82. $output[] = $location->phone;
  83. $output[] = $location->brand;
  84. $output[] = $location->region;
  85. $output[] = $location->internal_id;
  86. $output[] = $location->area_manager;
  87. $output[] = $age;
  88. $output[] = $gender;
  89. $output[] = $travel_costs;
  90. $output[] = $test_date;
  91. $output[] = $test_start;
  92. $output[] = $test_end;
  93. $output[] = $test_duration;
  94. foreach($fields as $field) {
  95. $field_name = $field->name;
  96. $value = isset($test->$field_name) ? $test->$field_name : ($values[$field->name] ?? "");
  97. if(!empty($field->displayStrings)) {
  98. $index = array_search($value, $field->values);
  99. $value = $field->displayStrings[$index];
  100. }
  101. $output[] = $value;
  102. }
  103. fputcsv($handle, $output);
  104. }