Passed
Push — main ( cce870...daa135 )
by Thierry
06:24
created

PrinterService::getFormViewPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Siak\Tontine\Service\Report\Pdf;
4
5
use Illuminate\Support\Facades\Log;
6
use Illuminate\Support\Str;
7
use Siak\Tontine\Model\Round;
8
use Siak\Tontine\Model\Session;
9
use Siak\Tontine\Service\Tontine\TontineService;
10
11
use function strtolower;
12
use function trans;
13
use function view;
14
15
class PrinterService
16
{
17
    /**
18
     * @param TontineService $tontineService
19
     * @param array $config
20
     */
21
    public function __construct(private TontineService $tontineService, private array $config)
22
    {}
23
24
    /**
25
     * @param string $report
26
     *
27
     * @return string
28
     */
29
    private function getViewPath(string $report): string
30
    {
31
        $template = $this->tontineService->getReportTemplate();
32
        return "tontine.report.$template.$report";
33
    }
34
35
    /**
36
     * @param string $templatePath
37
     * @param array $config
38
     *
39
     * @return string
40
     */
41
    private function getPdf(string $templatePath, array $config = []): string
42
    {
43
        $config = [
44
            ...$this->config,
45
            ...$config,
46
            'headerTemplate' => (string)view("$templatePath.tpl.header"),
47
            'footerTemplate' => (string)view("$templatePath.tpl.footer"),
48
        ];
49
        return GeneratorFacade::getPdf((string)view($templatePath), $config);
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getSessionReportPath(): string
56
    {
57
        return $this->getViewPath('session');
58
    }
59
60
    /**
61
     * @param Session $session
62
     *
63
     * @return string
64
     */
65
    public function getSessionReportFilename(Session $session): string
66
    {
67
        return strtolower(trans('meeting.titles.report')) . '-' . Str::slug($session->title) . '.pdf';
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getSessionReport(): string
74
    {
75
        return $this->getPdf($this->getViewPath('session'));
76
    }
77
78
    /**
79
     * @return string
80
     */
81
    public function getSavingsReportPath(): string
82
    {
83
        return $this->getViewPath('savings');
84
    }
85
86
    /**
87
     * @param Session $session
88
     *
89
     * @return string
90
     */
91
    public function getSavingsReportFilename(Session $session): string
92
    {
93
        return Str::slug(trans('meeting.titles.savings')) . '-' . Str::slug($session->title) . '.pdf';
94
    }
95
96
    /**
97
     * @return string
98
     */
99
    public function getSavingsReport(): string
100
    {
101
        return $this->getPdf($this->getViewPath('savings'));
102
    }
103
104
    /**
105
     * @return string
106
     */
107
    public function getRoundReportPath(): string
108
    {
109
        return $this->getViewPath('round');
110
    }
111
112
    /**
113
     * @param Round $round
114
     *
115
     * @return string
116
     */
117
    public function getRoundReportFilename(Round $round): string
118
    {
119
        return strtolower(trans('meeting.titles.report')) . '-' . Str::slug($round->title) . '.pdf';
120
    }
121
122
    /**
123
     * @return string
124
     */
125
    public function getRoundReport(): string
126
    {
127
        return $this->getPdf($this->getViewPath('round'));
128
    }
129
130
    /**
131
     * @param string $form
132
     *
133
     * @return string
134
     */
135
    public function getFormViewPath(string $form): string
136
    {
137
        return "tontine.entry.raptor.$form";
138
    }
139
140
    /**
141
     * @param string $form
142
     *
143
     * @return string
144
     */
145
    public function getEntryForm(string $form): string
146
    {
147
        return $this->getPdf($this->getFormViewPath($form));
148
    }
149
150
    /**
151
     * @param string $form
152
     *
153
     * @return string
154
     */
155
    public function getFormFilename(string $form): string
156
    {
157
        return trans("meeting.entry.files.$form") . '.pdf';
158
    }
159
}
160