-
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user