ConstructionConsentProject: Added company permissions
This commit is contained in:
@@ -90,6 +90,21 @@
|
||||
|
||||
<hr class="mt-3 mb-3" />
|
||||
|
||||
<h4>Berechtigungen</h4>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="sender_reply_to">Berechtigte Firmen</label>
|
||||
<div class="col-lg-10">
|
||||
<select class="form-control select2" name="address_id[]" id="adb_hausnummer_id" multiple="multiple">
|
||||
<?php foreach(AddressModel::search(["addresstype" => TT_NETWORK_ROLES_WITH_OWNER]) as $address): ?>
|
||||
<option value="<?=$address->id?>" <?=(array_key_exists($address->id, $project->addresses)) ? "selected='selected'" : ""?>><?=$address->getCompanyOrName()?><?=($address->customer_number) ? " (".$address->customer_number.")" : ""?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="mt-3 mb-3" />
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="note">Interne Notiz</label>
|
||||
<div class="col-lg-10">
|
||||
@@ -120,12 +135,6 @@
|
||||
closeOnSelect: false
|
||||
});
|
||||
|
||||
$('#adb_hausnummer_id').on('select2:close', function(e) {
|
||||
if(!$('#adb_hausnummer_id').val()) {
|
||||
$('#new-address-toggle').show();
|
||||
}
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php include(realpath(dirname(__FILE__) . "/../../$mfLayoutPackage") . "/footer.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;
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateConstructionConsentProjectAddress extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if($this->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") {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user