| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- $field_names = [
- "Test Result", "Test Void",
- "Location Name", "Address", "Region", "Internal ID", "Area Manager",
- "Date",
- ];
- 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);
- $test_date = "";
- $test_start = "";
- $test_end = "";
- $test_duration = "";
- $result = "Pending";
- $age = "";
- $gender = "";
- $travel_costs = "";
- $output = [];
- 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[] = $test->isVoid() ? "Y" : "N";
- $output[] = $location->name;
- $output[] = $location->getDisplayAddress();
- $output[] = $location->region;
- $output[] = $location->internal_id;
- $output[] = $location->area_manager;
- $output[] = $test_date;
- foreach($fields as $field) {
- $customer_export = $field->customerExport ?? true;
- if(!$customer_export) continue;
- $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);
- }
- ?>
|