WIP 2024-12-16 ConstructionConsent
This commit is contained in:
@@ -18,11 +18,55 @@ class ConstructionConsentProjectController extends mfBaseController {
|
||||
protected function indexAction() : void {
|
||||
$this->layout()->setTemplate("ConstructionConsentProject/Index");
|
||||
|
||||
if ($this->request->resetFilter) {
|
||||
unset($_SESSION[MFAPPNAME . '-ConstructionConsentProject-filter']);
|
||||
}
|
||||
|
||||
$filter = [];
|
||||
if (is_array($this->request->filter)) {
|
||||
$filter = $this->request->filter;
|
||||
$_SESSION[MFAPPNAME . '-ConstructionConsentProject-filter'] = $filter;
|
||||
} else {
|
||||
if (array_key_exists(MFAPPNAME . '-ConstructionConsentProject-filter', $_SESSION) && count($_SESSION[MFAPPNAME . '-ConstructionConsentProject-filter'])) {
|
||||
$filter = $_SESSION[MFAPPNAME . '-ConstructionConsentProject-filter'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->layout->set("filter", $filter);
|
||||
$filter = $this->getPreparedFilter($filter);
|
||||
|
||||
// pagination defaults
|
||||
$pagination = [];
|
||||
$pagination['start'] = 0;
|
||||
$pagination['count'] = 25;
|
||||
$pagination['maxItems'] = 0;
|
||||
|
||||
if (is_numeric($this->request->s)) {
|
||||
$pagination['start'] = intval($this->request->s);
|
||||
}
|
||||
//var_dump($filter);exit;
|
||||
$pagination['maxItems'] = ConstructionConsentProject::count($filter);
|
||||
|
||||
$projects = ConstructionConsentProject::getAll();
|
||||
$this->layout()->set("projects", $projects);
|
||||
$this->layout()->set("pagination", $pagination);
|
||||
|
||||
}
|
||||
|
||||
private function getPreparedFilter($filter) {
|
||||
$new_filter = [];
|
||||
|
||||
|
||||
|
||||
if (is_array($filter) && count($filter)) {
|
||||
foreach ($filter as $name => $value) {
|
||||
$new_filter[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $new_filter;
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
$this->layout()->setTemplate("ConstructionConsentProject/Form");
|
||||
|
||||
@@ -68,18 +112,36 @@ class ConstructionConsentProjectController extends mfBaseController {
|
||||
|
||||
$data = [];
|
||||
$data["name"] = $r->name;
|
||||
$data["sender_name"] = $r->sender_name;
|
||||
$data["sender_email"] = $r->sender_email;
|
||||
$data["sender_reply_to"] = $r->sender_reply_to;
|
||||
$data["email"] = $r->email;
|
||||
$data["phone"] = $r->phone;
|
||||
$data["note"] = $r->note;
|
||||
|
||||
if(!$r->name) {
|
||||
if($mode == "add") {
|
||||
$project = ConstructionConsentProject::create($data);
|
||||
} else {
|
||||
$project->update($data);
|
||||
}
|
||||
$this->layout()->set("project", $project);
|
||||
|
||||
if(!$r->name || !$r->sender_name || !$r->sender_email || !$r->email || !$r->phone) {
|
||||
$this->layout()->setFlash("Bitte alle erforderlichen Felder ausfüllen", "error");
|
||||
$this->redirect("ConstructionConsentProject");
|
||||
return $this->addAction();
|
||||
}
|
||||
if(!is_array($r->adb_netzgebiet_id) || !count($r->adb_netzgebiet_id)) {
|
||||
$this->layout()->setFlash("Bitte alle erforderlichen Felder ausfüllen", "error");
|
||||
$this->redirect("ConstructionConsentProject");
|
||||
$this->layout()->setFlash("Bitte mindestens ein Netzgebiet auswählen", "error");
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
$netzgebiete = [];
|
||||
|
||||
if(!$project->save()) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
foreach($r->adb_netzgebiet_id as $netzgebiet_id) {
|
||||
$netzgebiet = new ADBNetzgebiet($netzgebiet_id);
|
||||
if(!$netzgebiet->id) continue;
|
||||
@@ -87,20 +149,14 @@ class ConstructionConsentProjectController extends mfBaseController {
|
||||
$netzgebiete[] = $netzgebiet_id;
|
||||
}
|
||||
|
||||
/*
|
||||
if($mode == "add") {
|
||||
$project = ConstructionConsentProject::create($data);
|
||||
} else {
|
||||
$project->update($data);
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
if(!$project->save()) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
if($mode == "add") {
|
||||
$this->redirect("ConstructionConsentProject", "add");
|
||||
} else {
|
||||
$this->redirect("ConstructionConsentProject", "edit", ["id" => $project->id]);
|
||||
}
|
||||
}
|
||||
|
||||
//save networks
|
||||
foreach($netzgebiete as $netzgebiet_id) {
|
||||
|
||||
Reference in New Issue
Block a user