From 9c73bf4faf16c964bbb76b662159d023558d7782 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Wed, 18 Dec 2024 19:49:18 +0100 Subject: [PATCH] WIP ConstructionConsent & update-statusflags script --- Layout/default/ConstructionConsent/Form.php | 71 ++++++++++++++ Layout/default/ConstructionConsent/Index.php | 15 +-- .../ConstructionConsentProject/Index.php | 2 +- .../ConstructionConsentController.php | 92 ++++++++++++++++++- application/Preorder/Preorder.php | 4 +- lib/mvcfronk/mfValuecache/mfValuecache.php | 22 +++++ scripts/preorder/update-statusflags.php | 79 ++++++++++++++++ 7 files changed, 264 insertions(+), 21 deletions(-) create mode 100644 scripts/preorder/update-statusflags.php diff --git a/Layout/default/ConstructionConsent/Form.php b/Layout/default/ConstructionConsent/Form.php index b56f651cc..f4e2caefd 100644 --- a/Layout/default/ConstructionConsent/Form.php +++ b/Layout/default/ConstructionConsent/Form.php @@ -80,6 +80,77 @@ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+

Nutzung

+ +
+ +
+ +
+
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+
diff --git a/Layout/default/ConstructionConsent/Index.php b/Layout/default/ConstructionConsent/Index.php index 3f06749bb..cbd9644c6 100644 --- a/Layout/default/ConstructionConsent/Index.php +++ b/Layout/default/ConstructionConsent/Index.php @@ -36,8 +36,8 @@ $pagination_entity_name = "Zustimmungserklärungen";
@@ -70,17 +70,6 @@ $pagination_entity_name = "Zustimmungserklärungen"; - is("Admin")): ?> -
- -
-
diff --git a/Layout/default/ConstructionConsentProject/Index.php b/Layout/default/ConstructionConsentProject/Index.php index 3e3dbb18d..55ba1fcd5 100644 --- a/Layout/default/ConstructionConsentProject/Index.php +++ b/Layout/default/ConstructionConsentProject/Index.php @@ -85,7 +85,7 @@ $pagination_entity_name = "Zustimmungserklärungsprojekte"; - name?> + ["project_id" => $project->id]])?>">name?> networks) && count($project->networks)): ?>
    diff --git a/application/ConstructionConsent/ConstructionConsentController.php b/application/ConstructionConsent/ConstructionConsentController.php index 403fbb2d5..37b6d8779 100644 --- a/application/ConstructionConsent/ConstructionConsentController.php +++ b/application/ConstructionConsent/ConstructionConsentController.php @@ -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"); diff --git a/application/Preorder/Preorder.php b/application/Preorder/Preorder.php index 3cd2a2fcc..82d1c57d0 100644 --- a/application/Preorder/Preorder.php +++ b/application/Preorder/Preorder.php @@ -62,7 +62,7 @@ class Preorder extends mfBaseModel { if($this->oaid != $old_oaid) { $this->resetSaveNesting(); $this->save(); - return true; + //return true; } //TODO: history start @@ -464,7 +464,7 @@ class Preorder extends mfBaseModel { } $hflagval->value = $flag->value->value; $hflagval->save(); - $this->log->debug(__METHOD__.": Hausnummer flag ".$hflag->code." gespeichert"); + $this->log->debug(__METHOD__.": Hausnummer flag ".$hflag->code." value '".$hflagval->value."' gespeichert"); } // set wohneiheit flag diff --git a/lib/mvcfronk/mfValuecache/mfValuecache.php b/lib/mvcfronk/mfValuecache/mfValuecache.php index 8f25d40ee..e2ee3501b 100644 --- a/lib/mvcfronk/mfValuecache/mfValuecache.php +++ b/lib/mvcfronk/mfValuecache/mfValuecache.php @@ -23,6 +23,7 @@ class mfValuecache { public function set($key, $value) { $this->cache[$key] = $value; + return true; } public function getCache() { @@ -31,6 +32,27 @@ class mfValuecache { public function delete($key) { unset($this->cache[$key]); + return true; + } + + public function purge($beginning = "", $casesensitive = true) { + if(!$beginning) { + $this->cache = []; + return true; + } + + foreach($this->cache as $key => $value) { + if(!$casesensitive) { + if(strpos(strtolower($key), strtolower($beginning)) === 0) { + unset($this->cache[$key]); + } + } + if(strpos($key, $beginning) === 0) { + unset($this->cache[$key]); + } + } + + return true; } public function getMfObject($objectname, $id) { diff --git a/scripts/preorder/update-statusflags.php b/scripts/preorder/update-statusflags.php new file mode 100644 index 000000000..740f01f71 --- /dev/null +++ b/scripts/preorder/update-statusflags.php @@ -0,0 +1,79 @@ +#!/usr/bin/php +id); +define("INTERNAL_USER_USERNAME", $me->username); +define("MFBASE_BYPASS_LOGIN", true); + +$log = mfLoghandler::singleton(); + +$f = 0; +$u = 0; + +$status_codes = [300, 350, 351, 500]; + +$preorders = PreorderModel::searchActive(["status_code" => $status_codes]); +//$preorders = [new Preorder(1138)]; +foreach($preorders as $preorder) { + if(!in_array($preorder->status->code, $status_codes)) continue; + + $updated = false; + foreach(PreorderStatusflagModel::getAll() as $sflag) { + //$preorder = new Preorder($preorder->id); + if(!$sflag->id) { + var_dump($sflag);exit; + } + $sflag_val = PreorderStatusflagValueModel::getFirst(["preorder_id" => $preorder->id, "flag_id" => $sflag->id]); + if(!$sflag_val) { + $sflag_val = PreorderStatusflagValueModel::create([ + "preorder_id" => $preorder->id, + "flag_id" => $sflag->id + ]); + } + + if($sflag_val->value != 1) { + $log->debug(__FILE__.": Setting flag ".$sflag->code." to 1 in Preorder ".$preorder->id); + $sflag_val->value = 1; + $sflag_val->save(); + + $updated = true; + $f++; + + } + + $hflag = ADBStatusflagModel::getFirst(["code" => $sflag->code]); + $hflag_val = ADBHausnummerStatusflagValueModel::getFirst(["hausnummer_id" => $preorder->adb_hausnummer_id, "flag_id" => $hflag->id]); + if(!$hflag_val) { + $hflag_val = ADBHausnummerStatusflagValueModel::create([ + "hausnummer_id" => $preorder->adb_hausnummer_id, + "flag_id" => $hflag->id + ]); + } + if($hflag_val->value != 1) { + $hflag_val->value = 1; + $log->debug(__FILE__.": Setting flag ".$hflag->code." to 1 in Hausnummer ".$preorder->adb_hausnummer_id); + $hflag_val->save(); + } + + mfValuecache::singleton()->purge("mfObjectmodel-Preorder", false); + mfValuecache::singleton()->purge("Preorder", false); + $log->debug("=========================================="); + + } + if($updated) { + $u++; + } +} + +echo "Updated $f Flags for $u Preorders\n";