Skip to content
This repository was archived by the owner on Jun 9, 2020. It is now read-only.

Commit f84c7a0

Browse files
committed
Add certificate
1 parent a86cb75 commit f84c7a0

File tree

8 files changed

+473
-235
lines changed

8 files changed

+473
-235
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
}

app/Http/routes.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828

2929
$routes = function () {
3030
// Domain Routes
31-
\Route::group(['domain' => isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] == 'vip.codeday.dev' ? 'vip.codeday.dev' : 'codeday.vip'], function () {
31+
\Route::group(['domain' => isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] == 'vip.x' ? 'vip.x' : 'codeday.vip'], function () {
3232
\Route::Controller('/{ticket}/ticket', '\CodeDay\Http\Controllers\Vip\TicketController');
33+
\Route::Controller('/{ticket}/certificate', '\CodeDay\Http\Controllers\Vip\CertificateController');
3334
\Route::Controller('/{ticket}', '\CodeDay\Http\Controllers\Vip\IndexController');
3435
\Route::get('/', '\CodeDay\Http\Controllers\Vip\IndexController@getFind');
3536
\Route::post('/', '\CodeDay\Http\Controllers\Vip\IndexController@postFind');

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
"php": ">=5.5.9",
99
"laravel/framework": "5.2.*",
1010
"rcrowe/twigbridge": "0.9.1",
11+
"twig/twig": "1.30.0",
1112
"abraham/twitteroauth": "^0.7.2",
12-
"predis/predis": "^1.1"
13+
"predis/predis": "^1.1",
14+
"setasign/fpdi": "1.6.1",
15+
"setasign/fpdi-fpdf": "1.6.1"
1316
},
1417
"require-dev": {
1518
"fzaninotto/faker": "~1.4",

0 commit comments

Comments
 (0)