getConfiguration(); $customer = $template->getCustomer(); $brand_label = $customer->getBrandLabel(1); $region_label = $customer->getRegionLabel(1); $area_manager_label = $customer->getAreaManagerLabel(1); $field_names = [ "Project ID", "Project Name", "Template Name", "Test ID", "Test Status", "Test Void", "Gaming Void", "Alcohol Void", "Test Result", "Location Name", "Legal Entity", "Address", "Email", "Phone", $brand_label, $region_label, "Internal ID", $area_manager_label, "Tester Age", "Tester Gender", "Travel Costs", "Date", "Start Time", "End Time", "Duration", ]; if($config->hasAlcohol ?? false) { array_splice($field_names, 6, 0, ["Gaming Void", "Alcohol Void"]); } foreach($fields as $field) { $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); $test_date = ""; $test_start = ""; $test_end = ""; $test_duration = ""; $result = "Pending"; $age = ""; $gender = ""; $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 = []; $output[] = $project->id; $output[] = $project->name; $output[] = $template->name; $output[] = $test->id; $output[] = $test->getStatusText(); $output[] = $test->isVoid() ? "Y" : "N"; if($config->hasAlcohol ?? false) { $output[] = $gaming_void; $output[] = $alcohol_void; } if(!is_null($test->pass)) { $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; } } $output[] = $result; $output[] = $location->name; $output[] = $location->legal_entity_name; $output[] = $location->getDisplayAddress(); $output[] = $location->email; $output[] = $location->phone; $output[] = $location->brand; $output[] = $location->region; $output[] = $location->internal_id; $output[] = $location->area_manager; $output[] = $age; $output[] = $gender; $output[] = $travel_costs; $output[] = $test_date; $output[] = $test_start; $output[] = $test_end; $output[] = $test_duration; foreach($fields as $field) { $field_name = $field->name; $value = isset($test->$field_name) ? $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); }