| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- // Controller may be included directly and $pdf can be accessed.
- $test = Test::get($id);
- if(!$test) throw new Exception("Test not found.");
- $project = $test->getProject();
- $template = $project->getTemplate();
- if(!isset($output)) $output = true;
- $location = $test->getLocation();
- $tester = $test->getTester();
- $test_values = $test->getValues();
- $keys = array_column($test_values, "name");
- $values = array_column($test_values, "value");
- $values = array_combine($keys, $values);
- $values = array_filter($values, function($value) {
- return strlen($value) !== 0;
- });
- $tiny_font_size = 8;
- $small_font_size = 10;
- $normal_font_size = 10;
- $header_font_size = 14;
- $cell_height = 5;
- $cell_margin = 2;
- list($date_start, $time_start) = explode(" ", $test->dts_start);
- list($date_end, $time_end) = explode(" ", $test->dts_end);
- $dt_start = new DateTime($test->dts_start . " UTC");
- $dt_start->setTimezone(new DateTimeZone(TIMEZONE));
- $dt_end = new DateTime($test->dts_end . " UTC");
- $dt_end->setTimezone(new DateTimeZone(TIMEZONE));
- $time_start = $dt_start->format("H:i:s");
- $time_end = $dt_end->format("H:i:s");
- $diff = $dt_start->diff($dt_end, true);
- $date_start = date("d/m/Y", strtotime($test->dts_start . " UTC"));
- $location_text = " $location->name";
- if($location->internal_id) {
- $location_text .= " (ID: $location->internal_id)";
- }
- $template_processing_file_path = $template->getProcessingFilePath("test_pdf.php");
- // A4 size: 210x297mm
- // Start PDF Building
- $pdf = new TestPDF("P", "mm", "A4");
- $pdf->SetSubject("Test Result");
- $pdf->SetCreator(APP_NAME);
- $pdf->SetAuthor(APP_NAME);
- $pdf->SetTitle($location->name . " Test Result @ $date_start");
- $pdf->AddPage();
- $pdf->SetFont("Arial");
- $pdf->SetDrawColor(240, 240, 240);
- $pdf->SetFillColor(226, 240, 217);
- $pdf->SetAutoPageBreak(false);
- // Logo
- $pdf->Image("public/img/logo.png", 11, 10, 60);
- // Right contact info
- $pdf->SetFont("Arial", "B", $tiny_font_size);
- $pdf->SetTextColor(255, 0, 0);
- $pdf->SetLeftMargin(120);
- $pdf->SetY(10);
- $pdf->Cell(80, 4, "Test / Location ID: $test->id / $location->id", 0, 1, "R");
- $pdf->SetFont("Arial", "");
- $pdf->SetTextColor(0, 0, 0);
- $pdf->Cell(80, 4, "Tel: 01579 342 104", 0, 1, "R", false, "tel:01579+342+104");
- $pdf->SetFont("Arial", "U");
- $pdf->SetTextColor(0, 128, 255);
- $pdf->Cell(80, 4, "check-policy.com", 0, 1, "R", false, "https://check-policy.com");
- $pdf->Cell(80, 4, "info@check-policy.com", 0, 1, "R");
- $pdf->SetLeftMargin(10);
- $pdf->SetXY(10, $pdf->GetY() + $cell_margin);
- require $template_processing_file_path;
- // Output
- if($output) {
- $pdf->Output();
- }
- ?>
|