173 lines
5.8 KiB
PHP
173 lines
5.8 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\Generate;
|
|
|
|
use App\Actions\Generate\Pdf\Deckblatt;
|
|
use App\Actions\Generate\Pdf\DigitaleSignatur;
|
|
use App\Actions\Generate\Pdf\Inhalt;
|
|
use App\Actions\Generate\Pdf\Platzhalter;
|
|
use App\Actions\Generate\Pdf\Ueberschrift;
|
|
use App\Actions\Generate\Tabellen\Allgemeinflaechen;
|
|
use App\Actions\Generate\Tabellen\Nutzwertberechnung;
|
|
use App\Actions\Generate\Tabellen\Paragraph6;
|
|
use App\Actions\Generate\Tabellen\Zusammenstellung;
|
|
use App\Actions\Generate\Tabellen\ZuUndAbschlaege;
|
|
use App\Actions\Generate\Utilities\Format;
|
|
use App\Models\Auftraggeber;
|
|
use App\Models\Gutachter;
|
|
use App\Models\Projekte;
|
|
use App\Models\ProjektInhaltsverzeichnis;
|
|
use Filament\Forms\Components\RichEditor\RichContentRenderer;
|
|
use Illuminate\Support\Facades\File;
|
|
use Illuminate\Support\Facades\Response;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Mpdf\HTMLParserMode;
|
|
use Mpdf\Mpdf;
|
|
|
|
class PdfGenerator
|
|
{
|
|
public static $projekt;
|
|
|
|
public static $gutachter;
|
|
|
|
public static $auftraggeber;
|
|
|
|
public static $zusammenstellung = [];
|
|
|
|
public static function make($projekte_id, $part)
|
|
{
|
|
self::$projekt = Projekte::where('id', $projekte_id)->first();
|
|
|
|
self::$gutachter = Gutachter::where('id', self::$projekt->gutachter_id)->first();
|
|
|
|
self::$auftraggeber = Auftraggeber::where('id', self::$projekt->auftraggeber_id)->first();
|
|
|
|
$headers = [
|
|
'Content-Type: application/pdf',
|
|
'Cache-Control: max-age=0',
|
|
'Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT',
|
|
'Cache-Control: cache, must-revalidate',
|
|
];
|
|
|
|
$filepath = Storage::disk('public')->path("/download/$projekte_id/");
|
|
$filename = \ucfirst($part).' '.preg_replace("'[^0-9a-zA-Z]'", '', self::$projekt->interner_name).'.pdf';
|
|
|
|
if (! File::isDirectory($filepath)) {
|
|
File::makeDirectory($filepath, 0777, true, true);
|
|
}
|
|
|
|
$file = $filepath.$filename;
|
|
|
|
ob_start();
|
|
|
|
$mpdf = new Mpdf(
|
|
[
|
|
'debug' => true,
|
|
'mode' => 'utf-8',
|
|
'format' => 'A4-P',
|
|
'margin_left' => 10,
|
|
'margin_right' => 10,
|
|
'margin_top' => 12,
|
|
'margin_bottom' => 20,
|
|
'margin_header' => 0,
|
|
'margin_footer' => 0,
|
|
]
|
|
);
|
|
|
|
$stylesheet = file_get_contents(__DIR__.'/../../../resources/css/pdf-download.css');
|
|
$mpdf->WriteHTML($stylesheet, HTMLParserMode::HEADER_CSS);
|
|
$mpdf->SetTitle($filename);
|
|
$mpdf->SetCreator('nutzwerte.at');
|
|
$mpdf->SetAuthor(self::$gutachter->title.' '.self::$gutachter->gender.' '.self::$gutachter->name);
|
|
|
|
$inhaltesverzeichnis = ProjektInhaltsverzeichnis::where('projekte_id', $projekte_id)->where('part', $part)->orderBy('sort')->get();
|
|
|
|
// dd($inhaltesverzeichnis);
|
|
|
|
$platzhalter = Platzhalter::load($projekte_id);
|
|
|
|
foreach ($inhaltesverzeichnis as $inhalt) {
|
|
|
|
if ($inhalt->neue_seite) {
|
|
if ($part == 'nutzwerte') {
|
|
$mpdf->AddPage('P', '', self::$projekt->nutzwerte_startseite);
|
|
} else {
|
|
$mpdf->AddPage();
|
|
}
|
|
}
|
|
|
|
$html = '';
|
|
$html = Ueberschrift::load($inhalt);
|
|
|
|
if ($inhalt->textblock) {
|
|
$textblock = Platzhalter::replace($platzhalter, $inhalt->textblock);
|
|
$textblock = Format::fix_str($textblock);
|
|
if ($inhalt->inhaltselement_id != '9') {
|
|
$html .= $textblock;
|
|
}
|
|
}
|
|
|
|
if ($inhalt->textblock2) {
|
|
$textblock2 = Platzhalter::replace($platzhalter, $inhalt->textblock2);
|
|
$textblock2 = Format::fix_str($textblock2);
|
|
}
|
|
|
|
switch ($inhalt->inhaltselement_id) {
|
|
case '1':
|
|
$html .= Inhalt::load($projekte_id);
|
|
break;
|
|
case '3':
|
|
$html .= Paragraph6::load($projekte_id);
|
|
break;
|
|
case '4':
|
|
$html .= Allgemeinflaechen::load($projekte_id);
|
|
break;
|
|
case '5':
|
|
$html .= ZuUndAbschlaege::load($projekte_id);
|
|
break;
|
|
case '6':
|
|
$html .= Nutzwertberechnung::load($projekte_id);
|
|
break;
|
|
case '7':
|
|
$html .= Zusammenstellung::load($projekte_id);
|
|
break;
|
|
case '8':
|
|
// AUFTRAGGEBER
|
|
$str = RichContentRenderer::make(self::$auftraggeber->referenz_formatting)->toHtml();
|
|
$html .= Format::fix_str($str);
|
|
break;
|
|
case '9':
|
|
$html .= Deckblatt::load($inhalt, $textblock, $textblock2);
|
|
break;
|
|
case '10':
|
|
$html .= DigitaleSignatur::load($projekte_id);
|
|
break;
|
|
}
|
|
|
|
if ($inhalt->textblock2 and $inhalt->inhaltselement_id != 9) {
|
|
$html .= $textblock2;
|
|
}
|
|
|
|
if ($inhalt->seitenzahl_anzeige == 1) {
|
|
$mpdf->SetHTMLFooter('<div class="center">Seite {PAGENO} <br><br></div>');
|
|
}
|
|
if ($html) {
|
|
$mpdf->WriteHTML($html, HTMLParserMode::HTML_BODY);
|
|
}
|
|
|
|
ProjektInhaltsverzeichnis::where('id', $inhalt->id)->update(['seite' => $mpdf->page]);
|
|
|
|
}
|
|
|
|
if ($part == 'standard') {
|
|
Projekte::where('id', $projekte_id)->update(['nutzwerte_startseite' => $mpdf->page]);
|
|
}
|
|
|
|
ob_clean();
|
|
|
|
$mpdf->Output($file, 'F');
|
|
|
|
return Response::download($file, $filename, $headers);
|
|
}
|
|
}
|