36 lines
1.1 KiB
PHP
36 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Admin\Controllers;
|
|
|
|
use App\Models\DocumentTypeCatalog;
|
|
use App\Providers\DocumentTemplateRenderProvider;
|
|
use App\Providers\PdfGenerateAndDownloadProvider;
|
|
use App\Scopes\CommonController;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
|
|
/**
|
|
* Rendert die Vorlage mit Beispieldaten, ohne sie zu speichern -- damit niemand blind HTML editiert.
|
|
*/
|
|
class DocumentTemplatesPreviewController extends CommonController
|
|
{
|
|
public function __invoke(Request $request): Response
|
|
{
|
|
$documentType = (string) $request->input('type', DocumentTypeCatalog::default());
|
|
|
|
if (!DocumentTypeCatalog::has($documentType)) {
|
|
abort(422, 'Unbekannte Dokumentart.');
|
|
}
|
|
|
|
$html = new DocumentTemplateRenderProvider(
|
|
$documentType,
|
|
(array) $request->input('blocks', []),
|
|
)->render(DocumentTypeCatalog::sampleTokens($documentType));
|
|
|
|
return response(PdfGenerateAndDownloadProvider::fromHtml($html, 'portrait'), 200, [
|
|
'Content-Type' => 'application/pdf',
|
|
'Content-Disposition' => 'inline; filename="vorschau.pdf"',
|
|
]);
|
|
}
|
|
}
|