diff --git a/Layout/default/ConstructionConsentProject/Form.php b/Layout/default/ConstructionConsentProject/Form.php index 610ced431..2dc324781 100644 --- a/Layout/default/ConstructionConsentProject/Form.php +++ b/Layout/default/ConstructionConsentProject/Form.php @@ -90,6 +90,21 @@
+

Berechtigungen

+ +
+ +
+ +
+
+ +
+
@@ -120,12 +135,6 @@ closeOnSelect: false }); - $('#adb_hausnummer_id').on('select2:close', function(e) { - if(!$('#adb_hausnummer_id').val()) { - $('#new-address-toggle').show(); - } - - }); \ No newline at end of file diff --git a/application/ConstructionConsentProject/ConstructionConsentProject.php b/application/ConstructionConsentProject/ConstructionConsentProject.php index d80a96606..00d4ac2ed 100644 --- a/application/ConstructionConsentProject/ConstructionConsentProject.php +++ b/application/ConstructionConsentProject/ConstructionConsentProject.php @@ -4,6 +4,7 @@ class ConstructionConsentProject extends mfBaseModel { private $consents; private $networks; private $adb_networks; + private $addresses; protected function beforeUpdate($data) { if(!array_key_exists("edit_by", $data)) { @@ -18,11 +19,21 @@ class ConstructionConsentProject extends mfBaseModel { public function getProperty($name) { if($this->$name == null) { + if($name == "addresses") { + $addresses = ConstructionConsentProjectAddress::search(["constructionconsentproject_id" => $this->id]); + if(!count($addresses)) { + return []; + } + foreach($addresses as $address) { + $this->addresses[$address->address->id] = $address; + } + return $this->addresses; + } + if($name == "consents") { $consents = ConstructionConsent::search(["constructionconsentproject_id" => $this->id]); if(!$consents) { return []; - } $this->consents = $consents; return $this->consents; diff --git a/application/ConstructionConsentProject/ConstructionConsentProjectController.php b/application/ConstructionConsentProject/ConstructionConsentProjectController.php index 47bdd40a2..744cfc136 100644 --- a/application/ConstructionConsentProject/ConstructionConsentProjectController.php +++ b/application/ConstructionConsentProject/ConstructionConsentProjectController.php @@ -135,30 +135,21 @@ class ConstructionConsentProjectController extends mfBaseController { return $this->addAction(); } - $netzgebiete = []; if(!$project->save()) { $this->layout()->setFlash("Fehler beim Speichern", "error"); return $this->addAction(); } + + // save networks + $netzgebiete = []; foreach($r->adb_netzgebiet_id as $netzgebiet_id) { $netzgebiet = new ADBNetzgebiet($netzgebiet_id); if(!$netzgebiet->id) continue; $netzgebiete[] = $netzgebiet_id; } - - /* - if($mode == "add") { - $project = ConstructionConsentProject::create($data); - } else { - $project->update($data); - }*/ - - - - //save networks foreach($netzgebiete as $netzgebiet_id) { $ccn = ConstructionConsentNetwork::getFirst(["constructionconsentproject_id" => $project->id, "adb_netzgebiet_id" => $netzgebiet_id]); if(!$ccn) { @@ -169,17 +160,40 @@ class ConstructionConsentProjectController extends mfBaseController { $ccn->save(); } } - foreach(ConstructionConsentNetwork::search(["constructionconsentproject_id" => $project->id]) as $ccn) { if(!in_array($ccn->adb_netzgebiet_id, $netzgebiete)) { $ccn->delete(); } } + //var_dump($r->get());exit; + // save addresses + $addresses = []; + foreach($r->address_id as $address_id) { + $address = new Address($address_id); + if(!$address->id) continue; + + $addresses[] = $address_id; + } + foreach($addresses as $address_id) { + $cca = ConstructionConsentProjectAddress::getFirst(["constructionconsentproject_id" => $project->id, "address_id" => $address_id]); + if(!$cca) { + $cca = ConstructionConsentProjectAddress::create([ + "constructionconsentproject_id" => $project->id, + "address_id" => $address_id + ]); + $cca->save(); + } + } + foreach(ConstructionConsentProjectAddress::search(["constructionconsentproject_id" => $project->id]) as $cca) { + if(!in_array($cca->address_id, $addresses)) { + $cca->delete(); + } + } + + $this->layout()->setFlash("Zustimmungserklärungsprojekt erfolgreich gespeichert", "success"); $this->redirect("ConstructionConsentProject"); - - } diff --git a/db/migrations/20250205150003_create_construction_consent_project_address.php b/db/migrations/20250205150003_create_construction_consent_project_address.php new file mode 100644 index 000000000..836f5361f --- /dev/null +++ b/db/migrations/20250205150003_create_construction_consent_project_address.php @@ -0,0 +1,36 @@ +getEnvironment() == "thetool") { + $table = $this->table("ConstructionConsentProjectAddress"); + $table->addColumn("constructionconsentproject_id", "integer", ["null" => false]); + $table->addColumn("address_id", "integer", ["null" => false]); + $table->addColumn("create_by", "integer", ["null" => false]); + $table->addColumn("edit_by", "integer", ["null" => false]); + $table->addColumn("create", "integer", ["null" => false]); + $table->addColumn("edit", "integer", ["null" => false]); + $table->create(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } + + public function down(): void + { + if($this->getEnvironment() == "thetool") { + $this->table("ConstructionConsentProjectAddress")->drop()->save(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } +}