WIP ConstructionConsent & update-statusflags script

This commit is contained in:
Frank Schubert
2024-12-18 19:49:18 +01:00
parent 0e6489ce20
commit 9c73bf4faf
7 changed files with 264 additions and 21 deletions
@@ -18,21 +18,44 @@ class ConstructionConsentController extends mfBaseController {
protected function indexAction() : void {
$this->layout()->setTemplate("ConstructionConsent/Index");
if ($this->request->resetFilter) {
if($this->request->resetFilter) {
unset($_SESSION[MFAPPNAME . '-ConstructionConsent-filter']);
$this->redirect("ConstructionConsent");
foreach($_SESSION as $key => $s) {
if(preg_match('/^' . MFAPPNAME . '-ConstructionConsent-filter-project-\d+$/', $key)) {
unset($_SESSION[$key]);
}
}
}
$filter = [];
if (is_array($this->request->filter)) {
if(is_array($this->request->filter)) {
$filter = $this->request->filter;
$_SESSION[MFAPPNAME . '-ConstructionConsent-filter'] = $filter;
if(isset($this->request->filter["project_id"]) && $this->request->filter["project_id"]) {
$filter_p_id = $filter["project_id"];
if(count($this->request->filter) == 1 && isset($_SESSION[MFAPPNAME . '-ConstructionConsent-filter-project-' . $filter_p_id])) {
$filter = $_SESSION[MFAPPNAME . '-ConstructionConsent-filter-project-' . $filter_p_id];
} else {
$_SESSION[MFAPPNAME . '-ConstructionConsent-filter-project-' . $filter["project_id"]] = $filter;
}
} else {
$_SESSION[MFAPPNAME . '-ConstructionConsent-filter'] = $filter;
}
} else {
if (array_key_exists(MFAPPNAME . '-ConstructionConsent-filter', $_SESSION) && count($_SESSION[MFAPPNAME . '-ConstructionConsent-filter'])) {
if(array_key_exists(MFAPPNAME . '-ConstructionConsent-filter', $_SESSION) && count($_SESSION[MFAPPNAME . '-ConstructionConsent-filter'])) {
$filter = $_SESSION[MFAPPNAME . '-ConstructionConsent-filter'];
if(isset($filter['project_id'])) {
$filter_p_id = $filter['project_id'];
if(isset($_SESSION[MFAPPNAME . '-ConstructionConsent-filter-project-' . $filter_p_id])) {
$filter = $_SESSION[MFAPPNAME . '-ConstructionConsent-filter-project-' . $filter_p_id];
}
}
}
}
//var_dump($_SESSION, $filter);exit;
$this->layout->set("filter", $filter);
$filter = $this->getPreparedFilter($filter);
@@ -88,6 +111,65 @@ class ConstructionConsentController extends mfBaseController {
$this->addAction();
}
protected function saveAction() {
$r = $this->request;
//var_dump($r->get());exit;
$id = $r->id;
if(is_numeric($id) && $id > 0) {
$mode = "edit";
$item = new ConstructionConsent($id);
if(!$item->id) {
$this->layout()->setFlash("Zustimmungserklärung nicht gefunden", "error");
$this->redirect("ConstructionConsent");
}
} else {
$id = false;
$mode = "add";
}
$data = [];
$data["constructionconsentproject_id"] = $r->constructionconsentproject_id;
$data["object_type"] = $r->object_type;
$data["name"] = $r->name;
$data["adb_street_id"] = $r->adb_street_id;
$data["ez"] = $r->ez;
$data["kg"] = $r->kg;
$data["gst"] = $r->gst;
$data["gstnr"] = $r->gstnr;
$data["usage_length"] = $r->usage_length;
$data["usage_pipe_on_plot"] = $r->usage_pipe_on_plot;
$data["usage_pipe_in_building"] = $r->usage_pipe_in_building;
$data["usage_manhole"] = $r->usage_manhole;
$data["usage_owner"] = $r->usage_owner;
if($mode == "add") {
$item = ConstructionConsent::create($data);
} else {
$item->update($data);
}
$this->layout()->set("item", $item);
$project = new ConstructionConsentProject($data["constructionconsentproject_id"]);
if(!$project->id) {
$this->layout()->setFlash("Projekt nicht gefunden", "error");
return $this->addAction();
}
if(!$data["object_type"] || !$data["adb_strasse_id"]) {
$this->layout()->setFlash("Bitte alle benötigten Felder ausfüllen", "error");
return $this->addAction();
}
if(!$item->save()) {
$this->layout()->setFlash("Fehler beim Speichern", "error");
return $this->addAction();
}
$this->layout()->setFlash("Zustimmungserklärung erfolgreich gespeichert", "success");
$this->redirect("ConstructionConsent");
}
protected function apiAction() {
if(!$this->me->is(["Admin","netowner"]) && !$this->me->can("Preorder")) {
$this->redirect("Dashboard");