548 lines
21 KiB
PHP
548 lines
21 KiB
PHP
<?php
|
|
|
|
class AddressDB {
|
|
private $db;
|
|
private $log;
|
|
|
|
public $validation_error = [];
|
|
public static $wohneinheit_query = "SELECT `Netzgebiet`.`id` AS `netzgebiet_id`,
|
|
`Netzgebiet`.`name` AS `netzgebiet`,
|
|
`Netzgebiet`.`extref` AS `netzgebiet_extref`,
|
|
`Gemeinde`.`id` AS `gemeinde_id`,
|
|
`Gemeinde`.`kennziffer` AS `gemeinde_kennziffer`,
|
|
`Gemeinde`.`code` AS `gemeinde_code`,
|
|
`Gemeinde`.`name` AS `gemeinde`,
|
|
`Ortschaft`.`id` AS `ortschaft_id`,
|
|
`Ortschaft`.`kennziffer` AS `ortschaft_kennziffer`,
|
|
`Ortschaft`.`name` AS `ortschaft`,
|
|
`Plz`.`plz` AS `plz`,
|
|
`Strasse`.`id` AS `strasse_id`,
|
|
`Strasse`.`kennziffer` AS `strasse_kennziffer`,
|
|
`Strasse`.`name` AS `strasse`,
|
|
`Hausnummer`.`id` AS `hausnummer_id`,
|
|
`Hausnummer`.`status_id` AS `status_id`,
|
|
`Hausnummer`.`oaid` AS `hausnummer_oaid`,
|
|
`Hausnummer`.`adrcd` AS `adrcd`,
|
|
`Hausnummer`.`subcd` AS `subcd`,
|
|
`Hausnummer`.`hausnummer` AS `hausnummer`,
|
|
`Hausnummer`.`stiege` AS `hausnummer_stiege`,
|
|
`Hausnummer`.`extref` AS `hausnummer_extref`,
|
|
`Hausnummer`.`unit_count` AS `unit_count`,
|
|
`Hausnummer`.`gps_lat` AS `gps_lat`,
|
|
`Hausnummer`.`gps_long` AS `gps_long`,
|
|
`Hausnummer`.`grund_nr` AS `grund_nr`,
|
|
`Hausnummer`.`gdaeigenschaft` AS `gdaeigenschaft`,
|
|
`Hausnummer`.`rw` AS `rw`,
|
|
`Hausnummer`.`hw` AS `hw`,
|
|
`Hausnummer`.`meridian` AS `meridian`,
|
|
`Hausnummer`.`rollout` AS `rollout`,
|
|
`Hausnummer`.`rollout_info` AS `rollout_info`,
|
|
`Hausnummer`.`freigabe` AS `freigabe`,
|
|
`Hausnummer`.`visibility` AS `visibility`,
|
|
`Hausnummer`.`rimo_id` AS `hausnummer_rimo_id`,
|
|
`Hausnummer`.`rimo_type` AS `hausnummer_rimo_type`,
|
|
`Hausnummer`.`rimo_ex_state` AS `hausnummer_rimo_ex_state`,
|
|
`Hausnummer`.`rimo_op_state` AS `hausnummer_rimo_op_state`,
|
|
`Hausnummer`.`rimo_fcp_name` AS `rimo_fcp_name`,
|
|
`Hausnummer`.`borderpoint_lat` AS `borderpoint_lat`,
|
|
`Hausnummer`.`borderpoint_long` AS `borderpoint_long`,
|
|
`Wohneinheit`.`id` AS `wohneinheit_id`,
|
|
`Wohneinheit`.`status_id` AS `wohneinheit_status_id`,
|
|
`Wohneinheit`.`oaid` AS `wohneinheit_oaid`,
|
|
`Wohneinheit`.`extref` AS `wohneinheit_extref`,
|
|
`Wohneinheit`.`num` AS `num`,
|
|
`Wohneinheit`.`block` AS `block`,
|
|
`Wohneinheit`.`stiege` AS `stiege`,
|
|
`Wohneinheit`.`stock` AS `stock`,
|
|
`Wohneinheit`.`tuer` AS `tuer`,
|
|
`Wohneinheit`.`bezeichner` AS `bezeichner`,
|
|
`Wohneinheit`.`zusatz` AS `zusatz`,
|
|
`Wohneinheit`.`nutzung` AS `nutzung`,
|
|
`Wohneinheit`.`rimo_ex_state` AS `wohneinheit_rimo_ex_state`,
|
|
`Wohneinheit`.`rimo_op_state` AS `wohneinheit_rimo_op_state`,
|
|
`Wohneinheit`.`patch_cluster` AS `patch_cluster`,
|
|
`Wohneinheit`.`patch_shelf` AS `patch_shelf`,
|
|
`Wohneinheit`.`patch_module` AS `patch_module`,
|
|
`Wohneinheit`.`patch_port` AS `patch_port`,
|
|
tbl_preorder.type AS `order_type`,
|
|
tbl_address.id AS `partner_id`,
|
|
tbl_address.company AS `partner_company`
|
|
FROM `Hausnummer`
|
|
LEFT JOIN `Netzgebiet` ON (`Hausnummer`.`netzgebiet_id` = `Netzgebiet`.`id`)
|
|
LEFT JOIN `Plz` ON (`Plz`.`id` = `Hausnummer`.`plz_id`)
|
|
LEFT JOIN `Strasse` ON (`Strasse`.`id` = `Hausnummer`.`strasse_id`)
|
|
LEFT JOIN `Ortschaft` ON (`Ortschaft`.`id` = `Hausnummer`.`ortschaft_id`)
|
|
LEFT JOIN `Gemeinde` ON (`Gemeinde`.`id` = `Strasse`.`gemeinde_id`)
|
|
LEFT JOIN `Wohneinheit` ON (`Wohneinheit`.`hausnummer_id` = `Hausnummer`.`id`)
|
|
LEFT JOIN `".FRONKDB_DBNAME."`.`Preorder` as tbl_preorder on (tbl_preorder.`adb_wohneinheit_id` = `Wohneinheit`.`id` AND (tbl_preorder.`deleted` = 0 OR tbl_preorder.`deleted` IS NULL))
|
|
LEFT JOIN `".FRONKDB_DBNAME."`.`Address` as tbl_address on (tbl_address.`id` = tbl_preorder.partner_id)
|
|
";
|
|
|
|
/*public static $wohneinheit_query = "select `Netzgebiet`.`id` AS `netzgebiet_id`,
|
|
`Netzgebiet`.`name` AS `netzgebiet`,
|
|
`Netzgebiet`.`extref` AS `netzgebiet_extref`,
|
|
`Gemeinde`.`id` AS `gemeinde_id`,
|
|
`Gemeinde`.`kennziffer` AS `gemeinde_kennziffer`,
|
|
`Gemeinde`.`code` AS `gemeinde_code`,
|
|
`Gemeinde`.`name` AS `gemeinde`,
|
|
`Ortschaft`.`id` AS `ortschaft_id`,
|
|
`Ortschaft`.`kennziffer` AS `ortschaft_kennziffer`,
|
|
`Ortschaft`.`name` AS `ortschaft`,
|
|
`Plz`.`plz` AS `plz`,
|
|
`Strasse`.`id` AS `strasse_id`,
|
|
`Strasse`.`kennziffer` AS `strasse_kennziffer`,
|
|
`Strasse`.`name` AS `strasse`,
|
|
`Hausnummer`.`id` AS `hausnummer_id`,
|
|
`Hausnummer`.`oaid` AS `oaid`,
|
|
`Hausnummer`.`adrcd` AS `adrcd`,
|
|
`Hausnummer`.`subcd` AS `subcd`,
|
|
`Hausnummer`.`oaid` AS `hausnummer_oaid`,
|
|
`Hausnummer`.`hausnummer` AS `hausnummer`,
|
|
`Hausnummer`.`stiege` AS `hausnummer_stiege`,
|
|
`Hausnummer`.`extref` AS `hausnummer_extref`,
|
|
`Hausnummer`.`unit_count` AS `unit_count`,
|
|
`Hausnummer`.`meridian` AS `meridian`,
|
|
`Hausnummer`.`rw` AS `rw`,
|
|
`Hausnummer`.`hw` AS `hw`,
|
|
`Hausnummer`.`gps_lat` AS `gps_lat`,
|
|
`Hausnummer`.`gps_long` AS `gps_long`,
|
|
`Hausnummer`.`grund_nr` AS `grund_nr`,
|
|
`Hausnummer`.`rollout` AS `rollout`,
|
|
`Hausnummer`.`rollout_info` AS `rollout_info`,
|
|
`Hausnummer`.`freigabe` AS `freigabe`,
|
|
`Hausnummer`.`visibility` AS `visibility`,
|
|
`Hausnummer`.`rimo_id` AS `hausnummer_rimo_id`,
|
|
`Hausnummer`.`rimo_fcp_name` AS `rimo_fcp_name`,
|
|
`Wohneinheit`.`id` AS `wohneinheit_id`,
|
|
`Wohneinheit`.`oaid` AS `wohneinheit_oaid`,
|
|
`Wohneinheit`.`extref` AS `wohneinheit_extref`,
|
|
`Wohneinheit`.`num` AS `num`,
|
|
`Wohneinheit`.`block` AS `block`,
|
|
`Wohneinheit`.`stiege` AS `stiege`,
|
|
`Wohneinheit`.`stock` AS `stock`,
|
|
`Wohneinheit`.`tuer` AS `tuer`,
|
|
`Wohneinheit`.`bezeichner` AS `bezeichner`,
|
|
`Wohneinheit`.`zusatz` AS `zusatz`,
|
|
`Wohneinheit`.`nutzung` AS `nutzung`,
|
|
tbl_preorder.type AS `order_type`,
|
|
tbl_address.id AS `partner_id`,
|
|
tbl_address.company AS `partner_company`
|
|
from `Hausnummer`
|
|
left join `Netzgebiet` on (`Hausnummer`.`netzgebiet_id` = `Netzgebiet`.`id`)
|
|
left join `Plz` on (`Plz`.`id` = `Hausnummer`.`plz_id`)
|
|
left join `Strasse` on (`Strasse`.`id` = `Hausnummer`.`strasse_id`)
|
|
left join `Ortschaft` on (`Ortschaft`.`id` = `Hausnummer`.`ortschaft_id`)
|
|
left join `Gemeinde` on (`Gemeinde`.`id` = `Strasse`.`gemeinde_id`)
|
|
left join `Wohneinheit` on (`Wohneinheit`.`hausnummer_id` = `Hausnummer`.`id`)
|
|
left join `".FRONKDB_DBNAME."`.`Preorder` as tbl_preorder on (tbl_preorder.`adb_wohneinheit_id` = `Wohneinheit`.`id` AND (tbl_preorder.`deleted` = 0 OR tbl_preorder.`deleted` IS NULL))
|
|
left join `".FRONKDB_DBNAME."`.`Address` as tbl_address on (tbl_address.`id` = tbl_preorder.partner_id)
|
|
";*/
|
|
|
|
public function __construct() {
|
|
$this->db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
|
$this->log = mfLoghandler::singleton();
|
|
}
|
|
|
|
public static function handleRimoStatusUpdate($wohneinheit_id) {
|
|
if(!$wohneinheit_id) return true;
|
|
|
|
$log = mfLoghandler::singleton();
|
|
$log->debug(__METHOD__.": =============================== in handleRimoStatusUpdate");
|
|
|
|
$wohneinheit = new ADBWohneinheit($wohneinheit_id);
|
|
if(!$wohneinheit->id) {
|
|
//echo "no wohneinheit\n";
|
|
return false;
|
|
}
|
|
|
|
$hausnummer = $wohneinheit->hausnummer;
|
|
if(!$hausnummer->netzgebiet->getOption("statuschange")) {
|
|
//echo "no option statuschange\n";
|
|
return true;
|
|
}
|
|
|
|
$order_type = false;
|
|
|
|
$preorder = PreorderModel::getFirstActive(["adb_wohneinheit_id" => $wohneinheit->id]);
|
|
if($preorder) {
|
|
$order_type = $preorder->type;
|
|
}
|
|
/*if(!$preorder) {
|
|
echo "no preorder\n";
|
|
return true;
|
|
}*/
|
|
|
|
$b_ex_state = strtolower($hausnummer->rimo_ex_state);
|
|
$b_op_state = strtolower($hausnummer->rimo_op_state);
|
|
|
|
$h_ex_state = strtolower($wohneinheit->rimo_ex_state);
|
|
$h_op_state = strtolower($wohneinheit->rimo_op_state);
|
|
|
|
$wo_state = false;
|
|
$workorder = $wohneinheit->rimo_workorder;
|
|
if($workorder) {
|
|
$wo_state = strtolower($workorder->rimo_status);
|
|
}
|
|
|
|
|
|
|
|
|
|
$status_matrix = array_reverse(TT_PREORDER_RIMO_STATUS_MATRIX);
|
|
|
|
|
|
$log->debug(__METHOD__.": b_ex_state: ".$b_ex_state);
|
|
$log->debug(__METHOD__.": b_op_state: ".$b_op_state);
|
|
$log->debug(__METHOD__.": h_ex_state: ".$h_ex_state);
|
|
$log->debug(__METHOD__.": h_op_state: ".$h_op_state);
|
|
$log->debug(__METHOD__.": wo_state: ".$wo_state);
|
|
$log->debug(__METHOD__.": order_type: ".$order_type);
|
|
|
|
|
|
foreach($status_matrix as $matrix) {
|
|
//var_dump($matrix);
|
|
if($matrix["rbop"]) {
|
|
if(!is_array($matrix["rbop"])) $matrix["rbop"] = [$matrix["rbop"]];
|
|
if(!in_array($b_op_state, $matrix["rbop"])) continue;
|
|
}
|
|
if($matrix["rbex"] && $matrix["rbex"] != $b_ex_state) {
|
|
if(!is_array($matrix["rbex"])) $matrix["rbex"] = [$matrix["rbex"]];
|
|
if(!in_array($b_ex_state, $matrix["rbex"])) continue;
|
|
};
|
|
|
|
if($matrix["rhop"] && $matrix["rhop"] != $h_op_state) {
|
|
if(!is_array($matrix["rhop"])) $matrix["rhop"] = [$matrix["rhop"]];
|
|
if(!in_array($h_op_state, $matrix["rhop"])) continue;
|
|
};
|
|
if($matrix["rhex"] && $matrix["rhex"] != $h_ex_state) {
|
|
if(!is_array($matrix["rhex"])) $matrix["rhex"] = [$matrix["rhex"]];
|
|
if(!in_array($h_ex_state, $matrix["rhex"])) continue;
|
|
};
|
|
|
|
if($matrix["rwo"] && (!$workorder || $matrix["rwo"] != $wo_state)) continue;
|
|
|
|
if($matrix["pt"] && $order_type && $matrix["pt"] != $order_type) continue;
|
|
// seems all criteria match => set new status
|
|
|
|
$log->debug(__METHOD__.": new Preorder Status: ".$matrix["p"]);
|
|
|
|
if($preorder) {
|
|
$preorderstatus = null;
|
|
$preorderstatus_flag = null;
|
|
if(array_key_exists("p", $matrix) && $matrix["p"]) {
|
|
$preorderstatus = $matrix["p"];
|
|
}
|
|
if(array_key_exists("pf", $matrix) && $matrix["pf"]) {
|
|
$preorderstatus_flag = $matrix["pf"];
|
|
}
|
|
|
|
if($preorderstatus) {
|
|
$log->debug(__METHOD__.": Setting Preorder Status to ".$preorderstatus);
|
|
$preorder->setNewStatusCode($preorderstatus);
|
|
$preorder->save();
|
|
$preorder->resetSaveNesting();
|
|
}
|
|
if($preorderstatus_flag) {
|
|
$log->debug(__METHOD__.": Setting Preorder Status Flag ".$preorderstatus);
|
|
$preorder->setNewStatusCode($preorderstatus);
|
|
$preorder->save();
|
|
$preorder->resetSaveNesting();
|
|
}
|
|
}
|
|
|
|
$hausnummer_status = $matrix["h"];
|
|
if($hausnummer_status) {
|
|
$log->debug(__METHOD__.": new Hausnummer (".$hausnummer->id.") status: ".$matrix["h"]);
|
|
$old_status = $hausnummer->status_id;
|
|
$hausnummer->setNewStatusCode($hausnummer_status);
|
|
if($hausnummer->status_id != $old_status) {
|
|
$hausnummer->save();
|
|
}
|
|
|
|
}
|
|
|
|
$wohneinheit = new ADBWohneinheit($wohneinheit->id);
|
|
|
|
$wohneinheit_status = $matrix["w"];
|
|
if($wohneinheit_status) {
|
|
$log->debug(__METHOD__.": new Wohneinheit (".$wohneinheit->id.") status: ".$matrix["w"]);
|
|
$old_status_id = $wohneinheit->status_id;
|
|
$wohneinheit->setNewStatusCode($wohneinheit_status);
|
|
if($wohneinheit->status_id != $old_status_id) {
|
|
$wohneinheit->save();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function import($input) {
|
|
$path = __DIR__."/Importer/";
|
|
$dir = opendir($path);
|
|
|
|
while(($file = readdir($dir)) !== false) {
|
|
if(substr($file, 0, 1) == ".") continue;
|
|
if(substr($file, -4) != ".php") continue;
|
|
if(!is_file($path.$file)) continue;
|
|
|
|
require_once $path.$file;
|
|
$classname = "AddressDB_Importer_".ucfirst(substr($file, 0, strlen($file)-4));
|
|
if(class_exists($classname)) {
|
|
$importer = new $classname();
|
|
if($importer->isValid($input)) {
|
|
return $importer->import();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function getAllFcpNames($netzgebiet_id) {
|
|
$fcps = [];
|
|
if($netzgebiet_id) {
|
|
$res = $this->db->query("SELECT rimo_fcp_name FROM `Hausnummer` WHERE netzgebiet_id=$netzgebiet_id GROUP BY rimo_fcp_name ORDER BY LENGTH(rimo_fcp_name), rimo_fcp_name");
|
|
} else {
|
|
$res = $this->db->query("SELECT rimo_fcp_name FROM `Hausnummer` GROUP BY rimo_fcp_name ORDER BY LENGTH(rimo_fcp_name), rimo_fcp_name");
|
|
}
|
|
if($this->db->num_rows($res)) {
|
|
while($data = $this->db->fetch_object($res)) {
|
|
if($data->rimo_fcp_name) {
|
|
$fcps[] = $data->rimo_fcp_name;
|
|
}
|
|
}
|
|
}
|
|
|
|
$fcps = array_unique($fcps);
|
|
|
|
return $fcps;
|
|
}
|
|
|
|
/*
|
|
* methods to create or update an Address from strings
|
|
*/
|
|
public function createUpdateHausnummer($data) {
|
|
$netzgebiet_id = 0;
|
|
$netzgebiet = null;
|
|
$gemeinde = null;
|
|
$ortschaft = null;
|
|
$strasse = null;
|
|
$plz = null;
|
|
$hausnummer = null;
|
|
|
|
//var_dump($data);exit;
|
|
|
|
foreach(["gemeinde", "ortschaft", "strasse", "plz"] as $field) {
|
|
$classname = "ADB".ucfirst($field);
|
|
$idfield = $field."_id";
|
|
if(!array_key_exists($field."_id", $data)) continue;
|
|
$$field = new $classname($data[$idfield]);
|
|
if(!${$field}->id) {
|
|
$$field = null;
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("netzgebiet_id", $data) && $data['netzgebiet_id']) {
|
|
$netzgebiet_id = $data['netzgebiet_id'];
|
|
$netzgebiet = new ADBNetzgebiet($data['netzgebiet_id']);
|
|
if(!$netzgebiet->id) {
|
|
$this->log->debug(__CLASS__."::".__METHOD__.": Missing netzgebiet_id");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
if(!$gemeinde) {
|
|
// dont allow creating Gemeinden
|
|
$this->log->debug(__CLASS__."::".__METHOD__.": Missing Gemeinde");
|
|
return false;
|
|
}
|
|
|
|
if(!$ortschaft) {
|
|
// search by kennziffer
|
|
if(array_key_exists("ortschaft_kennziffer", $data) && $data['ortschaft_kennziffer']) {
|
|
$ortschaft = ADBOrtschaftModel::getFirst(['kennziffer' => $data['ortschaft_kennziffer']]);
|
|
}
|
|
|
|
if(!$ortschaft) {
|
|
// search by name
|
|
if(!array_key_exists("ortschaft", $data) || !$data['ortschaft']) return false;
|
|
$ortschaft = ADBOrtschaftModel::getFirst(['gemeinde_id' => $gemeinde->id, 'name' => $data['ortschaft']]);
|
|
}
|
|
|
|
if(!$ortschaft) {
|
|
// create Ortschaft
|
|
$ortschaft = ADBOrtschaftModel::create([
|
|
'gemeinde_id' => $gemeinde->id,
|
|
'kennziffer' => ($data['ortschaft_kennziffer']) ? $data['ortschaft_kennziffer'] : null,
|
|
'name' => $data['ortschaft']
|
|
]);
|
|
if(!$ortschaft->save()) {
|
|
$this->log->debug(__CLASS__."::".__METHOD__.": Cannot save Ortschaft");
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(!$strasse) {
|
|
// search by kennziffer
|
|
if(array_key_exists("strasse_kennziffer", $data) && $data['strasse_kennziffer']) {
|
|
$strasse = ADBStrasseModel::getFirst(['kennziffer' => $data['strasse_kennziffer']]);
|
|
}
|
|
|
|
if(!$strasse) {
|
|
// search by name
|
|
if(!array_key_exists("strasse", $data) || !$data['strasse']) return false;
|
|
$strasse = ADBStrasseModel::getFirst(['gemeinde_id' => $gemeinde->id, 'name' => $data['strasse']]);
|
|
}
|
|
|
|
if(!$strasse) {
|
|
// create Strasse
|
|
if(!array_key_exists("strasse", $data) || !$data['strasse']) return false;
|
|
$strasse = ADBStrasseModel::create([
|
|
'gemeinde_id' => $gemeinde->id,
|
|
'kennziffer' => ($data['strasse_kennziffer']) ? $data['strasse_kennziffer'] : null,
|
|
'name' => $data['strasse']
|
|
]);
|
|
if(!$strasse->save()) {
|
|
$this->log->debug(__CLASS__."::".__METHOD__.": Cannot save Strasse");
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(!$plz) {
|
|
// search by plz
|
|
if(!array_key_exists("plz", $data) || !$data['plz']) return false;
|
|
$plz = ADBPlzModel::getFirst(['gemeinde_id' => $gemeinde->id, 'plz' => $data['plz']]);
|
|
if(!$plz) {
|
|
// create PLZ
|
|
$plz = ADBPlzModel::create([
|
|
'gemeinde_id' => $gemeinde->id,
|
|
'plz' => $data['plz'],
|
|
'plzstring' => $data['plz']
|
|
]);
|
|
if(!$plz->save()) {
|
|
$this->log->debug(__CLASS__."::".__METHOD__.": Cannot save PLZ");
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("hausnummer_id", $data)) {
|
|
// if hausnummer_id is set but empty => fail
|
|
if(!$data['hausnummer_id']) return false;
|
|
$hausnummer = new ADBHausnummer($data['hausnummer_id']);
|
|
if(!$hausnummer->id) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
$me = new User();
|
|
$me->loadMe();
|
|
|
|
$adrcd = null;
|
|
$subcd = null;
|
|
|
|
if(array_key_exists("adrcd", $data) && $data["adrcd"]) {
|
|
$adr = trim($data["adrcd"]);
|
|
$adr_parts = explode("-", $adr);
|
|
if(count($adr_parts)) {
|
|
$adrcd = $adr_parts[0];
|
|
if(array_key_exists(1, $adr_parts)) {
|
|
$subcd = $adr_parts[1];
|
|
}
|
|
}
|
|
}
|
|
|
|
// build hausnummer data
|
|
//$hausnummer_data['oaid'] = (array_key_exists("oaid", $data) && $data['oaid']) ? $data['oaid'] : null;
|
|
$hausnummer_data['adrcd'] = ($adrcd) ? $adrcd : null;
|
|
$hausnummer_data['subcd'] = ($subcd) ? $subcd : null;
|
|
$hausnummer_data['extref'] = ($data['extref']) ? $data['extref'] : null;
|
|
$hausnummer_data['rimo_id'] = ($data['rimo_id']) ? $data['rimo_id'] : null;
|
|
$hausnummer_data['netzgebiet_id'] = $netzgebiet_id;
|
|
$hausnummer_data['ortschaft_id'] = $ortschaft->id;
|
|
$hausnummer_data['plz_id'] = $plz->id;
|
|
$hausnummer_data['strasse_id'] = $strasse->id;
|
|
$hausnummer_data['hausnummer'] = $data['hausnummer'];
|
|
$hausnummer_data['stiege'] = $data['stiege'];
|
|
$hausnummer_data['grund_nr'] = $data['grund_nr'];
|
|
$hausnummer_data['gdaeigenschaft'] = $data['gdaeigenschaft'];
|
|
$hausnummer_data['meridian'] = $data['meridian'];
|
|
$hausnummer_data['tool_building_type'] = $data['tool_building_type'] ?? '0';
|
|
$hausnummer_data['tool_building_type_override'] = $data['tool_building_type_override'] ?? '0';
|
|
$hausnummer_data['rw'] = ($data['rw']) ? str_replace(",",".", $data['rw']) : null;
|
|
$hausnummer_data['hw'] = ($data['hw']) ? str_replace(",",".", $data['hw']) : null;
|
|
|
|
if($data['rw'] && !is_numeric($hausnummer_data['rw'])) {
|
|
$hausnummer_data['rw'] = null;
|
|
$this->validation_error[] = "RW nicht gespeichert: Keine Zahl";
|
|
}
|
|
if($data['hw'] && !is_numeric($hausnummer_data['hw'])) {
|
|
$hausnummer_data['hw'] = null;
|
|
$this->validation_error[] = "HW nicht gespeichert: Keine Zahl";
|
|
}
|
|
|
|
$hausnummer_data['gps_lat'] = ($data['gps_lat']) ? str_replace(",", ".", $data['gps_lat']) : null;
|
|
$hausnummer_data['gps_long'] = ($data['gps_long']) ? str_replace(",", ".", $data['gps_long']) : null;
|
|
$hausnummer_data['rollout'] = (trim($data['rollout'])) ? trim($data['rollout']) : null;
|
|
$hausnummer_data['rollout_info'] = (trim($data['rollout_info'])) ? trim($data['rollout_info']) : null;
|
|
$hausnummer_data['freigabe'] = json_encode($data['freigabe']);
|
|
|
|
if(!$hausnummer) {
|
|
$hausnummer_data['manual_add'] = date('U');
|
|
$hausnummer_data['manual_add_by'] = $me->id;
|
|
$hausnummer_data['manual_add_info'] = "thetool user ".$me->username." via AddressDB";
|
|
}
|
|
$hausnummer_data['manual_update'] = date('U');
|
|
$hausnummer_data['manual_update_by'] = $me->id;
|
|
$hausnummer_data['manual_update_info'] = "thetool user ".$me->username." via AddressDB";
|
|
//var_dump($data);exit;
|
|
if(!$data["visibility"]) {
|
|
$hausnummer_data['visibility'] = "public";
|
|
} else {
|
|
switch($data['visibility']) {
|
|
case "private":
|
|
$hausnummer_data['visibility'] = "private";
|
|
break;
|
|
default:
|
|
$hausnummer_data['visibility'] = "public";
|
|
}
|
|
}
|
|
|
|
//var_dump($hausnummer_data, $hausnummer);exit;
|
|
|
|
if(!$hausnummer) {
|
|
// create hausnummer
|
|
$hausnummer = ADBHausnummerModel::create($hausnummer_data);
|
|
} else {
|
|
// update hausnummer
|
|
$hausnummer->update($hausnummer_data);
|
|
}
|
|
|
|
$hausnummer_id = $hausnummer->save();
|
|
if(!$hausnummer_id) {
|
|
$this->log->debug(__CLASS__."::".__METHOD__.": Cannot save Hausnummer");
|
|
return false;
|
|
}
|
|
|
|
// create OAID
|
|
if(!$hausnummer->oaid) {
|
|
$hausnummer->oaid = $hausnummer->getNewOAID();
|
|
if(!$hausnummer->save()) {
|
|
$this->log->debug(__CLASS__."::".__METHOD__.": Cannot save Hausnummer OAID");
|
|
}
|
|
}
|
|
|
|
|
|
return $hausnummer_id;
|
|
}
|
|
|
|
public function updateHausnummer($hausnummer_id, $data) {
|
|
|
|
}
|
|
|
|
} |