|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace CodeDay\Http\Controllers\Vip; |
| 4 | + |
| 5 | +use CodeDay\Http\Controllers; |
| 6 | +use CodeDay\Models; |
| 7 | +use Carbon\Carbon; |
| 8 | +define('FPDF_FONTPATH', base_path().'/resources/fonts'); |
| 9 | + |
| 10 | +class CertificateController extends Controllers\Controller |
| 11 | +{ |
| 12 | + public function getIndex() |
| 13 | + { |
| 14 | + $ticket = Models\Ticket::find(\Route::input('ticket')); |
| 15 | + // TODO(@tylermenezes): We should check if they've checked in, however Clear clears checkin time upon checkout. |
| 16 | + $ends_at = new Carbon($ticket->event['batch']['ends_at']); |
| 17 | + //if ($ends_at->gte(Carbon::now())) \App::abort(404); |
| 18 | + |
| 19 | + |
| 20 | + $pdf = new \FPDI('L', 'mm', 'Letter'); |
| 21 | + $pdf->AddPage(); |
| 22 | + $pdf->setSourceFile(base_path().'/resources/pdf/certificate.pdf'); |
| 23 | + $tplIdx = $pdf->importPage(1); |
| 24 | + $pdf->useTemplate($tplIdx, 0, -1, 278); |
| 25 | + |
| 26 | + // now write some text above the imported page |
| 27 | + $pdf->AddFont('Avenir Next', 'B', 'hinted-AvenirNext-Bold.php'); |
| 28 | + $pdf->SetFont('Avenir Next', 'B'); |
| 29 | + $pdf->SetTextColor(31, 29, 30); |
| 30 | + |
| 31 | + $eventName = $ticket->event['region_name'].' '.$ticket->event['batch']['name']; |
| 32 | + $pdf->SetFontSize(16); |
| 33 | + $width = $pdf->GetStringWidth($eventName); |
| 34 | + $pdf->text(250-$width, 35, $eventName); |
| 35 | + |
| 36 | + $certificateName = $ticket->name; |
| 37 | + $pdf->SetFontSize(52); |
| 38 | + $pdf->Text(34, 105, $certificateName); |
| 39 | + |
| 40 | + $filename = 'certificate-of-completion.pdf'; |
| 41 | + |
| 42 | + $bin = $pdf->Output($filename, 'S'); |
| 43 | + return response($bin) |
| 44 | + ->header('Content-type', 'application/pdf') |
| 45 | + ->header('Content-Disposition', 'inline; filename="'.$filename.'"'); |
| 46 | + } |
| 47 | +} |
0 commit comments