Added image upload to ConstructionConsent Form

This commit is contained in:
Frank Schubert
2025-01-13 19:06:50 +01:00
parent 15bfe7c734
commit f2cfefc7a2
6 changed files with 83 additions and 5 deletions
@@ -106,7 +106,6 @@ class ConstructionConsentController extends mfBaseController {
}
$this->layout()->set("item", $item);
}
protected function addAction() : void {
@@ -227,8 +226,35 @@ class ConstructionConsentController extends mfBaseController {
return $this->addAction();
}
if(is_array($_FILES) && array_key_exists("consent_plan_image", $_FILES) && !$_FILES['consent_plan_image']['error']) {
try {
// returns File object or throws Exception on error
$file = mfUpload::handleFormUpload("consent_plan_image", false, TT_CONSTRUCTIONCONSENT_FILE_UPLOAD_SUBFOLDER);
} catch (Exception $ex) {
$this->layout()->setFlash("Fehler beim Hochladen: " . $ex->getMessage(), "warning");
return $this->editAction();
}
$ccf = ConstructionConsentFile::create([
'constructionconsent_id' => $id,
'file_id' => $file->id,
'filename' => "zustimmungserklärung-".$item->id."-plan.png",
]);
// delete previous image
$img = ConstructionConsentFile::getFirst(["constructionconsent_id" => $id]);
if($img) {
$img->file->delete();
$img->delete();
}
if(!$ccf->save()) {
$this->layout()->setFlash("Fehler beim Hochladen", "warning");
}
}
$this->layout()->setFlash("Zustimmungserklärung erfolgreich gespeichert", "success");
$this->redirect("ConstructionConsent");
$this->redirect("ConstructionConsent", "View", ["id" => $id]);
}