1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Jobs; |
4
|
|
|
|
5
|
|
|
use Illuminate\Bus\Queueable; |
6
|
|
|
use Illuminate\Queue\SerializesModels; |
7
|
|
|
use Illuminate\Queue\InteractsWithQueue; |
8
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
9
|
|
|
use Illuminate\Foundation\Bus\Dispatchable; |
10
|
|
|
use App\Models\Eloquent\ContestModel as EloquentContestModel; |
11
|
|
|
use Imtigger\LaravelJobStatus\Trackable; |
12
|
|
|
use PDF; |
13
|
|
|
|
14
|
|
|
class GeneratePDF implements ShouldQueue |
15
|
|
|
{ |
16
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, Trackable; |
|
|
|
|
17
|
|
|
|
18
|
|
|
public $tries = 5; |
19
|
|
|
protected $cid; |
20
|
|
|
protected $config; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Create a new job instance. |
24
|
|
|
* |
25
|
|
|
* @return void |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
public function __construct($cid, $config) |
29
|
|
|
{ |
30
|
|
|
$this->prepareStatus(); |
31
|
|
|
$this->cid=$cid; |
32
|
|
|
$default=[ |
33
|
|
|
'cover'=>false, |
34
|
|
|
'advice'=>false, |
35
|
|
|
]; |
36
|
|
|
$this->config=array_merge($default,$config); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Execute the job. |
41
|
|
|
* |
42
|
|
|
* @return void |
43
|
|
|
*/ |
44
|
|
|
public function handle() |
45
|
|
|
{ |
46
|
|
|
$cid=$this->cid; |
47
|
|
|
$config=$this->config; |
48
|
|
|
|
49
|
|
|
if (!is_dir(storage_path("app/contest/pdf/"))){ |
50
|
|
|
mkdir(storage_path("app/contest/pdf/"), 0777, true); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$record=EloquentContestModel::find($cid); |
54
|
|
|
// dd(EloquentContestModel::getProblemSet($cid)); |
55
|
|
|
|
56
|
|
|
$pdf=PDF::setOptions([ |
57
|
|
|
'dpi' => 150, |
58
|
|
|
'isPhpEnabled' => true, |
59
|
|
|
'isHtml5ParserEnabled' => true, |
60
|
|
|
'isRemoteEnabled' => true |
61
|
|
|
])->setWarnings(true)->loadView('pdf.contest.main', [ |
62
|
|
|
'conf'=>$config, |
63
|
|
|
'contest' => [ |
64
|
|
|
'cid'=>$cid, |
65
|
|
|
'name'=>$record->name, |
66
|
|
|
'shortName'=>$record->name, |
67
|
|
|
'date'=>date("F j, Y", strtotime($record->begin_time)), |
68
|
|
|
], |
69
|
|
|
'problemset'=>EloquentContestModel::getProblemSet($cid, true), |
70
|
|
|
]); |
71
|
|
|
// $pdf->getDomPDF()->add_info('Subject', "$record->name ProblemSet"); |
72
|
|
|
// $pdf->getDomPDF()->add_info('Producer', config('app.displayName')); |
73
|
|
|
// $pdf->getDomPDF()->add_info('Creator', config('app.name').' Contest PDF Auto-Generater'); |
74
|
|
|
// $pdf->getDomPDF()->add_info('CreatorTool', config('app.url')); |
75
|
|
|
// $pdf->getDomPDF()->add_info('BaseURL', route('contest.detail',['cid'=>$cid])); |
76
|
|
|
$pdf->save(storage_path("app/contest/pdf/$cid.pdf")); |
77
|
|
|
|
78
|
|
|
$record->pdf=1; |
79
|
|
|
$record->save(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function failed() |
83
|
|
|
{ |
84
|
|
|
|
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|