Files
nutzwerte_fi4/app/Actions/Download/Nutzwerte.php
T
2025-10-23 12:07:56 +02:00

67 lines
2.0 KiB
PHP

<?php
namespace App\Actions\Download;
use App\Actions\Generate\MakeNutzwerte;
use App\Models\Projekte;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Storage;
class Nutzwerte
{
public function download($projekte_id, $mode)
{
if ($mode == 'new') {
Projekte::where('id', $projekte_id)->update(['pdf_nutzwerte_name' => '', 'pdf_nutzwerte_status' => '0']);
}
$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',
];
$projekt = Projekte::where('id', $projekte_id)->first()->toArray();
$filepath = Storage::disk('public')->path("/download/$projekte_id/");
$filename = 'Gutachten '.preg_replace("'[^0-9a-zA-Z]'", '', $projekt['interner_name']).'.pdf';
if (! File::isDirectory($filepath)) {
File::makeDirectory($filepath, 0777, true, true);
}
$file = $filepath.$filename;
MakeNutzwerte::generate($file, $projekte_id);
return Response::download($file, 'Nutzwert '.$projekt['offizieller_name'], $headers);
// if ($projekt['pdf_nutzwerte_status'] == 0) {
// $filename = preg_replace("'[^0-9a-zA-Z]'", '', $projekt['intname']).'.pdf';
// if (! File::isDirectory($filepath)) {
// File::makeDirectory($filepath, 0777, true, true);
// }
// $file = $filepath.$filename;
// GenerateNutzwerte::generate($file, $projekte_id);
// Projekte::where('id', $projekte_id)->update(['pdf_nutzwerte' => $filename, 'pdf_nutzwerte_ok' => '1']);
// return Response::download($file, $projekt['name'], $headers);
// } else {
// $filename = $projekt['pdf_nutzwerte_name'];
// $file = $filepath.$filename;
// return Response::download($file, $projekt['name'], $headers);
// }
}
}