| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php /** @noinspection PhpUnhandledExceptionInspection */
- /**
- * @var Template $template
- * @var object[] $fields
- * @var resource $handle
- * @var Test[] $tests
- * @var Constraint $year_cycle_constraint
- */
- $config = $template->getConfiguration();
- $field_names = [
- "Test Result", "Test Void",
- "Location Name", "Address", "Brand", "Region", "Internal ID", "Area Manager",
- "Date",
- "All-Time Test Count", "Current Year Period Test Count"
- ];
- if($config->hasAlcohol ?? false) {
- array_splice($field_names, 2, 0, ["Gaming Void", "Alcohol Void"]);
- }
- foreach($fields as $field) {
- $customer_export = $field->customerExport ?? true;
- if(!$customer_export) {
- continue;
- }
- $field_names[] = $field->label;
- }
- fputcsv($handle, $field_names);
- foreach($tests as $test) {
- $project = $test->getProject();
- $location = $test->getLocation();
- $tester = $test->getTester();
- $values = $test->getValues(true);
- $total_test_count = count($location->getCompletedTests());
- $current_test_count = count($location->getCompletedTests(["dts_start" => $year_cycle_constraint]));
- $test_date = "";
- $test_start = "";
- $test_end = "";
- $test_duration = "";
- $result = "Pending";
- $age = "";
- $gender = "";
- $travel_costs = "";
- $output = [];
- if($test->pass !== null) {
- $result = $test->pass ? "Pass" : "Fail";
- $test_start_dt = new DateTime($test->dts_start);
- $test_end_dt = new DateTime($test->dts_end);
- $test_duration_diff = $test_start_dt->diff($test_end_dt, true);
- $test_date = $test_start_dt->format("d/m/Y");
- $test_start = $test_start_dt->format("H:i:s");
- $test_end = $test_end_dt->format("H:i:s");
- $test_duration = $test_duration_diff->h . ":" . $test_duration_diff->i . ":" . $test_duration_diff->s;
- if($tester) {
- $tester_dob_dt = new DateTime($tester->date_of_birth);
- $dob_diff = $test_start_dt->diff($tester_dob_dt, true);
- $age = $dob_diff->y;
- $gender = $tester->gender;
- $travel_costs = $test->test_travel_costs;
- }
- }
- if($test->isVoid()) {
- $gaming_void = "Y";
- $alcohol_void = "Y";
- }
- else {
- $gaming_void = $test->void_primary ? "Y" : "N";
- $alcohol_void = $test->void_secondary ? "Y" : "N";
- }
- $output[] = $result;
- $output[] = $test->isVoid() ? "Y" : "N";
- if($config->hasAlcohol ?? false) {
- $output[] = $gaming_void;
- $output[] = $alcohol_void;
- }
- $output[] = $location->name;
- $output[] = $location->getDisplayAddress();
- $output[] = $location->brand;
- $output[] = $location->region;
- $output[] = $location->internal_id;
- $output[] = $location->area_manager;
- $output[] = $test_date;
- $output[] = $total_test_count;
- $output[] = $current_test_count;
- foreach($fields as $field) {
- $customer_export = $field->customerExport ?? true;
- if(!$customer_export) continue;
- $field_name = $field->name;
- $value = $test->$field_name ?? ($values[$field->name] ?? "");
- if(!empty($field->displayStrings)) {
- $index = array_search($value, $field->values);
- $value = $field->displayStrings[$index];
- }
- $output[] = $value;
- }
- fputcsv($handle, $output);
- }
|