Ver código fonte

paraemetrizing pdf creation texts

Medowar 4 dias atrás
pai
commit
98424504cc
3 arquivos alterados com 95 adições e 22 exclusões
  1. 30 0
      config/app.sample.php
  2. 43 22
      src/mail/pdfgenerator.php
  3. 22 0
      src/mail/submissionformatter.php

+ 30 - 0
config/app.sample.php

@@ -59,6 +59,36 @@ return [
         'logs' => $root . '/storage/logs',
         'locks' => $root . '/storage/locks',
     ],
+    'pdf_texts' => [
+        'metadata' => [
+            'creator' => 'Feuerwehr Freising - Mitgliedsantrag',
+            'author' => 'Feuerwehr Freising',
+        ],
+        'common' => [
+            'submitted_prefix' => 'Eingereicht: ',
+            'email_prefix' => 'E-Mail: ',
+            'uploads_heading' => 'Hochgeladene Dateien',
+            'missing_image' => '[Bild konnte nicht geladen werden]',
+        ],
+        'form_data' => [
+            'title' => 'Mitgliedsantrag',
+            'filename_prefix' => 'antragsdaten',
+        ],
+        'minor_signature' => [
+            'document_title' => 'Einverständniserklärung Minderjährige',
+            'heading' => 'Einverständniserklärung fuer Minderjährige',
+            'instruction' => 'Dieses Dokument ist auszudrucken, handschriftlich zu unterschreiben und persoenlich einzureichen.',
+            'filename_prefix' => 'minderjaehrige_einverstaendnis',
+            'signature_heading' => 'Unterschriften',
+            'signature_confirmation' => 'Hiermit bestaetigen Antragsteller/in und Erziehungsberechtigte/r die Richtigkeit der oben aufgefuehrten Angaben.',
+            'signature_minor_label' => 'Antragsteller/in (minderjaehrig)',
+            'signature_guardian_label' => 'Erziehungsberechtigte/r (Eltern)',
+        ],
+        'attachments' => [
+            'title' => 'Anlagen zum Mitgliedsantrag',
+            'filename_prefix' => 'anlagen',
+        ],
+    ],
     'api_messages' => [
         'common' => [
             'method_not_allowed' => 'Method not allowed',

+ 43 - 22
src/mail/pdfgenerator.php

@@ -22,6 +22,8 @@ final class PdfGenerator
     private SubmissionFormatter $formatter;
     private FormSchema $schema;
     private string $uploadBasePath;
+    /** @var array<string, mixed> */
+    private array $pdfTexts;
 
     public function __construct(SubmissionFormatter $formatter, FormSchema $schema)
     {
@@ -30,6 +32,7 @@ final class PdfGenerator
 
         $app = Bootstrap::config('app');
         $this->uploadBasePath = rtrim((string) ($app['storage']['uploads'] ?? ''), '/');
+        $this->pdfTexts = is_array($app['pdf_texts'] ?? null) ? $app['pdf_texts'] : [];
     }
 
     /** @param array<string, mixed> $submission */
@@ -37,14 +40,14 @@ final class PdfGenerator
     {
         try {
             $pdf = $this->createPdf();
-            $pdf->SetTitle($this->enc('Mitgliedsantrag'), true);
+            $pdf->SetTitle($this->enc($this->pdfText('form_data.title')), true);
             $pdf->AddPage();
 
             $pdf->SetFont('Helvetica', 'B', 16);
-            $pdf->Cell(0, 10, $this->enc('Mitgliedsantrag'), 0, 1);
+            $pdf->Cell(0, 10, $this->enc($this->pdfText('form_data.title')), 0, 1);
             $pdf->SetFont('Helvetica', '', 9);
-            $pdf->Cell(0, 5, $this->enc('Eingereicht: ' . $this->formatTimestamp($submission)), 0, 1);
-            $pdf->Cell(0, 5, $this->enc('E-Mail: ' . (string) ($submission['email'] ?? '')), 0, 1);
+            $pdf->Cell(0, 5, $this->enc($this->pdfText('common.submitted_prefix') . $this->formatTimestamp($submission)), 0, 1);
+            $pdf->Cell(0, 5, $this->enc($this->pdfText('common.email_prefix') . (string) ($submission['email'] ?? '')), 0, 1);
             $pdf->Ln(4);
 
             $this->renderPortrait($pdf, $submission);
@@ -58,7 +61,7 @@ final class PdfGenerator
             if ($uploads !== []) {
                 $this->ensureSpace($pdf, 20);
                 $pdf->SetFont('Helvetica', 'B', 12);
-                $pdf->Cell(0, 8, $this->enc('Hochgeladene Dateien'), 0, 1);
+                $pdf->Cell(0, 8, $this->enc($this->pdfText('common.uploads_heading')), 0, 1);
                 $pdf->SetFont('Helvetica', '', 10);
                 foreach ($uploads as $group) {
                     $pdf->SetFont('Helvetica', 'B', 10);
@@ -71,7 +74,7 @@ final class PdfGenerator
                 }
             }
 
-            $tmpPath = $this->tempPath('antragsdaten');
+            $tmpPath = $this->tempPath($this->pdfText('form_data.filename_prefix', 'antragsdaten'));
             $pdf->Output('F', $tmpPath);
             return $tmpPath;
         } catch (\Throwable $e) {
@@ -94,21 +97,21 @@ final class PdfGenerator
 
         try {
             $pdf = $this->createPdf();
-            $pdf->SetTitle($this->enc('Einverstaendniserklaerung Minderjaehrige'), true);
+            $pdf->SetTitle($this->enc($this->pdfText('minor_signature.document_title')), true);
             $pdf->AddPage();
 
             $pdf->SetFont('Helvetica', 'B', 15);
-            $pdf->Cell(0, 10, $this->enc('Einverstaendniserklaerung fuer Minderjaehrige'), 0, 1);
+            $pdf->Cell(0, 10, $this->enc($this->pdfText('minor_signature.heading')), 0, 1);
             $pdf->SetFont('Helvetica', '', 9);
-            $pdf->Cell(0, 5, $this->enc('Eingereicht: ' . $this->formatTimestamp($submission)), 0, 1);
-            $pdf->Cell(0, 5, $this->enc('E-Mail: ' . (string) ($submission['email'] ?? '')), 0, 1);
+            $pdf->Cell(0, 5, $this->enc($this->pdfText('common.submitted_prefix') . $this->formatTimestamp($submission)), 0, 1);
+            $pdf->Cell(0, 5, $this->enc($this->pdfText('common.email_prefix') . (string) ($submission['email'] ?? '')), 0, 1);
             $pdf->Ln(3);
 
             $pdf->SetFont('Helvetica', '', 10);
             $pdf->MultiCell(
                 0,
                 5,
-                $this->enc('Dieses Dokument ist auszudrucken, handschriftlich zu unterschreiben und persoenlich einzureichen.')
+                $this->enc($this->pdfText('minor_signature.instruction'))
             );
             $pdf->Ln(2);
 
@@ -121,7 +124,7 @@ final class PdfGenerator
             if ($uploads !== []) {
                 $this->ensureSpace($pdf, 20);
                 $pdf->SetFont('Helvetica', 'B', 12);
-                $pdf->Cell(0, 8, $this->enc('Hochgeladene Dateien'), 0, 1);
+                $pdf->Cell(0, 8, $this->enc($this->pdfText('common.uploads_heading')), 0, 1);
                 $pdf->SetFont('Helvetica', '', 10);
                 foreach ($uploads as $group) {
                     $pdf->SetFont('Helvetica', 'B', 10);
@@ -136,7 +139,7 @@ final class PdfGenerator
 
             $this->renderMinorSignatureSection($pdf);
 
-            $tmpPath = $this->tempPath('minderjaehrige_einverstaendnis');
+            $tmpPath = $this->tempPath($this->pdfText('minor_signature.filename_prefix', 'minderjaehrige_einverstaendnis'));
             $pdf->Output('F', $tmpPath);
             return $tmpPath;
         } catch (\Throwable $e) {
@@ -160,7 +163,7 @@ final class PdfGenerator
 
         try {
             $pdf = $this->createPdf();
-            $pdf->SetTitle($this->enc('Anlagen zum Mitgliedsantrag'), true);
+            $pdf->SetTitle($this->enc($this->pdfText('attachments.title')), true);
 
             foreach ($images as $img) {
                 $pdf->AddPage();
@@ -173,11 +176,11 @@ final class PdfGenerator
                     $this->embedImage($pdf, $imgPath);
                 } else {
                     $pdf->SetFont('Helvetica', '', 10);
-                    $pdf->Cell(0, 10, $this->enc('[Bild konnte nicht geladen werden]'), 0, 1);
+                    $pdf->Cell(0, 10, $this->enc($this->pdfText('common.missing_image')), 0, 1);
                 }
             }
 
-            $tmpPath = $this->tempPath('anlagen');
+            $tmpPath = $this->tempPath($this->pdfText('attachments.filename_prefix', 'anlagen'));
             $pdf->Output('F', $tmpPath);
             return $tmpPath;
         } catch (\Throwable $e) {
@@ -310,12 +313,12 @@ final class PdfGenerator
         $this->ensureSpace($pdf, 55);
         $pdf->Ln(6);
         $pdf->SetFont('Helvetica', 'B', 11);
-        $pdf->Cell(0, 8, $this->enc('Unterschriften'), 0, 1);
+        $pdf->Cell(0, 8, $this->enc($this->pdfText('minor_signature.signature_heading')), 0, 1);
         $pdf->SetFont('Helvetica', '', 10);
         $pdf->MultiCell(
             0,
             5,
-            $this->enc('Hiermit bestaetigen Antragsteller/in und Erziehungsberechtigte/r die Richtigkeit der oben aufgefuehrten Angaben.')
+            $this->enc($this->pdfText('minor_signature.signature_confirmation'))
         );
         $pdf->Ln(10);
 
@@ -330,9 +333,9 @@ final class PdfGenerator
         $pdf->SetY($lineY + 2);
         $pdf->SetFont('Helvetica', '', 9);
         $pdf->SetX($leftX);
-        $pdf->Cell($lineWidth, 5, $this->enc('Antragsteller/in (minderjaehrig)'), 0, 0);
+        $pdf->Cell($lineWidth, 5, $this->enc($this->pdfText('minor_signature.signature_minor_label')), 0, 0);
         $pdf->SetX($rightX);
-        $pdf->Cell($lineWidth, 5, $this->enc('Erziehungsberechtigte/r (Eltern)'), 0, 1);
+        $pdf->Cell($lineWidth, 5, $this->enc($this->pdfText('minor_signature.signature_guardian_label')), 0, 1);
     }
 
     private function embedImage(\FPDF $pdf, string $path): void
@@ -486,8 +489,8 @@ final class PdfGenerator
         $pdf = new \FPDF('P', 'mm', 'A4');
         $pdf->SetAutoPageBreak(true, 20);
         $pdf->SetMargins(15, 15, 15);
-        $pdf->SetCreator($this->enc('Feuerwehr Freising - Mitgliedsantrag'), true);
-        $pdf->SetAuthor($this->enc('Feuerwehr Freising'), true);
+        $pdf->SetCreator($this->enc($this->pdfText('metadata.creator')), true);
+        $pdf->SetAuthor($this->enc($this->pdfText('metadata.author')), true);
         return $pdf;
     }
 
@@ -504,6 +507,24 @@ final class PdfGenerator
         return sys_get_temp_dir() . '/antrag_' . $prefix . '_' . bin2hex(random_bytes(8)) . '.pdf';
     }
 
+    private function pdfText(string $path, string $fallback = ''): string
+    {
+        $value = $this->pdfTexts;
+        foreach (explode('.', $path) as $segment) {
+            if (!is_array($value) || !array_key_exists($segment, $value)) {
+                return $fallback;
+            }
+            $value = $value[$segment];
+        }
+
+        if (!is_string($value)) {
+            return $fallback;
+        }
+
+        $text = trim($value);
+        return $text !== '' ? $text : $fallback;
+    }
+
     /**
      * Encode UTF-8 to Windows-1252 for FPDF's built-in fonts.
      * Transliterates characters outside the target charset.

+ 22 - 0
src/mail/submissionformatter.php

@@ -27,6 +27,7 @@ final class SubmissionFormatter
     {
         $formData = (array) ($submission['form_data'] ?? []);
         $formData['is_minor'] = $this->deriveIsMinor($formData);
+        $submissionEmail = trim((string) ($submission['email'] ?? ''));
         $result = [];
 
         foreach ($this->schema->getSteps() as $step) {
@@ -55,6 +56,10 @@ final class SubmissionFormatter
                 $fields[] = ['label' => $label, 'value' => $value];
             }
 
+            if ($this->isPersonalDataStep($title) && $submissionEmail !== '' && !$this->hasEmailField($fields)) {
+                $fields[] = ['label' => 'E-Mail', 'value' => $submissionEmail];
+            }
+
             if ($fields !== []) {
                 $result[] = ['title' => $title, 'fields' => $fields];
             }
@@ -200,6 +205,23 @@ final class SubmissionFormatter
         return true;
     }
 
+    private function isPersonalDataStep(string $title): bool
+    {
+        return trim($title) === 'Persönliche Daten';
+    }
+
+    /** @param array<int, array{label: string, value: string}> $fields */
+    private function hasEmailField(array $fields): bool
+    {
+        foreach ($fields as $field) {
+            if (strtolower(trim((string) ($field['label'] ?? ''))) === 'e-mail') {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
     /** @param array<string, mixed> $formData */
     private function deriveIsMinor(array $formData): string
     {