Integrated Contractconfig Hooks in Contractconfig/Save with restore on
error
This commit is contained in:
@@ -57,30 +57,73 @@
|
||||
<div class="card-body">
|
||||
<h4 class="text-center mb-3">Konfiguration bearbeiten</h4>
|
||||
<?php if(is_array($groups) && count($groups)): ?>
|
||||
<form method="post" action="<?=self::getUrl("Contractconfig", "Save")?>">
|
||||
<form id="contract-config-form" method="post" action="<?=self::getUrl("Contractconfig", "Save")?>">
|
||||
<input type="hidden" name="contract_id" value="<?=$contract->id?>" />
|
||||
<table class="table table-sm table-borderless view-table">
|
||||
<?php foreach($groups as $group): ?>
|
||||
<tr class="bg-light">
|
||||
<th><h4><u><?=$group->name?></u></h4></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<?php foreach($group->items as $item): ?>
|
||||
<tr>
|
||||
<th style="max-width: 50vw;"><?=$item->displayname?>:</th>
|
||||
<td style="width: 50vw;">
|
||||
<?php if($item->type == "enum"): ?>
|
||||
<select class="form-control" name="itemvalues[<?=$item->id?>]">
|
||||
<?php foreach($item->getTypedataArray() as $option): ?>
|
||||
<option value="<?=htmlentities($option)?>" <?=($item->getValue() == $option) ? "selected='selected'" : ""?>><?=htmlentities($option)?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php else: ?>
|
||||
<input type="text" class="form-control <?=(is_array($error_items) && in_array($item->id, $error_items)) ? "invalid" : ""?>" name="itemvalues[<?=$item->id?>]" value="<?=(isset($request)) ? htmlentities($request->itemvalues[$item->id]) : htmlentities($item->getValue())?>" />
|
||||
<?php endif; ?>
|
||||
<small><?=$item->description?></small>
|
||||
</td>
|
||||
<tr class="bg-light">
|
||||
<th><h4><u><?=$group->name?></u></h4></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<?php foreach($group->items as $item): ?>
|
||||
<?php
|
||||
$inputname = "itemvalues[".$item->id."]";
|
||||
if($item->multiple) {
|
||||
$inputname .= "[]";
|
||||
}
|
||||
$inputid = "itemvalues_".$item->id;
|
||||
$array_count = 0;
|
||||
?>
|
||||
<?php if($item->multiple): ?>
|
||||
<?php foreach($item->getValue() as $item_value): ?>
|
||||
<tr id="tr-<?=$inputid?>_<?=$array_count?>">
|
||||
<th style="max-width: 50vw;"><?=$item->displayname?><span class="array_counter"> (<?=$array_count + 1?>)</span>:</th>
|
||||
<td style="width: 50vw;">
|
||||
<input type="text"
|
||||
class="form-control <?=(is_array($error_items) && in_array($item->id, $error_items)) ? "invalid" : ""?>"
|
||||
name="<?=$inputname?>"
|
||||
id="<?=$inputid?>_<?=$array_count?>"
|
||||
value="<?=(isset($request)) ? htmlentities($request->itemvalues[$item->id][$array_count]) : htmlentities($item_value)?>"
|
||||
<?=($item->multiple) ? "data-item-multiple='true'" : ""?> />
|
||||
<small><?=$item->description?></small>
|
||||
</td>
|
||||
</tr>
|
||||
<?php $array_count++; ?>
|
||||
<?php endforeach; ?>
|
||||
<tr id="tr-<?=$inputid?>_<?=$array_count?>">
|
||||
<th style="max-width: 50vw;"><?=$item->displayname?><span class="array_counter"> (<?=$array_count + 1?>)</span>:</th>
|
||||
<td style="width: 50vw;">
|
||||
<input type="text"
|
||||
class="form-control <?=(is_array($error_items) && in_array($item->id, $error_items)) ? "invalid" : ""?>"
|
||||
name="<?=$inputname?>"
|
||||
id="<?=$inputid?>_<?=$array_count?>"
|
||||
value="<?=(isset($request)) ? htmlentities($request->itemvalues[$item->id][$array_count]) : ""?>"
|
||||
<?=($item->multiple) ? "data-item-multiple='true'" : ""?> />
|
||||
<small><?=$item->description?></small>
|
||||
</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<tr id="tr-<?=$inputid?>_0">
|
||||
<th style="max-width: 50vw;"><?=$item->displayname?>:</th>
|
||||
<td style="width: 50vw;">
|
||||
<?php if($item->type == "enum"): ?>
|
||||
<select class="form-control" name="<?=$inputname?>" id="<?=$inputid?>" <?=($item->multiple) ? "data-item-multiple='true'" : ""?>>
|
||||
<?php foreach($item->getTypedataArray() as $option): ?>
|
||||
<option value="<?=htmlentities($option)?>" <?=($item->getValue() == $option) ? "selected='selected'" : ""?>><?=htmlentities($option)?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php else: ?>
|
||||
<input type="text"
|
||||
class="form-control <?=(is_array($error_items) && in_array($item->id, $error_items)) ? "invalid" : ""?>"
|
||||
name="<?=$inputname?>"
|
||||
id="<?=$inputid?>_0"
|
||||
value="<?=(isset($request)) ? htmlentities($request->itemvalues[$item->id]) : htmlentities($item->getValue())?>"
|
||||
<?=($item->multiple) ? "data-item-multiple='true'" : ""?> />
|
||||
<?php endif; ?>
|
||||
<small><?=$item->description?></small>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
@@ -105,4 +148,73 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$("#contract-config-form input").each(function() {
|
||||
var input = this;
|
||||
if(!$(input).attr("name")) return;
|
||||
|
||||
//console.log(this);
|
||||
console.log($(input).attr("name"));
|
||||
if($(input).data("item-multiple")) {
|
||||
$(input).change(function() {
|
||||
addMultipleValueField($(this).prop("id"));
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function addMultipleValueField(id) {
|
||||
console.log(id);
|
||||
|
||||
var id_match = id.match(/^itemvalues_(\d+)_(\d+)$/);
|
||||
var elem_id = id_match[1];
|
||||
var last_elem_count = 0;
|
||||
|
||||
var stop = false;
|
||||
|
||||
// find last input
|
||||
$("input[id^=itemvalues_" + elem_id + "_").each(function() {
|
||||
console.log("input id: " + this.id)
|
||||
console.log("value: " + $(this).val());
|
||||
|
||||
if(!$(this).val()) {
|
||||
stop = true;
|
||||
return false;
|
||||
}
|
||||
var this_count_match = this.id.match(/^itemvalues_\d+_(\d+)$/);
|
||||
var this_count = this_count_match[1]
|
||||
if(this_count.length) {
|
||||
console.log("last_elem_count: " + last_elem_count);
|
||||
console.log("this count: " + this_count)
|
||||
last_elem_count = Math.max(this_count, last_elem_count);
|
||||
}
|
||||
});
|
||||
|
||||
if(stop) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!elem_id.length && !last_elem_count.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
var new_tr = $("#tr-" + id).clone();
|
||||
console.log(new_tr);
|
||||
|
||||
var new_count = parseInt(last_elem_count) + 1;
|
||||
new_tr.prop("id", "tr-itemvalues_" + elem_id + "_" + new_count);
|
||||
|
||||
new_tr.find("td input[type=text]").prop("id", "itemvalues_" + elem_id + "_" + new_count);
|
||||
new_tr.find("td input[type=text]").val("");
|
||||
new_tr.find("td input[type=text]").change(function() {
|
||||
addMultipleValueField($(this).prop("id"));
|
||||
});
|
||||
new_tr.find("span.array_counter").text(" (" + (parseInt(new_count) + 1) + ")");
|
||||
$(new_tr).insertAfter($("#tr-" + id));
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>
|
||||
@@ -219,7 +219,7 @@
|
||||
<input type="submit" class="btn btn-purple" value="Speichern" />
|
||||
</div>
|
||||
<div class="col-md-2 float-right text-right">
|
||||
<small><a class="text-danger" href="<?=self::getUrl("Contractconfig", "deleteItem", ['id' => $item->id])?>" onclick="if(!confirm('Attribut wirklich löschen?')) return false;"><i class="fas fa-trash-alt"></i> löschen</a></small>
|
||||
<small><a class="text-danger" href="<?=self::getUrl("ContractconfigItem", "delete", ['id' => $item->id])?>" onclick="if(!confirm('Attribut wirklich löschen?')) return false;"><i class="fas fa-trash-alt"></i> löschen</a></small>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<tr>
|
||||
<th>Nummer</th>
|
||||
<th>Aktiv</th>
|
||||
<th>Contract ID</th>
|
||||
<th>Routing</th>
|
||||
<th>Portierungsstatus</th>
|
||||
<th>Sperre</th>
|
||||
@@ -26,6 +27,7 @@
|
||||
<span class="text-danger"><i class="fas fa-times"></i></span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td><a href="<?=self::getUrl("Contract", "view", ["id" => $num->contract_id])?>"><?=$num->contract_id?></a></td>
|
||||
<td><?=__($num->routing)?></td>
|
||||
<td>
|
||||
<?php if($num->ported_out): ?>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
class ContractconfigController extends mfBaseController {
|
||||
public $hook_errors;
|
||||
|
||||
protected function init() {
|
||||
$this->needlogin=true;
|
||||
@@ -68,13 +69,24 @@ class ContractconfigController extends mfBaseController {
|
||||
|
||||
$error_items = [];
|
||||
|
||||
$old_values = [];
|
||||
|
||||
foreach($r->itemvalues as $item_id => $itemvalue) {
|
||||
//var_dump($item_id, $itemvalue); continue;
|
||||
|
||||
$item = new ContractconfigItem($item_id);
|
||||
if(!$item->id) {
|
||||
$this->log->warn("Tried to save non-existant ContractconfigItem $item_id");
|
||||
continue;
|
||||
}
|
||||
$item->setContractId($contract_id);
|
||||
|
||||
/*if(!array_key_exists($item->name, $old_values)) {
|
||||
$old_values[$item->name] = [];
|
||||
}*/
|
||||
$old_values[$item->name] = $item->getValue();
|
||||
|
||||
|
||||
if(!$item->value->set($itemvalue)) {
|
||||
$error_items[$item->id] = $item->name;
|
||||
continue;
|
||||
@@ -85,6 +97,7 @@ class ContractconfigController extends mfBaseController {
|
||||
return $this->editAction();
|
||||
}
|
||||
}
|
||||
//exit;
|
||||
|
||||
if(count($error_items)) {
|
||||
$this->layout()->set("error_items", array_keys($error_items));
|
||||
@@ -94,12 +107,74 @@ class ContractconfigController extends mfBaseController {
|
||||
}
|
||||
|
||||
// run custom productgroup hooks
|
||||
|
||||
if(!$this->runAfterSaveHooks($contract)) {
|
||||
$errors = [];
|
||||
foreach($this->hook_errors as $item_name => $item_errors) {
|
||||
if(is_array($item_errors) && count($item_errors)) {
|
||||
foreach($item_errors as $error_string) {
|
||||
$errors[] = "[$item_name] $error_string";
|
||||
}
|
||||
//var_dump($old_values[$item_name]);
|
||||
// on error restore old values
|
||||
if(array_key_exists($item_name, $old_values)) {
|
||||
$old_item = ContractconfigItemModel::getFirst(["name" => $item_name]);
|
||||
$old_item->setContractId($contract_id);
|
||||
$old_item->value->set($old_values[$item_name]);
|
||||
$old_item->value->save();
|
||||
//var_dump($old_item->value->json);exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//var_dump($errors);exit;
|
||||
|
||||
|
||||
$this->layout()->setFlash(implode("<br />", $errors), "error");
|
||||
$this->redirect("Contract", "view", ['id' => $contract_id]);
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Konfiguration gespeichert", "success");
|
||||
$this->redirect("Contract", "view", ['id' => $contract_id]);
|
||||
|
||||
}
|
||||
|
||||
private function runAfterSaveHooks(Contract $contract) {
|
||||
if(!$contract || !$contract->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$folderpath = APPDIR."/Contractconfig/hooks/";
|
||||
$dir = opendir($folderpath);
|
||||
while($filename = readdir($dir)) {
|
||||
if(substr($filename, 0, 1) == ".") {
|
||||
continue;
|
||||
}
|
||||
if($filename == "Contractconfig_Hook.php") continue;
|
||||
if(substr($filename, -4) != ".php") continue;
|
||||
|
||||
$hook_type = basename($filename, ".php");
|
||||
$classname = "Contractconfig_Hook_$hook_type";
|
||||
$hook_class_filename = $folderpath.$filename;
|
||||
require_once $hook_class_filename;
|
||||
|
||||
if(!class_exists($classname)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$hook = new $classname($contract);
|
||||
if($hook->isResponsible()) {
|
||||
$this->log->debug("Running {$classname}->afterSave() for Contract id ".$contract->id);
|
||||
$hook->afterSave();
|
||||
if($hook->errors) {
|
||||
$this->hook_errors = $hook->errors;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
abstract class Contractconfig_Hook {
|
||||
protected $log;
|
||||
|
||||
protected $required_product_attributes = [];
|
||||
protected $contract;
|
||||
protected $items;
|
||||
@@ -22,6 +24,8 @@ abstract class Contractconfig_Hook {
|
||||
|
||||
|
||||
public function __construct(Contract $contract) {
|
||||
$this->log = mfLoghandler::singleton();
|
||||
|
||||
$this->contract = $contract;
|
||||
|
||||
if($contract->product) {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__."/Contractconfig_Hook.php";
|
||||
|
||||
class Contractconfig_Hook_Voicenumberblock extends Contractconfig_Hook {
|
||||
protected $required_product_attributes = ["needs_number"];
|
||||
private $voip_routing;
|
||||
|
||||
|
||||
private $create_numbers = [];
|
||||
/*
|
||||
* Checks to determine if class needs to work on contract.
|
||||
*/
|
||||
@@ -24,6 +26,9 @@ class Contractconfig_Hook_Voicenumberblock extends Contractconfig_Hook {
|
||||
}
|
||||
|
||||
public function init() {
|
||||
$this->errors["voicenumberblock_voicenumber"] = [];
|
||||
|
||||
|
||||
// get voip routing for number
|
||||
if(is_array($this->contract->configvalues)) {
|
||||
// look in contract config
|
||||
@@ -39,78 +44,117 @@ class Contractconfig_Hook_Voicenumberblock extends Contractconfig_Hook {
|
||||
}
|
||||
|
||||
public function beforeSave() {
|
||||
|
||||
return $this->checkNewNumbers();
|
||||
}
|
||||
|
||||
public function afterSave() {
|
||||
// check if number was saved
|
||||
if(!array_key_exists("voicenumber", $this->configitems)) {
|
||||
echo "configitem voicenumber does not exists\n";
|
||||
return true;
|
||||
}
|
||||
echo "configitem voicenumber exists\n";
|
||||
$item = $this->configitems['voicenumber'];
|
||||
$number = $item->value->string;
|
||||
if(!$number) {
|
||||
echo "Keine nummer gespeichert\n";
|
||||
return true;
|
||||
}
|
||||
echo "Nummer: $number\n";
|
||||
$this->checkNewNumbers();
|
||||
|
||||
// check if Voicenumber exists
|
||||
$voicenumberblock = Voicenumberblock::findBlock($number);
|
||||
if(!$voicenumberblock) {
|
||||
$this->errors[] = "Ungültige Rufnummer: Kein aktiver Rufnummernblock gefunden";
|
||||
echo "Voicenumberblock für $number nicht gefunden\n";
|
||||
}
|
||||
|
||||
if(!$voicenumberblock->isNumberInBlock($number)) {
|
||||
$this->errors[] = "Ungültige Rufnummer: Bitte Rufnummernlänge kontrollieren! Block erlaubt ".$voicenumberblock->first ." bis ".$voicenumberblock->last;
|
||||
echo "Voicenumber $number not in Block ".$voicenumberblock->prefix."\n";
|
||||
if(count($this->errors["voicenumberblock_voicenumber"])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$voicenumber = VoicenumberModel::getFirst(['number' => $number]);
|
||||
if($voicenumber) {
|
||||
// check if number belongs to another contract
|
||||
if($voicenumber->contract_id) {
|
||||
if($voicenumber->contract_id == $this->contract->id) {
|
||||
// belongs to our contract already => no changes needed
|
||||
return true;
|
||||
foreach($this->create_numbers as $voicenumberblock_id => $numbers) {
|
||||
foreach($numbers as $number){
|
||||
$voicenumber = VoicenumberModel::getFirst(['number' => $number]);
|
||||
|
||||
if(!$voicenumber) {
|
||||
$this->log->debug("creating voicenumber $number in block ".$voicenumberblock->prefix);
|
||||
$voicenumber = VoicenumberModel::create([
|
||||
'voicenumberblock_id' => $voicenumberblock_id,
|
||||
"contract_id" => $this->contract->id,
|
||||
'active' => 1,
|
||||
'activated_date' => date('U'),
|
||||
'routing' => $this->voip_routing,
|
||||
'number' => $number,
|
||||
'disabled' => 0
|
||||
]);
|
||||
if(!$voicenumber->save()) {
|
||||
$this->errors["voicenumberblock_voicenumber"][] = "Error saving new number $number";
|
||||
}
|
||||
}
|
||||
$this->errors[] = "Ungültige Rufnummer: Rufnummer gehört zu bestehendem contract ".$voicenumber->contract_id;
|
||||
return false;
|
||||
}
|
||||
// check if number is locked
|
||||
if($voicenumber->disabled) {
|
||||
$this->errors[] = "Ungültige Rufnummer: Rufnummer ist gesperrt ".$voicenumber->contract_id;
|
||||
return false;
|
||||
}
|
||||
// check if number was ported out
|
||||
if($voicenumber->ported_out) {
|
||||
$this->errors[] = "Ungültige Rufnummer: Rufnummer wurde rausportiert ".$voicenumber->contract_id;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
echo "creating voicenumber $number in block ".$voicenumberblock->prefix."\n";
|
||||
$voicenumber = VoicenumberModel::create([
|
||||
'voicenumberblock_id' => $voicenumberblock->id,
|
||||
"contract_id" => $this->contract->id,
|
||||
'active' => 1,
|
||||
'activated_date' => date('U'),
|
||||
'routing' => $this->voip_routing,
|
||||
'number' => $number,
|
||||
'disabled' => 0
|
||||
]);
|
||||
if(!$voicenumber->save()) {
|
||||
echo "Error saving new number\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(count($this->errors["voicenumberblock_voicenumber"])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: Check if contract was canceled, then set lock and lock_reason to reserved
|
||||
*/
|
||||
public function checkNewNumbers() {
|
||||
$this->log->debug(":: In Contractconfig_Hook_Voicenumberblock->afterSave()");
|
||||
// check if number was saved
|
||||
if(!array_key_exists("voicenumber", $this->configitems)) {
|
||||
$this->log->debug("configitem voicenumber does not exists");
|
||||
return true;
|
||||
}
|
||||
|
||||
$item = $this->configitems['voicenumber'];
|
||||
//var_dump($item);exit;
|
||||
if($item->value->json) {
|
||||
$numbers = json_decode($item->value->json);
|
||||
}
|
||||
|
||||
if(!is_array($numbers) || !count($numbers)) {
|
||||
return true;
|
||||
}
|
||||
foreach($numbers as $number) {
|
||||
if(!$number) {
|
||||
$this->log->debug("Keine nummer gespeichert");
|
||||
continue;
|
||||
}
|
||||
$this->log->debug("Nummer: $number");
|
||||
|
||||
// check if Voicenumber exists
|
||||
$voicenumberblock = Voicenumberblock::findBlock($number);
|
||||
if(!$voicenumberblock) {
|
||||
$this->errors["voicenumberblock_voicenumber"][] = "Ungültige Rufnummer $number: Kein aktiver Rufnummernblock gefunden";
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!$voicenumberblock->isNumberInBlock($number)) {
|
||||
$this->errors["voicenumberblock_voicenumber"][] = "Ungültige Rufnummer $number: Bitte Rufnummernlänge kontrollieren! Block erlaubt ".$voicenumberblock->first ." bis ".$voicenumberblock->last;
|
||||
continue;
|
||||
}
|
||||
|
||||
$voicenumber = VoicenumberModel::getFirst(['number' => $number]);
|
||||
if($voicenumber) {
|
||||
// check if number belongs to another contract
|
||||
if($voicenumber->contract_id) {
|
||||
if($voicenumber->contract_id == $this->contract->id) {
|
||||
// belongs to our contract already => no changes needed
|
||||
continue;
|
||||
}
|
||||
$this->errors["voicenumberblock_voicenumber"][] = "Ungültige Rufnummer $number: Rufnummer gehört zu bestehendem contract ".$voicenumber->contract_id;
|
||||
continue;
|
||||
}
|
||||
// check if number is locked
|
||||
if($voicenumber->disabled) {
|
||||
$this->errors["voicenumberblock_voicenumber"][] = "Ungültige Rufnummer $number: Rufnummer ist gesperrt ".$voicenumber->contract_id;
|
||||
continue;
|
||||
}
|
||||
// check if number was ported out
|
||||
if($voicenumber->ported_out) {
|
||||
$this->errors["voicenumberblock_voicenumber"][] = "Ungültige Rufnummer $number: Rufnummer wurde rausportiert ".$voicenumber->contract_id;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if(!array_key_exists($voicenumberblock->id, $this->create_numbers)) {
|
||||
$this->create_numbers[$voicenumberblock->id] = [];
|
||||
}
|
||||
$this->create_numbers[$voicenumberblock->id][] = $number;
|
||||
}
|
||||
}
|
||||
|
||||
if(count($this->errors["voicenumberblock_voicenumber"])) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,9 @@ class ContractconfigItem extends mfBaseModel {
|
||||
return null;
|
||||
}
|
||||
|
||||
if($this->multiple) {
|
||||
return json_decode($value->json);
|
||||
}
|
||||
if($this->type == "int") {
|
||||
return $value->int;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ class ContractconfigItemController extends mfBaseController {
|
||||
$item_data['type'] = "decimal";
|
||||
break;
|
||||
default:
|
||||
$this->layout()->setFlash("Ungültiger Datentyp!");
|
||||
$this->layout()->setFlash("Ungültiger Datentyp!", "error");
|
||||
$this->redirect("Contractconfiggroup");
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ class ContractconfigItemController extends mfBaseController {
|
||||
$item_id = $item->save();
|
||||
|
||||
if(!$item_id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern!");
|
||||
$this->layout()->setFlash("Fehler beim Speichern!", "error");
|
||||
$this->redirect("Contractconfiggroup");
|
||||
}
|
||||
|
||||
@@ -80,5 +80,35 @@ class ContractconfigItemController extends mfBaseController {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function deleteAction() {
|
||||
$r = $this->request;
|
||||
|
||||
$id = $r->id;
|
||||
if(!is_numeric($id) || $id < 1) {
|
||||
$this->layout()->setFlash("Config Element nicht gefunden!", "error");
|
||||
$this->redirect("Contractconfiggroup");
|
||||
}
|
||||
|
||||
$item = new ContractconfigItem($id);
|
||||
if(!$item->id) {
|
||||
$this->layout()->setFlash("Config Element nicht gefunden!", "error");
|
||||
$this->redirect("Contractconfiggroup");
|
||||
}
|
||||
|
||||
if(ContractconfigValueModel::getFirst(["item_id" => $id])) {
|
||||
$this->layout()->setFlash("Config Element kann nicht gelöscht werden, das es in Verwendung ist!", "error");
|
||||
$this->redirect("Contractconfiggroup");
|
||||
}
|
||||
|
||||
if(!$item->delete()) {
|
||||
$this->layout()->setFlash("Fehler beim Löschen!", "error");
|
||||
$this->redirect("Contractconfiggroup");
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Config Element erfolgreich gelöscht!", "success");
|
||||
$this->redirect("Contractconfiggroup");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ class ContractconfigItemModel {
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
public static function getFirst($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
|
||||
@@ -10,14 +10,29 @@ class ContractconfigValue extends mfBaseModel {
|
||||
$me->loadMe();
|
||||
$this->edit_by = $me->id;
|
||||
|
||||
if($new_value === null || strlen($new_value) == 0) {
|
||||
if(!is_array($new_value) && ($new_value === null || strlen($new_value) == 0)) {
|
||||
$this->int = null;
|
||||
$this->number = null;
|
||||
$this->string = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
if($item->type == "int") {
|
||||
|
||||
if($item->multiple) {
|
||||
if(!is_array($new_value)) {
|
||||
$new_value = [$new_vale];
|
||||
}
|
||||
|
||||
$json_array = [];
|
||||
|
||||
foreach($new_value as $v) {
|
||||
if($v) {
|
||||
$json_array[] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
$this->json = json_encode($json_array);
|
||||
} elseif($item->type == "int") {
|
||||
if(!is_numeric($new_value)) return false;
|
||||
$this->int = $new_value;
|
||||
} elseif($item->type == "decimal") {
|
||||
|
||||
288
scripts/addressdb/lieboch/import-rimo-attributes.php
Normal file
288
scripts/addressdb/lieboch/import-rimo-attributes.php
Normal file
@@ -0,0 +1,288 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
//require 'vendor/autoload.php';
|
||||
require("../../../config/config.php");
|
||||
|
||||
define('FRONKDB_SQLDEBUG',false);
|
||||
error_reporting(E_ALL & ~(E_NOTICE | E_STRICT | E_DEPRECATED));
|
||||
|
||||
require_once(LIBDIR."/mvcfronk/mfRouter/mfRouter.php");
|
||||
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseModel.php");
|
||||
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseController.php");
|
||||
|
||||
|
||||
$netzgebiet_name_main = "Liezen";
|
||||
$freigabe_default = json_encode(["interest", "provision", "order", "reorder"]);
|
||||
|
||||
|
||||
$me = new User(1);
|
||||
|
||||
$folder = __DIR__."/import/";
|
||||
$csvname = "SDIBuilding__Locations__FTTx_premstaetten_2023-03-07.csv";
|
||||
$filename = $folder.$csvname;
|
||||
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
$log = mfLoghandler::singleton();
|
||||
|
||||
$input = fopen($filename, "r");
|
||||
|
||||
$h_extrefs = [];
|
||||
|
||||
$l = 0;
|
||||
$u = 0;
|
||||
while($csv = fgetcsv($input, 0, ";")) {
|
||||
$l++;
|
||||
if($l == 1) continue;
|
||||
|
||||
$hausnummer = false;
|
||||
|
||||
if(!trim($csv[0])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$hausnummer_extref = trim($csv[64]);
|
||||
$adrcd_subcd = trim($csv[46]);
|
||||
$netzgebiet_extref = trim($csv[54]);
|
||||
$grund_nr = trim($csv[73]);
|
||||
//gps_long, gps_lat
|
||||
//$rollout_time = trim($csv[17]);
|
||||
//$rollout_info = trim($csv[18]);
|
||||
//$freigabe = trim($csv[19])
|
||||
$unit_count = trim($csv[78]);
|
||||
$gdaeigenschaft = trim($csv[66]);
|
||||
$fcp_name = trim($csv[49]);
|
||||
|
||||
$execution_state = trim($csv[8]);
|
||||
$btype = trim($csv[30]);
|
||||
|
||||
if(!$netzgebiet_extref) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$netzgebiet = ADBNetzgebietModel::getFirst(["extref" => $netzgebiet_extref]);
|
||||
if(!$netzgebiet) {
|
||||
echo "netzgebiet not found\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
if($execution_state == "Canceled") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if($btype == "Greenfield") {
|
||||
continue;
|
||||
}
|
||||
|
||||
$adrcd = false;
|
||||
if($adrcd_subcd) {
|
||||
$adrparts = explode("-", $adrcd_subcd);
|
||||
$adrcd = $adrparts[0];
|
||||
}
|
||||
|
||||
$gem_name = trim($csv[59]);
|
||||
$plz_string = trim($csv[88]);
|
||||
$ort_name = trim($csv[31]);
|
||||
$strasse_hausnummer = trim($csv[22]);
|
||||
|
||||
$strasse_name = "";
|
||||
$hausnummer_name = "";
|
||||
|
||||
$m = [];
|
||||
if(preg_match('/^(.+)\s+(\d+[a-z0-9\/&#._-]*)(.+)?/i', $strasse_hausnummer, $m)) {
|
||||
$strasse_name = trim($m[1]);
|
||||
$hausnummer_name = trim($m[2]);
|
||||
if(array_key_exists(3, $m)) {
|
||||
$addresszusatz = trim($m[3]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
$adrcd = trim($csv[0]);
|
||||
$gem_kz = trim($csv[2]);
|
||||
$gem_name = trim($csv[3]);
|
||||
$ort_kz = trim($csv[5]);
|
||||
$plz_string = trim($csv[4]);
|
||||
$ort_name = trim($csv[6]);
|
||||
$skz = trim($csv[7]);
|
||||
$strasse_name = trim($csv[8]);
|
||||
$hausnummer_string = trim($csv[9]);
|
||||
$hausnummer_extref = trim($csv[0]);
|
||||
if(in_array($hausnummer_extref, $h_extrefs)) {
|
||||
die("Hausnummer extref doppelt! $hausnummer_extref\n");
|
||||
}
|
||||
$h_extrefs[] = $hausnummer_extref;
|
||||
*/
|
||||
//$lat = str_replace(",",".",trim($csv[7]));
|
||||
//$long = str_replace(",",".",trim($csv[8]));
|
||||
|
||||
|
||||
if(!$adrcd) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!is_numeric($adrcd)) {
|
||||
echo "Invalid adrcd ($adrcd)\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!$hausnummer_extref) {
|
||||
die("!!! Keine Hausnummer Extref\n");
|
||||
}
|
||||
|
||||
|
||||
if($hausnummer_extref == "25012262") {
|
||||
$unit_count = 45;
|
||||
}
|
||||
if($hausnummer_extref == "25012676") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if($hausnummer_extref == "25012153" || $hausnummer_extref == "25012155" || $hausnummer_extref == "25012157") {
|
||||
continue;
|
||||
}
|
||||
if($hausnummer_extref == "25012159") {
|
||||
$unit_count = 61;
|
||||
}
|
||||
|
||||
if($hausnummer_extref == "25010649") {
|
||||
continue;
|
||||
}
|
||||
if($hausnummer_extref == "25010723" || $hausnummer_extref == "25010816") {
|
||||
continue;
|
||||
}
|
||||
|
||||
$existing_hausnummer = ADBHausnummerModel::getFirst(["extref" => $hausnummer_extref]);
|
||||
if(!$existing_hausnummer) {
|
||||
$existing_hausnummer = ADBHausnummerModel::getFirst(["adrcd" => $adrcd]);
|
||||
}
|
||||
if(!$existing_hausnummer) {
|
||||
//echo "$hausnummer_extref not found $strasse_name $hausnummer_name\n";
|
||||
//continue;
|
||||
|
||||
// find hausnummer
|
||||
//echo "$strasse_name $hausnummer_name\n";
|
||||
|
||||
if($strasse_name == "Toepferring") $strasse_name = "Töpferring";
|
||||
if($strasse_name == "Foehrenweg") $strasse_name = "Föhrenweg";
|
||||
|
||||
$strasse_name = $db->escape($strasse_name);
|
||||
$hausnummer_name = $db->escape($hausnummer_name);
|
||||
|
||||
$strasse_search = [$strasse_name];
|
||||
|
||||
if(strpos($strasse_name, ' ') !== false) $strasse_search[] = str_replace(' ', '-', $strasse_name);
|
||||
if(strpos($strasse_name, '-') !== false) $strasse_search[] = str_replace('-', ' ', $strasse_name);
|
||||
if(strpos($strasse_name, '.') !== false) $strasse_search[] = str_replace('.', '. ', $strasse_name);
|
||||
if(strpos($strasse_name, '.') !== false) $strasse_search[] = str_replace('.', '.-', $strasse_name);
|
||||
if(strpos($strasse_name, '. ') !== false) $strasse_search[] = str_replace('. ', '.', $strasse_name);
|
||||
if(strpos($strasse_name, '. ') !== false) $strasse_search[] = str_replace('. ', '.-', $strasse_name);
|
||||
if(strpos($strasse_name, '.') !== false) $strasse_search[] = str_replace('.-', '.', $strasse_name);
|
||||
if(strpos($strasse_name, '.') !== false) $strasse_search[] = str_replace('.-', '. ', $strasse_name);
|
||||
|
||||
foreach($strasse_search as $search) {
|
||||
if(strpos($search, 'ß') !== false) $strasse_search[] = str_replace('ß', 'ss', $search);
|
||||
if(strpos($search, 'ä') !== false) $strasse_search[] = str_replace('ä', 'ae', $search);
|
||||
if(strpos($search, 'ö') !== false) $strasse_search[] = str_replace('ö', 'oe', $search);
|
||||
if(strpos($search, 'ü') !== false) $strasse_search[] = str_replace('ü', 'ue', $search);
|
||||
|
||||
if(strpos($search, 'ss') !== false) $strasse_search[] = str_replace('ss', 'ß', $search);
|
||||
if(strpos($search, 'ae') !== false) $strasse_search[] = str_replace('ae', 'ä', $search);
|
||||
if(strpos($search, 'oe') !== false) $strasse_search[] = str_replace('oe', 'ö', $search);
|
||||
if(strpos($search, 'ue') !== false) $strasse_search[] = str_replace('ue', 'ü', $search);
|
||||
}
|
||||
|
||||
|
||||
$sql = "SELECT * FROM view_hausnummer WHERE gemeinde_id = 1 AND strasse IN ('". implode("', '", $strasse_search)."') AND hausnummer='$hausnummer_name'";
|
||||
$res = $db->query($sql);
|
||||
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$existing_hausnummer = new ADBHausnummer($data->hausnummer_id);
|
||||
$existing_hausnummer->netzgebiet_id = $netzgebiet->id;
|
||||
|
||||
if(!$existing_hausnummer->adrcd) {
|
||||
$existing_hausnummer->adrcd = $adrcd;
|
||||
}
|
||||
|
||||
$existing_hausnummer->extref = $hausnummer_extref;
|
||||
$existing_hausnummer->grund_nr = $grund_nr;
|
||||
$existing_hausnummer->gdaeigenschaft = $gdaeigenschaft;
|
||||
$existing_hausnummer->rimo_fcp_name = $fcp_name;
|
||||
if(!$existing_hausnummer->oaid) {
|
||||
$existing_hausnummer->oaid = $existing_hausnummer->getNewOAID();
|
||||
}
|
||||
$existing_hausnummer->save();
|
||||
|
||||
} else {
|
||||
echo "Address not found (straße: $strasse_name, hausnummer: $hausnummer_name, adrcd: $adrcd, extref: $hausnummer_extref, unit_count: $unit_count)\n";
|
||||
}
|
||||
} else {
|
||||
// found hausnummer
|
||||
$existing_hausnummer->netzgebiet_id = $netzgebiet->id;
|
||||
if(!$existing_hausnummer->adrcd) {
|
||||
$existing_hausnummer->adrcd = $adrcd;
|
||||
}
|
||||
|
||||
$existing_hausnummer->extref = $hausnummer_extref;
|
||||
$existing_hausnummer->grund_nr = $grund_nr;
|
||||
$existing_hausnummer->gdaeigenschaft = $gdaeigenschaft;
|
||||
$existing_hausnummer->rimo_fcp_name = $fcp_name;
|
||||
if(!$existing_hausnummer->oaid) {
|
||||
$existing_hausnummer->oaid = $existing_hausnummer->getNewOAID();
|
||||
}
|
||||
$existing_hausnummer->save();
|
||||
}
|
||||
continue;
|
||||
|
||||
// add new units
|
||||
$existing_units_count = ADBWohneinheitModel::count(['hausnummer_id' => $existing_hausnummer->id]);
|
||||
if($existing_units_count != $unit_count) {
|
||||
/*if(($existing_units_count - $unit_count) > 1) {
|
||||
echo "========================================================================\n";
|
||||
echo "=============== [".$existing_hausnummer->id."] Need to delete ".($existing_units_count - $unit_count)." units\n";
|
||||
echo "========================================================================\n";
|
||||
}*/
|
||||
if($existing_units_count < $unit_count) {
|
||||
echo "=============== Adding ".($unit_count - $existing_units_count)." units\n";
|
||||
|
||||
$new_units_count = $unit_count - $existing_units_count;
|
||||
$last_unit_num = 0;
|
||||
|
||||
|
||||
foreach(ADBWohneinheitModel::search(['hausnummer_id' => $existing_hausnummer->id]) as $tmp_unit) {
|
||||
if($tmp_unit->num > $last_unit_num) {
|
||||
$last_unit_num = $tmp_unit->num;
|
||||
}
|
||||
}
|
||||
|
||||
// create wohneinheiten
|
||||
for($i = 1; $i <= $new_units_count; $i++) {
|
||||
$num = $last_unit_num + $i;
|
||||
//echo "$existing_units_count create wohneinheit $num\n";
|
||||
$unit_data = [
|
||||
'hausnummer_id' => $existing_hausnummer->id,
|
||||
'num' => $num,
|
||||
];
|
||||
$wohneinheit = ADBWohneinheitModel::create($unit_data);
|
||||
$wohneinheit_id = $wohneinheit->save();
|
||||
if(!$wohneinheit_id) {
|
||||
die("Cannot save Wohneinheit\n");
|
||||
}
|
||||
$wohneinheit->oaid = $wohneinheit->getNewOAID();
|
||||
if(!$wohneinheit->oaid) {
|
||||
die("Error generating OAID for wohneinheit ".$wohneinheit->id);
|
||||
}
|
||||
//var_dump($wohneinheit);
|
||||
$wohneinheit->save();
|
||||
$w++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//echo "$hausnummer_extref: $adrcd, $netzgebiet_extref, $grund_nr, $unit_count, $gdaeigenschaft\n";
|
||||
|
||||
}
|
||||
2946
scripts/addressdb/lieboch/import/GWR_Lieboch_gesamt.csv
Normal file
2946
scripts/addressdb/lieboch/import/GWR_Lieboch_gesamt.csv
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
251
scripts/addressdb/lieboch/import_from_gemeinde_gwr.php
Normal file
251
scripts/addressdb/lieboch/import_from_gemeinde_gwr.php
Normal file
@@ -0,0 +1,251 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
//require 'vendor/autoload.php';
|
||||
require("../../../config/config.php");
|
||||
|
||||
define('FRONKDB_SQLDEBUG',false);
|
||||
error_reporting(E_ALL & ~(E_NOTICE | E_STRICT | E_DEPRECATED));
|
||||
|
||||
require_once(LIBDIR."/mvcfronk/mfRouter/mfRouter.php");
|
||||
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseModel.php");
|
||||
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseController.php");
|
||||
|
||||
|
||||
$freigabe_default = json_encode(["interest", "provision", "order", "reorder"]);
|
||||
|
||||
$me = new User(1);
|
||||
|
||||
$folder = __DIR__."/import/";
|
||||
$csvname = "GWR_Lieboch_gesamt.csv";
|
||||
$filename = $folder.$csvname;
|
||||
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
$log = mfLoghandler::singleton();
|
||||
|
||||
$input = fopen($filename, "r");
|
||||
|
||||
$h_extrefs = [];
|
||||
|
||||
|
||||
$gem_kz = "";
|
||||
$gem_name = "";
|
||||
$ort_kz = "";
|
||||
$plz_name = "";
|
||||
$ort_name = "";
|
||||
$strasse_hausnummer = "";
|
||||
$strasse_building = "";
|
||||
$strasse_name = "";
|
||||
$strasse = "";
|
||||
$addresszusatz = "";
|
||||
$adrcd = "";
|
||||
$hausnummer_name = "";
|
||||
$hausnummer_extref = "";
|
||||
|
||||
// netzgebiet Lieboch
|
||||
$netzgebiet = new ADBNetzgebiet(30);
|
||||
|
||||
$l = 0;
|
||||
$u = 0;
|
||||
$i = 0;
|
||||
while($csv = fgetcsv($input, 0, ",")) {
|
||||
$i++;
|
||||
if($i == 1) continue;
|
||||
|
||||
//var_dump($csv);exit;
|
||||
|
||||
|
||||
if(trim($csv[0])) {
|
||||
$gem_kz = trim($csv[0]);
|
||||
$gem_name = trim($csv[1]);
|
||||
$ort_kz = "14994";
|
||||
$plz_name = "8501";
|
||||
$ort_name = "Lieboch";
|
||||
$strasse_hausnummer = trim($csv[4]);
|
||||
//$strasse_name = trim($csv[13]);
|
||||
$adrcd = trim($csv[8]);
|
||||
$hausnummer_extref = trim($csv[12]);
|
||||
//echo "strasse: $strasse\n";
|
||||
//echo "strasse_building: $strasse_building\n";
|
||||
|
||||
$strasse_name = "";
|
||||
$hausnummer_name = "";
|
||||
$addresszusatz = "";
|
||||
|
||||
//echo $strasse_hausnummer."\n";
|
||||
if(preg_match('/^(.+)\s+(\d+[a-z0-9\/&#._-]*)/i', $strasse_hausnummer, $m)) {
|
||||
$strasse_name = trim($m[1]);
|
||||
$hausnummer_name = trim($m[2]);
|
||||
if(array_key_exists(3, $m)) {
|
||||
$addresszusatz = trim($m[3]);
|
||||
}
|
||||
}
|
||||
//echo "$strasse_name $hausnummer_name\n";
|
||||
}
|
||||
|
||||
if(!$strasse_name || !$hausnummer_name) {
|
||||
echo "no strasse_name ($strasse_name) or hausnummer_name ($hausnummer_name)\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$strasse_we = trim($csv[13]);
|
||||
//$nutzung = trim($csv[8]);
|
||||
$we_num = trim($csv[17]);
|
||||
|
||||
if(!$strasse_we) {
|
||||
echo "Adresse Wohneinheit fehlt.\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
//echo "strasse_we: $strasse_we\n";
|
||||
if($strasse_hausnummer == $strasse_we) {
|
||||
$addresszusatz = "";
|
||||
} else {
|
||||
$addresszusatz = preg_replace('/^'.$strasse_hausnummer.'\s+/', "", $strasse_we);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$hausnummer_zusatz = ADBWohneinheit::parseHausnummerZusatz($addresszusatz);
|
||||
//var_dump($hausnummer_zusatz);
|
||||
|
||||
echo "Gemeinde: $gem_name | PLZ: $plz_name | Ort: $ort_name | Strasse: $strasse_name | Hausnummer: $hausnummer_name | Zusatz: ";
|
||||
|
||||
foreach($hausnummer_zusatz as $key => $value) {
|
||||
if($value) {
|
||||
if($key == "zusatz") {
|
||||
echo $value;
|
||||
continue;
|
||||
}
|
||||
echo ucfirst($key)." ".$value;
|
||||
}
|
||||
}
|
||||
echo "\n";
|
||||
|
||||
//continue;
|
||||
|
||||
$gemeinde = ADBGemeindeModel::getFirst(['kennziffer' => $gem_kz]);
|
||||
if(!$gemeinde) {
|
||||
die("Gemeinde $gem_kz nicht gefunden\n");
|
||||
/*$gemeinde = new ADBGemeinde();
|
||||
$gemeinde->kennziffer = $gem_kz;
|
||||
$gemeinde->code = $gem_kz;
|
||||
$gemeinde->name = $gem_name;
|
||||
$gemeinde_id = $gemeinde->save();
|
||||
if(!$gemeinde_id) {
|
||||
|
||||
}*/
|
||||
}
|
||||
|
||||
$ort = ADBOrtschaftModel::getFirst(['kennziffer' => $ort_kz]);
|
||||
if(!$ort) {
|
||||
die("Ortschaft $ort_kz nicht gefunden\n");
|
||||
/*$ort = new ADBOrtschaft();
|
||||
$ort->gemeinde_id = $gemeinde->id;
|
||||
$ort->kennziffer = $ort_kz;
|
||||
$ort->name = $ort_name;
|
||||
$ort->plz = $plz_name;
|
||||
$ort_id = $ort->save();
|
||||
if(!$ort_id) {
|
||||
die("Error creating Ortschaft $ort_kz $ort_name!\n");
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
$plz = ADBPlzModel::getFirst(['plz' => $plz_name]);
|
||||
if(!$plz) {
|
||||
die("PLZ $plz_name nicht gefunden\n");
|
||||
/*$plz = new ADBPlz();
|
||||
$plz->plz = $plz_name;
|
||||
$plz->plzstring = $plz_name;
|
||||
$plz_id = $plz->save();
|
||||
if(!$plz) {
|
||||
die("Error creating Plz $plz_name!\n");
|
||||
}*/
|
||||
}
|
||||
//var_dump($plz);exit;
|
||||
|
||||
|
||||
$strasse = ADBStrasseModel::getFirst(['gemeinde_id' => $gemeinde->id, 'name' => $strasse_name]);
|
||||
if(!$strasse) {
|
||||
die("Strasse $strasse_name nicht gefunden\n");
|
||||
/*$strasse = new ADBStrasse();
|
||||
$strasse->ortschaft_id = $ort->id;
|
||||
$strasse->gemeinde_id = $gemeinde->id;
|
||||
$strasse->name = $strasse_name;
|
||||
$strasse_id = $strasse->save();
|
||||
if(!$strasse_id) {
|
||||
die("error creating Strasse $strasse_name (gemeinde ".$gemeinde->id.", ort ".$ort->id.")");
|
||||
}*/
|
||||
}
|
||||
//var_dump($strasse);exit;
|
||||
|
||||
$hausnummer = ADBHausnummerModel::getFirst(['adrcd' => $adrcd]);
|
||||
|
||||
if(!$hausnummer) {
|
||||
$hausnummer = ADBHausnummerModel::getFirst(['strasse_id' => $strasse->id, 'hausnummer' => $hausnummer_name]);
|
||||
}
|
||||
|
||||
if(!$hausnummer) {
|
||||
$hausnummer = new ADBHausnummer();
|
||||
$hausnummer->adrcd = $adrcd;
|
||||
$hausnummer->plz_id = $plz->id;
|
||||
$hausnummer->strasse_id = $strasse->id;
|
||||
$hausnummer->ortschaft_id = $ort->id;
|
||||
$hausnummer->hausnummer = $hausnummer_name;
|
||||
}
|
||||
|
||||
$hausnummer->netzgebiet_id = $netzgebiet->id;
|
||||
$hausnummer->extref = $hausnummer_extref;
|
||||
$hausnummer->freigabe = $freigabe_default;
|
||||
|
||||
$hausnummer_id = $hausnummer->save();
|
||||
if(!$hausnummer_id) {
|
||||
die("error creating Hausnummer $strasse_name $hausnummer_name\n");
|
||||
}
|
||||
$hausnummer->oaid = $hausnummer->getNewOAID();
|
||||
if(!$hausnummer->save()) {
|
||||
die("Cannot save oaid $strasse_name $hausnummer_name\n");
|
||||
}
|
||||
//var_dump($hausnummer);exit;
|
||||
|
||||
|
||||
$we_search = [
|
||||
'hausnummer_id' => $hausnummer->id,
|
||||
'num' => $we_num,
|
||||
'block' => $hausnummer_zusatz['block'],
|
||||
'stiege' => $hausnummer_zusatz['stiege'],
|
||||
'stock' => $hausnummer_zusatz['stock'],
|
||||
'tuer' => $hausnummer_zusatz['tuer'],
|
||||
'zusatz' => $hausnummer_zusatz['zusatz'],
|
||||
];
|
||||
|
||||
$wohneinheit = ADBWohneinheitModel::getFirst($we_search);
|
||||
if(!$wohneinheit) {
|
||||
$wohneinheit = new ADBWohneinheit();
|
||||
$wohneinheit->hausnummer_id = $hausnummer->id;
|
||||
$wohneinheit->num = $we_num;
|
||||
$wohneinheit->block = ($hausnummer_zusatz['block']) ? $hausnummer_zusatz['block'] : null;
|
||||
$wohneinheit->stiege = ($hausnummer_zusatz['stiege']) ? $hausnummer_zusatz['stiege'] : null;
|
||||
$wohneinheit->stock = ($hausnummer_zusatz['stock']) ? $hausnummer_zusatz['stock'] : null;
|
||||
$wohneinheit->tuer = ($hausnummer_zusatz['tuer']) ? $hausnummer_zusatz['tuer'] : null;
|
||||
$wohneinheit->zusatz = ($hausnummer_zusatz['zusatz']) ? $hausnummer_zusatz['zusatz'] : null;
|
||||
//$wohneinheit->nutzung = $nutzung;
|
||||
$wohneinheit_id = $wohneinheit->save();
|
||||
if(!$wohneinheit_id) {
|
||||
die("error creating Wohneinheit $strasse_name $hausnummer_name ".implode(", ", $hausnummer_zusatz));
|
||||
}
|
||||
$wohneinheit->oaid = $wohneinheit->getNewOAID();
|
||||
if(!$wohneinheit->save()) {
|
||||
die("cannot save oaid $strasse_name $hausnummer_name\n" . print_r($wohneinheit,true));
|
||||
}
|
||||
} else {
|
||||
echo "XXXX wohneinheit gibts schon: $strasse_name $hausnummer_name ".implode(", ", $hausnummer_zusatz)."\n\n";
|
||||
}
|
||||
|
||||
|
||||
/*if($i > 10) {
|
||||
exit;
|
||||
}*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user