added ConstructionConsentController::deleteAction()

This commit is contained in:
Frank Schubert
2025-02-14 16:19:05 +01:00
parent 61b192e1c9
commit 7575ef05fb
6 changed files with 74 additions and 32 deletions
@@ -34,6 +34,33 @@ class ConstructionConsent extends mfBaseModel {
return $data;
}
protected function beforeDelete() {
if(!$this->id) return true;
// delete owners
foreach($this->getProperty("owners") as $owner) {
$owner->delete();
}
// delete contacts
foreach($this->getProperty("contacts") as $contact) {
$contact->delete();
}
// delete journals
foreach($this->getProperty("journal") as $journal) {
$journal->delete();
}
// delete history
foreach($this->getProperty("history") as $history) {
$history->delete();
}
// delete files
if($this->getProperty("file")) {
$this->getProperty("file")->delete();
}
return true;
}
protected function afterSave() {
$this->createHistory();
}
@@ -181,7 +208,7 @@ class ConstructionConsent extends mfBaseModel {
}
if($name == "file") {
if(!$this->id) return [];
if(!$this->id) return null;
$file = ConstructionConsentFile::getFirst(["constructionconsent_id" => $this->id]);
if($file) {
$this->file = $file;
@@ -70,7 +70,7 @@ class ConstructionConsentController extends mfBaseController {
$pagination['maxItems'] = ConstructionConsent::count($filter);
$this->layout()->set("pagination", $pagination);
$items = ConstructionConsent::search($filter);
$items = ConstructionConsent::search($filter, $pagination);
$this->layout->set("items", $items);
if(array_key_exists("project_id", $filter) && $filter["project_id"]) {
@@ -320,6 +320,25 @@ class ConstructionConsentController extends mfBaseController {
}
protected function deleteAction() {
$id = $this->request->id;
if(!is_numeric($id) || $id < 1) {
$this->layout()->setFlash("Zustimmungserklärung nicht gefunden", "error");
$this->redirect("ConstructionConsent");
}
$item = new ConstructionConsent($id);
if(!$item->id) {
$this->layout()->setFlash("Zustimmungserklärung nicht gefunden", "error");
$this->redirect("ConstructionConsent");
}
$item->delete();
$this->layout()->setFlash("Zustimmungserklärung erfolgreich gelöscht", "success");
$this->redirect("ConstructionConsent");
}
protected function saveDate() {
$r = $this->request;