1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: caspa |
5
|
|
|
* Date: 31.05.2018 |
6
|
|
|
* Time: 12:11. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace App\Http\Controllers; |
10
|
|
|
|
11
|
|
|
use DB; |
12
|
|
|
use File; |
13
|
|
|
use Illuminate\Http\Request; |
14
|
|
|
use jeremykenedy\Uuid\Uuid; |
15
|
|
|
use PDF; |
16
|
|
|
use QrCode; |
17
|
|
|
|
18
|
|
|
class GenerateController extends Controller |
19
|
|
|
{ |
20
|
|
|
public function showGenerate() |
21
|
|
|
{ |
22
|
|
|
return view('leader.generate'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function index(Request $request) |
26
|
|
|
{ |
27
|
|
|
$this->preCleanup(); |
28
|
|
|
|
29
|
|
|
$countQR = CodeCount::setCodeCount($request['countQR']); |
30
|
|
|
|
31
|
|
|
for ($i = 0; $i < $countQR; $i++) { |
32
|
|
|
$code = $this->generateCodes(); |
33
|
|
|
|
34
|
|
|
$this->generateQR($code, $i); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
if ($countQR > 0) { |
38
|
|
|
$this->generatePDF($countQR); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return back(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
private function preCleanup() |
45
|
|
|
{ |
46
|
|
|
DB::table('game_codes')->delete(); |
47
|
|
|
DB::table('users_codes')->delete(); |
48
|
|
|
DB::table('game_admin')->delete(); |
49
|
|
|
|
50
|
|
|
DB::update('UPDATE users SET rank = NULL;'); |
51
|
|
|
DB::update('UPDATE users SET total_points = NULL;'); |
52
|
|
|
DB::update('UPDATE users SET start = NULL;'); |
53
|
|
|
DB::update('UPDATE users SET end = NULL;'); |
54
|
|
|
|
55
|
|
|
File::delete(File::glob(storage_path().'/pdf/codes/..png')); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
private function generateCodes() |
59
|
|
|
{ |
60
|
|
|
$code = uuid::generate(4); |
61
|
|
|
|
62
|
|
|
DB::table('game_codes')->insert(['game_code' => $code]); |
63
|
|
|
|
64
|
|
|
return $code; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
private function generateQR($code, $QRNumber) |
68
|
|
|
{ |
69
|
|
|
QrCode::format('png')->size(200)->generate(url('/').'/user/qr/scan/'.$code, storage_path().'/pdf/codes/'.$QRNumber.'.png'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
private function generatePDF($fileCount) |
73
|
|
|
{ |
74
|
|
|
PDF::SetTitle(config('app.name')); |
75
|
|
|
PDF::SetFont('Arial', 'B', 18); |
76
|
|
|
PDF::SetMargins(10, 10, 10); |
77
|
|
|
PDF::SetCreator(config('app.name')); |
78
|
|
|
PDF::SetAuthor(config('app.name')); |
79
|
|
|
|
80
|
|
|
for ($i = 0; $i < $fileCount; $i++) { |
81
|
|
|
$j = $i; |
82
|
|
|
if ($fileCount - $i == 1) { |
83
|
|
|
PDF::AddPage(); |
84
|
|
|
PDF::Cell(0, 15, config('app.name').' - QR Nr. '.++$j, 0, 1, 'C'); |
85
|
|
|
PDF::SetY(20); |
86
|
|
|
PDF::SetX(80); |
87
|
|
|
PDF::Image(storage_path().'/pdf/codes/'.$i.'.png'); |
88
|
|
|
PDF::SetY(70); |
89
|
|
|
PDF::SetX(20); |
90
|
|
|
PDF::Image(storage_path().'/pdf/logo.png'); |
91
|
|
|
} else { |
92
|
|
|
PDF::AddPage(); |
93
|
|
|
PDF::Cell(0, 15, config('app.name').' - QR Nr. '.++$j, 0, 1, 'C'); |
94
|
|
|
PDF::SetY(20); |
95
|
|
|
PDF::SetX(80); |
96
|
|
|
PDF::Image(storage_path().'/pdf/codes/'.$i.'.png'); |
97
|
|
|
PDF::SetY(70); |
98
|
|
|
PDF::SetX(20); |
99
|
|
|
PDF::Image(storage_path().'/pdf/logo.png'); |
100
|
|
|
|
101
|
|
|
PDF::SetY(130); |
102
|
|
|
PDF::SetX(0); |
103
|
|
|
PDF::SetMargins(0, 10, 0); |
104
|
|
|
PDF::Cell(0, 0, '', 1, 1); |
105
|
|
|
PDF::SetY(150); |
106
|
|
|
|
107
|
|
|
PDF::AddPage(); |
108
|
|
|
PDF::Cell(0, 15, config('app.name').' - QR Nr. '.++$j, 0, 1, 'C'); |
109
|
|
|
PDF::SetY(160); |
110
|
|
|
PDF::SetX(80); |
111
|
|
|
PDF::Image(storage_path().'/pdf/codes/'.$i.'.png'); |
112
|
|
|
PDF::SetY(210); |
113
|
|
|
PDF::SetX(20); |
114
|
|
|
PDF::Image(storage_path().'/pdf/logo.png'); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
PDF::Output(storage_path().'/pdf/file/QR-Codes.pdf', 'F'); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|