|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use Illuminate\Http\Response; |
|
7
|
|
|
use Illuminate\View\View; |
|
8
|
|
|
use Siak\Tontine\Service\LocaleService; |
|
9
|
|
|
use Siak\Tontine\Service\Meeting\SessionService; |
|
10
|
|
|
use Siak\Tontine\Service\Report\Pdf\PrinterService; |
|
11
|
|
|
use Siak\Tontine\Service\Report\ReportService; |
|
12
|
|
|
use Siak\Tontine\Service\TenantService; |
|
13
|
|
|
use Sqids\SqidsInterface; |
|
14
|
|
|
|
|
15
|
|
|
use function base64_decode; |
|
16
|
|
|
use function compact; |
|
17
|
|
|
use function response; |
|
18
|
|
|
use function trans; |
|
19
|
|
|
use function view; |
|
20
|
|
|
|
|
21
|
|
|
class FormController extends Controller |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @param TenantService $tenantService |
|
25
|
|
|
* @param PrinterService $printerService |
|
26
|
|
|
* @param SessionService $sessionService |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct(private TenantService $tenantService, |
|
29
|
|
|
private PrinterService $printerService, private SessionService $sessionService) |
|
30
|
|
|
{} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param Request $request |
|
34
|
|
|
* @param string $form |
|
35
|
|
|
* |
|
36
|
|
|
* @return View|Response |
|
37
|
|
|
*/ |
|
38
|
|
|
private function form(Request $request, string $form) |
|
39
|
|
|
{ |
|
40
|
|
|
// Show the html page |
|
41
|
|
|
if($request->has('html')) |
|
42
|
|
|
{ |
|
43
|
|
|
return view($this->printerService->getFormViewPath($form)); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
// Print the pdf |
|
47
|
|
|
$filename = $this->printerService->getFormFilename($form); |
|
48
|
|
|
return response(base64_decode($this->printerService->getEntryForm($form)), 200) |
|
49
|
|
|
->header('Content-Description', trans("meeting.entry.titles.$form")) |
|
50
|
|
|
->header('Content-Type', 'application/pdf') |
|
51
|
|
|
->header('Content-Disposition', "inline; filename=$filename") |
|
52
|
|
|
->header('Content-Transfer-Encoding', 'binary') |
|
53
|
|
|
->header('Expires', '0') |
|
54
|
|
|
->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0') |
|
55
|
|
|
->header('Pragma', 'public'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param Request $request |
|
60
|
|
|
* @param SqidsInterface $sqids |
|
61
|
|
|
* @param string $sessionSqid |
|
62
|
|
|
* |
|
63
|
|
|
* @return View|Response |
|
64
|
|
|
*/ |
|
65
|
|
|
public function session(Request $request, ReportService $reportService, |
|
66
|
|
|
SqidsInterface $sqids, string $sessionSqid) |
|
67
|
|
|
{ |
|
68
|
|
|
[$sessionId] = $sqids->decode($sessionSqid); |
|
69
|
|
|
$session = $this->sessionService->getSession($sessionId); |
|
70
|
|
|
view()->share($reportService->getSessionEntry($session)); |
|
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
return $this->form($request, 'session'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param Request $request |
|
77
|
|
|
* @param LocaleService $localeService |
|
78
|
|
|
* @param SqidsInterface $sqids |
|
79
|
|
|
* @param string $form |
|
80
|
|
|
* @param string $sessionSqid |
|
81
|
|
|
* |
|
82
|
|
|
* @return View|Response |
|
83
|
|
|
*/ |
|
84
|
|
|
public function entry(Request $request, LocaleService $localeService, |
|
85
|
|
|
SqidsInterface $sqids, string $form, string $sessionSqid = '') |
|
86
|
|
|
{ |
|
87
|
|
|
$tontine = $this->tenantService->tontine(); |
|
88
|
|
|
[$country] = $localeService->getNameFromTontine($tontine); |
|
|
|
|
|
|
89
|
|
|
$session = null; |
|
90
|
|
|
if($sessionSqid !== '') |
|
91
|
|
|
{ |
|
92
|
|
|
[$sessionId] = $sqids->decode($sessionSqid); |
|
93
|
|
|
$session = $this->sessionService->getSession($sessionId); |
|
94
|
|
|
} |
|
95
|
|
|
view()->share(compact('tontine', 'country', 'session')); |
|
96
|
|
|
|
|
97
|
|
|
return $this->form($request, $form); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|