This commit is contained in:
Luca Haid
2025-05-06 11:28:55 +02:00
parent 4c4dc1b00c
commit 265f07ed53
6 changed files with 91 additions and 15 deletions
@@ -189,20 +189,33 @@ class ConstructionConsentController extends mfBaseController {
protected function downloadMultipleAction()
{
// Reuse index filter logic
$filter = $this->getPreparedFilter($this->request->filter);
$owners = [];
foreach (ConstructionConsent::search($filter, []) as $consent) {
foreach (ConstructionConsent::search($this->getPreparedFilter($this->request->filter), []) as $consent)
$owners = array_merge($owners, $consent->owners ?: []);
}
if (empty($owners)) {
$this->layout()->setFlash("Keine Besitzer gefunden", "error");
$this->redirect("ConstructionConsent");
}
// Use first consent as base - might need adjustment for your use case
if ($this->request->markAsSent === '1') {
foreach ($owners as $owner) {
$update = $owner->status === 'new' || $owner->status === null;
if ($owner->status === 'new') $owner->status = 'sent';
if ($owner->result === null) $owner->result = 'open';
if ($update) {
$owner->save();
$history = ConstructionConsentHistory::create([
"constructionconsent_id" => $owner->consent->id,
"key" => "status",
"old_value" => 'new',
"new_value" => 'sent'
]);
$history->save();
}
}
}
if (!($filename = $this->generatePdf($owners, $owners[0]->consent))) {
$this->layout()->setFlash("PDF-Erstellung fehlgeschlagen", "error");
$this->redirect("ConstructionConsent");
@@ -214,7 +227,7 @@ class ConstructionConsentController extends mfBaseController {
private function sendPdfResponse(string $filename, string $downloadName): void
{
header('Content-Type: ' . mime_content_type($filename));
header('Content-disposition: attachment; filename="' . $downloadName . '"');
header('Content-disposition: attachment; filename="' . rawurlencode($downloadName) . '"');
header('Content-Length: ' . filesize($filename));
readfile($filename);
exit;