Issues (232)

app/Http/Controllers/PDFController.php (1 issue)

Severity
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Championship;
6
use App\Grade;
7
use Barryvdh\Snappy\Facades\SnappyPdf as PDF;
8
use Illuminate\Http\Request;
9
10
class PdfController extends Controller
11
{
12
    public function tree(Request $request)
13
    {
14
        $layout = 'pdf.preliminary_tree';
15
        // Get all data
16
        $championship = Championship::with('fightersGroups', 'settings', 'category')->find($request->championship);
17
        $grades = Grade::getAllPlucked();
0 ignored issues
show
The assignment to $grades is dead and can be removed.
Loading history...
18
        // Get Tree Type
19
        if ($championship->hasPreliminary()) {
20
            $layout = 'pdf.preliminary_tree';
21
        } else if ($championship->isSingleEliminationType()) {
22
            $layout = 'pdf.direct_elimination_tree';
23
        } else if ($championship->isPlayOffType()) {
24
            $layout = 'pdf.round_robin_tree';
25
        }
26
//        return view($layout, compact('championship'));
27
28
        // Generate PDF
29
        $file = 'tree-' . $championship->buildName();
30
        $file = sanitize($file) . '.pdf';
31
32
        $pdf = PDF::loadView($layout, ['championship' => $championship]);
33
        return $pdf->inline($file);
34
35
    }
36
37
38
    public function scoreSheets(Request $request)
39
    {
40
        $layout = 'pdf.scoresheets.sheet';
41
        // Get all data
42
        $championship = Championship::with('fightersGroups.championship.category',
43
            'settings',
44
            'category',
45
            'fightersGroups.championship.category', // TODO This is not good
46
            'fightersGroups.teams',
47
            'fightersGroups.competitors',
48
            'fightersGroups.fights.group.championship.category', // TODO This is not good
49
            'fightersGroups.fights.competitor1',
50
            'fightersGroups.fights.competitor2',
51
            'fightersGroups.fights.team1',
52
            'fightersGroups.fights.team2'
53
        )->find($request->championship);
54
55
56
        $tournament = $championship->tournament;
57
58
        // Generate PDF
59
        $file = 'scoreSheet-' . $championship->buildName();
60
        $file = sanitize($file) . '.pdf';
61
62
//                return view($layout, compact('championship','tournament'));
63
        $pdf = PDF::loadView($layout, ['championship' => $championship, 'tournament' => $tournament]);
64
        return $pdf->inline($file);
65
66
    }
67
68
}
69