Groß St.Florian Locations/Homes update
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
#!/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/C03080_sbidi_Ortskern_Homes_221025.csv";
|
||||
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
$log = mfLoghandler::singleton();
|
||||
|
||||
$input = fopen($filename, "r");
|
||||
|
||||
$hausnummer_extref_trans = [
|
||||
"25138081" => "25138353",
|
||||
"25138090" => "25138402",
|
||||
"25138104" => "25138399",
|
||||
"25138112" => "25138285",
|
||||
"25138116" => "25138401",
|
||||
"25138172" => "25138384",
|
||||
"25138229" => "25138283",
|
||||
"25138246" => "25138346",
|
||||
"25138249" => "25151924",
|
||||
"25138261" => "25138413",
|
||||
"25138282" => "25138388",
|
||||
"25138284" => "25138391",
|
||||
"25151923" => "25151924",
|
||||
"25138547" => "25138605",
|
||||
"25138576" => "25138603",
|
||||
"25138578" => "25138599",
|
||||
"25138427" => "25138493",
|
||||
"25138431" => "25138494",
|
||||
"25138480" => "25138532",
|
||||
"25138507" => "25138479"
|
||||
];
|
||||
|
||||
$wohnextref_zusatz = [
|
||||
"SDIHome_92719443457_1666705401" => "Pfarrheim",
|
||||
"SDIHome_92718863105_1666705401" => "Ölmühle",
|
||||
"SDIHome_92718862081_1666705401" => "Ölmühle",
|
||||
"SDIHome_92718073089_1666705401" => "Hinterhofgebäude",
|
||||
"SDIHome_92718072065_1666705401" => "Hinterhofgebäude",
|
||||
"SDIHome_92718071041_1666705401" => "Hinterhofgebäude",
|
||||
"SDIHome_92718077185_1666705401" => "Lagerhalle und Werkstatt",
|
||||
"SDIHome_92718076161_1666705401" => "Lagerhalle und Werkstatt",
|
||||
"SDIHome_92719454721_1666705401" => "Zubau Musikheim",
|
||||
"SDIHome_92719358977_1666705401" => "Firma",
|
||||
"SDIHome_92719222273_1666705401" => "Wohnhaus",
|
||||
"SDIHome_92719249921_1666705401" => "Wohnung",
|
||||
"SDIBuilding_104216715265_1659686456" => "a",
|
||||
"SDIHome_92719070465_1666705401" => "Nebengebäude"
|
||||
];
|
||||
|
||||
$i = 0;
|
||||
while($csv = fgetcsv($input, 0, ";")) {
|
||||
$i++;
|
||||
if($i == 1) continue;
|
||||
|
||||
if(!trim($csv[0])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$zusatz = false;
|
||||
$wohneinheit_extref = trim($csv[0]);
|
||||
$hausnummer_extref = trim($csv[1]);
|
||||
$adresse = trim($csv[7]);
|
||||
|
||||
if(array_key_exists($hausnummer_extref, $hausnummer_extref_trans)) {
|
||||
$hausnummer_extref = $hausnummer_extref_trans[$hausnummer_extref];
|
||||
}
|
||||
|
||||
$hausnummer = ADBHausnummerModel::getFirst(['extref' => $hausnummer_extref]);
|
||||
if(!$hausnummer) {
|
||||
if(preg_match('/GST /', $adresse)) continue;
|
||||
die("Hausnummer $hausnummer_extref nicht gefunden\n");
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists($wohneinheit_extref, $wohnextref_zusatz)) {
|
||||
$zusatz = $wohnextref_zusatz[$wohneinheit_extref];
|
||||
}
|
||||
|
||||
// get last wohneinheit
|
||||
$num = 0;
|
||||
$last_we = getLastWohneinheit($hausnummer->id);
|
||||
if($last_we) {
|
||||
$num = ($last_we->num) ? $last_we->num : 0;
|
||||
}
|
||||
|
||||
$num++;
|
||||
|
||||
$wohneinheit_data = [
|
||||
'extref' => $wohneinheit_extref,
|
||||
'hausnummer_id' => $hausnummer->id,
|
||||
'num' => $num,
|
||||
'zusatz' => ($zusatz) ? $zusatz : null
|
||||
];
|
||||
|
||||
$wohneinheit = ADBWohneinheitModel::create($wohneinheit_data);
|
||||
//continue;
|
||||
//var_dump($wohneinheit);exit;
|
||||
$wohneinheit->save();
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user