ConstructionConsentProject: Added company permissions

This commit is contained in:
Frank Schubert
2025-02-11 14:32:02 +01:00
parent 3520642930
commit b5124f3dab
4 changed files with 92 additions and 22 deletions

View File

@@ -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");
}