178 lines
4.7 KiB
PHP
Executable File
178 lines
4.7 KiB
PHP
Executable File
#!/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");
|
|
|
|
$me = new User(1);
|
|
|
|
$filename = __DIR__."/import/SDIHome__Homes_PremSued_20231207.csv";
|
|
|
|
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
|
$log = mfLoghandler::singleton();
|
|
|
|
$input = fopen($filename, "r");
|
|
|
|
$hausnummer_extref_trans = [
|
|
"25011065" => "25011726",
|
|
"25011725" => "25011726",
|
|
"25011829" => "25012419",
|
|
"25010921" => "25011704",
|
|
"25010922" => "25012205",
|
|
"25012204" => "25012205",
|
|
"25011953" => "25011954",
|
|
"25012291" => "25013176",
|
|
"25010897" => "25013219",
|
|
"25010895" => "25013220",
|
|
"25010927" => "25022100",
|
|
"25010950" => "25013206",
|
|
|
|
|
|
];
|
|
|
|
$wohnextref_zusatz = [
|
|
"SDIHome_63149022721_1664900169" => "Wohnhaus",
|
|
"SDIHome_63151303425_1664900169" => "Betriebsgebaeude",
|
|
"SDIHome_63149432833_1664900169" => "Verkaufsgebaeude", // hausnummer_id 98
|
|
|
|
];
|
|
|
|
$hausnummer_extref_ignore = [
|
|
//"25012366", // Bierbaumer strasse 24a
|
|
"25012430", // kiefernweg 20/8
|
|
"25012642", // kiefernweg 20/9
|
|
"25012367", // Sender
|
|
//"25137949", // Laa 37a
|
|
//"25012486", // Schwarzer Weg 97
|
|
//"25012653", // Kirchweg 8a
|
|
//"25013177", // Kirchweg 1
|
|
//"25037532", // Poniglweg 4
|
|
|
|
|
|
|
|
|
|
];
|
|
|
|
$current_wohneinheit_nums = [];
|
|
|
|
$i = 0;
|
|
while($csv = fgetcsv($input, 0, ";")) {
|
|
$i++;
|
|
if($i == 1) continue;
|
|
|
|
if(!trim($csv[1])) {
|
|
continue;
|
|
}
|
|
|
|
$zusatz = false;
|
|
$wohneinheit_extref = trim($csv[37]);
|
|
$hausnummer_extref = trim($csv[35]);
|
|
$building_string = trim($csv[25]);
|
|
|
|
$adresse = "";
|
|
|
|
$m = [];
|
|
if(preg_match('/\[([^\]]+)\]/', $building_string, $m)) {
|
|
$adresse = $m[1];
|
|
}
|
|
|
|
|
|
if(array_key_exists($hausnummer_extref, $hausnummer_extref_trans)) {
|
|
$hausnummer_extref = $hausnummer_extref_trans[$hausnummer_extref];
|
|
}
|
|
|
|
if(in_array($hausnummer_extref, $hausnummer_extref_ignore)) continue;
|
|
|
|
$hausnummer = ADBHausnummerModel::getFirst(['extref' => $hausnummer_extref]);
|
|
if(!$hausnummer) {
|
|
if(preg_match('/(GST |^L\d)/', $adresse)) continue;
|
|
if($adresse) {
|
|
die("Hausnummer $hausnummer_extref nicht gefunden\n");
|
|
} else {
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
if(array_key_exists($wohneinheit_extref, $wohnextref_zusatz)) {
|
|
$zusatz = $wohnextref_zusatz[$wohneinheit_extref];
|
|
}
|
|
|
|
if(array_key_exists($hausnummer_extref, $current_wohneinheit_nums)) {
|
|
$current_wohneinheit_nums[$hausnummer_extref]++;
|
|
} else {
|
|
$current_wohneinheit_nums[$hausnummer_extref] = 1;
|
|
}
|
|
|
|
|
|
// get last wohneinheit
|
|
$num = $current_wohneinheit_nums[$hausnummer_extref];
|
|
|
|
$unit_count = ADBWohneinheitModel::count(["hausnummer_id" => $hausnummer->id]);
|
|
//echo "num: $num, unit_count: $unit_count\n";
|
|
if($num > $unit_count) {
|
|
$last_we = getLastWohneinheit($hausnummer->id);
|
|
if($last_we) {
|
|
$num = ($last_we->num) ? $last_we->num + 1 : 1;
|
|
}
|
|
//var_dump($current_wohneinheit_nums[$hausnummer_extref]);
|
|
$wohneinheit_data = [
|
|
'extref' => $wohneinheit_extref,
|
|
'hausnummer_id' => $hausnummer->id,
|
|
'num' => $num,
|
|
'zusatz' => ($zusatz) ? $zusatz : null
|
|
];
|
|
|
|
$wohneinheit = ADBWohneinheitModel::create($wohneinheit_data);
|
|
$wohneinheit->save();
|
|
//echo "+ ".$wohneinheit->extref."\n";
|
|
} else {
|
|
$wohneinheit = ADBWohneinheitModel::getFirst(['hausnummer_id' => $hausnummer->id, "extref" => $wohneinheit_extref]);
|
|
if($wohneinheit) continue; // unit with extref exists so continue
|
|
|
|
if(!$wohneinheit) {
|
|
// get unit with num
|
|
$wohneinheit = ADBWohneinheitModel::getFirst(['hausnummer_id' => $hausnummer->id, "num" => $num]);
|
|
}
|
|
// else get unit without num nor extref
|
|
if(!$wohneinheit) {
|
|
$wohneinheit = ADBWohneinheitModel::getFirst(['hausnummer_id' => $hausnummer->id, "num" => null, "extref" => null]);
|
|
}
|
|
}
|
|
|
|
if(!$wohneinheit) {
|
|
echo "Keine passende Wohneinheit gefunden für $hausnummer_extref ($num)\n";
|
|
exit;
|
|
}
|
|
|
|
if(!$wohneinheit->extref) {
|
|
$wohneinheit->extref = $wohneinheit_extref;
|
|
//var_dump("UPDATE UNIT",$wohneinheit);exit;
|
|
//echo "u ".$wohneinheit->extref."\n";
|
|
$wohneinheit->save();
|
|
//exit;
|
|
}
|
|
//continue;
|
|
//var_dump($wohneinheit);exit;
|
|
|
|
|
|
}
|
|
|
|
echo "\n";
|
|
|
|
function getLastWohneinheit($hausnummer_id) {
|
|
global $db;
|
|
$sql = "SELECT * FROM Wohneinheit WHERE hausnummer_id = $hausnummer_id ORDER BY num DESC LIMIT 1";
|
|
$res = $db->query($sql);
|
|
if($db->num_rows($res)) {
|
|
return new ADBWohneinheit($db->fetch_object($res));
|
|
}
|
|
return false;
|
|
} |