407 lines
12 KiB
PHP
407 lines
12 KiB
PHP
<?php
|
|
|
|
class ADBHausnummerModel {
|
|
public $oaid;
|
|
public $adrcd;
|
|
public $subcd;
|
|
public $netzgebiet_id;
|
|
public $extref;
|
|
public $ortschaft_id;
|
|
public $plz_id;
|
|
public $strasse_id;
|
|
public $hausnummer;
|
|
public $stiege;
|
|
public $zusatz;
|
|
public $grund_nr;
|
|
public $gdaeigenschaft;
|
|
public $rw;
|
|
public $hw;
|
|
public $meridian;
|
|
public $unit_count;
|
|
public $gps_lat;
|
|
public $gps_long;
|
|
public $borderpoint_lat;
|
|
public $borderpoint_long;
|
|
public $trenches;
|
|
public $rollout;
|
|
public $rollout_info;
|
|
public $freigabe;
|
|
public $visibility;
|
|
public $manual_add;
|
|
public $manual_add_by;
|
|
public $manual_add_info;
|
|
public $manual_update;
|
|
public $manual_update_by;
|
|
public $manual_update_info;
|
|
public $rimo_id;
|
|
public $rimo_fcp_name;
|
|
|
|
public $create = null;
|
|
public $edit = null;
|
|
|
|
public static function create(Array $data) {
|
|
$model = new ADBHausnummer();
|
|
|
|
foreach($data as $field => $value) {
|
|
if(property_exists(get_called_class(), $field)) {
|
|
$model ->$field = $value;
|
|
}
|
|
}
|
|
|
|
$me = mfValuecache::singleton()->get("me");
|
|
if(!$me) {
|
|
$me = new User();
|
|
$me->loadMe();
|
|
mfValuecache::singleton()->set("me", $me);
|
|
}
|
|
/*
|
|
if($model->create_by === null) {
|
|
$model->create_by = $me->id;
|
|
}
|
|
if($model->edit_by === null) {
|
|
$model->edit_by = $me->id;
|
|
}*/
|
|
|
|
return $model;
|
|
}
|
|
|
|
public static function getFirst($filter) {
|
|
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
|
|
$sql = "SELECT Hausnummer.* FROM Hausnummer
|
|
LEFT JOIN Ortschaft ON (Ortschaft.id = Hausnummer.ortschaft_id)
|
|
LEFT JOIN Gemeinde ON (Gemeinde.id = Ortschaft.gemeinde_id)
|
|
LEFT JOIN Strasse ON (Hausnummer.strasse_id = Strasse.id)
|
|
LEFT JOIN Plz ON (Hausnummer.plz_id = Plz.id)
|
|
WHERE $where
|
|
ORDER BY netzgebiet_id,Gemeinde.id,ortschaft_id,strasse_id,LENGTH(hausnummer), hausnummer
|
|
LIMIT 1";
|
|
|
|
mfLoghandler::singleton()->debug($sql);
|
|
$res = $db->query($sql);
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
$item = new ADBHausnummer($data);
|
|
if($item->id) {
|
|
return $item;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static function getAll() {
|
|
$items = [];
|
|
|
|
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
|
|
|
$res = $db->select("Hausnummer", "*", "1=1 ORDER BY strasse_id,hausnummer");
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new ADBHausnummer($data);
|
|
}
|
|
}
|
|
return $items;
|
|
|
|
}
|
|
|
|
|
|
public static function count($filter) {
|
|
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT COUNT(*) as cnt FROM Hausnummer
|
|
LEFT JOIN Ortschaft ON (Ortschaft.id = Hausnummer.ortschaft_id)
|
|
LEFT JOIN Gemeinde ON (Gemeinde.id = Ortschaft.gemeinde_id)
|
|
LEFT JOIN Strasse ON (Hausnummer.strasse_id = Strasse.id)
|
|
LEFT JOIN Plz ON (Hausnummer.plz_id = Plz.id)
|
|
WHERE $where
|
|
";
|
|
|
|
|
|
$res = $db->query($sql);
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
return $data->cnt;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public static function search($filter, $limit = false, $returnDBRessource = false) {
|
|
$items = [];
|
|
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT Hausnummer.* FROM Hausnummer
|
|
LEFT JOIN Ortschaft ON (Ortschaft.id = Hausnummer.ortschaft_id)
|
|
LEFT JOIN Gemeinde ON (Gemeinde.id = Ortschaft.gemeinde_id)
|
|
LEFT JOIN Strasse ON (Hausnummer.strasse_id = Strasse.id)
|
|
LEFT JOIN Plz ON (Hausnummer.plz_id = Plz.id)
|
|
WHERE $where
|
|
ORDER BY netzgebiet_id,Gemeinde.id,ortschaft_id,strasse_id,LENGTH(hausnummer), hausnummer";
|
|
|
|
if(is_array($limit) && count($limit)) {
|
|
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
|
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
|
} elseif(is_numeric($limit['count'])) {
|
|
$sql .= " LIMIT ".$limit['count'];
|
|
}
|
|
}
|
|
|
|
mfLoghandler::singleton()->debug($sql);
|
|
|
|
$res = $db->query($sql);
|
|
if($db->num_rows($res)) {
|
|
|
|
// hack for AddressDBController::exportAction
|
|
if($returnDBRessource) {
|
|
return $res;
|
|
}
|
|
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new ADBHausnummer($data);
|
|
}
|
|
}
|
|
return $items;
|
|
}
|
|
|
|
private static function getSqlFilter($filter) {
|
|
$where = "1=1 ";
|
|
|
|
if(array_key_exists("adrcd", $filter)) {
|
|
$adrcd = FronkDB::singleton()->escape($filter['adrcd']);
|
|
if($adrcd) {
|
|
$where .= " AND Hausnummer.`adrcd` = '$adrcd'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("adrcd%", $filter)) {
|
|
$adrcd = FronkDB::singleton()->escape($filter['adrcd%']);
|
|
if($adrcd) {
|
|
$where .= " AND Hausnummer.`adrcd` like '$adrcd%'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("subcd", $filter)) {
|
|
$subcd = FronkDB::singleton()->escape($filter['subcd']);
|
|
if($subcd === false || $subcd === null) {
|
|
$where .= " AND (Hausnummer.`subcd` IS NULL OR Hausnummer.`subcd` = 0)";
|
|
}
|
|
if($subcd) {
|
|
$where .= " AND Hausnummer.`subcd` = $subcd";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("oaid", $filter)) {
|
|
$oaid = FronkDB::singleton()->escape($filter['oaid']);
|
|
if($oaid) {
|
|
$where .= " AND Hausnummer.`oaid` = '$oaid'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("oaid%", $filter)) {
|
|
$oaid = FronkDB::singleton()->escape($filter['oaid%']);
|
|
if($oaid) {
|
|
$where .= " AND Hausnummer.`oaid` like '$oaid%'";
|
|
}
|
|
}
|
|
|
|
|
|
if(array_key_exists("extref", $filter)) {
|
|
$extref = FronkDB::singleton()->escape($filter['extref']);
|
|
if($extref) {
|
|
$where .= " AND Hausnummer.`extref` = '$extref'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("extref%", $filter)) {
|
|
$extref = FronkDB::singleton()->escape($filter['extref%']);
|
|
if($extref) {
|
|
$where .= " AND Hausnummer.`extref` like '$extref%'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("rimo_id", $filter)) {
|
|
$rimo_id = FronkDB::singleton()->escape($filter['rimo_id']);
|
|
if($rimo_id) {
|
|
$where .= " AND Hausnummer.rimo_id = '$rimo_id'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("plz", $filter)) {
|
|
$plz = FronkDB::singleton()->escape($filter['plz']);
|
|
if($plz) {
|
|
$where .= " AND Plz.plz = '$plz'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("plz%", $filter)) {
|
|
$plz = FronkDB::singleton()->escape($filter['plz%']);
|
|
if($plz) {
|
|
$where .= " AND Plz.plz like '$plz%'";
|
|
}
|
|
}
|
|
|
|
|
|
if(array_key_exists("netzgebiet_id", $filter)) {
|
|
$netzgebiet_id = $filter['netzgebiet_id'];
|
|
if(is_numeric($netzgebiet_id)) {
|
|
$where .= " AND Hausnummer.netzgebiet_id=$netzgebiet_id";
|
|
} elseif(is_array($netzgebiet_id) && count($netzgebiet_id)) {
|
|
$where .= " AND Hausnummer.netzgebiet_id IN (". implode(",", $netzgebiet_id).")";
|
|
} elseif($netzgebiet_id === null) {
|
|
$where .= " AND Hausnummer.netzgebiet_id IS NULL";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("plz_id", $filter)) {
|
|
$plz_id = $filter['plz_id'];
|
|
if(is_numeric($plz_id)) {
|
|
$where .= " AND Hausnummer.plz_id=$plz_id";
|
|
} elseif(is_array($plz_id) && count($plz_id)) {
|
|
$where .= " AND Hausnummer.plz_id IN (". implode(",", $plz_id).")";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("strasse_id", $filter)) {
|
|
$strasse_id = $filter['strasse_id'];
|
|
if(is_numeric($strasse_id)) {
|
|
$where .= " AND Hausnummer.strasse_id=$strasse_id";
|
|
} elseif(is_array($strasse_id) && count($strasse_id)) {
|
|
$where .= " AND Hausnummer.strasse_id IN (". implode(",", $strasse_id).")";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("gemeinde_id", $filter)) {
|
|
$gemeinde_id = $filter['gemeinde_id'];
|
|
if(is_numeric($gemeinde_id)) {
|
|
$where .= " AND Ortschaft.gemeinde_id=$gemeinde_id";
|
|
} elseif(is_array($gemeinde_id) && count($gemeinde_id)) {
|
|
$where .= " AND Ortschaft.gemeinde_id IN (". implode(",", $gemeinde_id).")";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("gemeinde", $filter)) {
|
|
$gemeinde = FronkDB::singleton()->escape($filter['gemeinde']);
|
|
if($gemeinde) {
|
|
$where .= " AND Gemeinde.name = '$gemeinde'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("gemeinde%", $filter)) {
|
|
$gemeinde = FronkDB::singleton()->escape($filter['gemeinde%']);
|
|
if($gemeinde) {
|
|
$where .= " AND Gemeinde.name like '$gemeinde%'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("ortschaft", $filter)) {
|
|
$ortschaft = FronkDB::singleton()->escape($filter['ortschaft']);
|
|
if($ortschaft) {
|
|
$where .= " AND Ortschaft.name = '$ortschaft'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("ortschaft%", $filter)) {
|
|
$ortschaft = FronkDB::singleton()->escape($filter['ortschaft%']);
|
|
if($ortschaft) {
|
|
$where .= " AND Ortschaft.name like '$ortschaft%'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("ortschaft_id", $filter)) {
|
|
$ortschaft_id = $filter['ortschaft_id'];
|
|
if(is_numeric($ortschaft_id)) {
|
|
$where .= " AND Hausnummer.ortschaft_id=$ortschaft_id";
|
|
} elseif(is_array($ortschaft_id) && count($ortschaft_id)) {
|
|
$where .= " AND Hausnummer.ortschaft_id IN (". implode(",", $ortschaft_id).")";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("hausnummer", $filter)) {
|
|
if(is_array($filter['hausnummer'])) {
|
|
$hausnummer = $filter['hausnummer'];
|
|
$where .= " AND Hausnummer.`hausnummer` IN ('".implode("','", $hausnummer)."')";
|
|
} else {
|
|
$hausnummer = FronkDB::singleton()->escape($filter['hausnummer']);
|
|
if($hausnummer) {
|
|
$where .= " AND Hausnummer.`hausnummer` = '$hausnummer'";
|
|
}
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("hausnummer%", $filter)) {
|
|
$hausnummer = FronkDB::singleton()->escape($filter['hausnummer%']);
|
|
if($hausnummer) {
|
|
$where .= " AND Hausnummer.`hausnummer` like '$hausnummer%'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("stiege", $filter)) {
|
|
$stiege = FronkDB::singleton()->escape($filter['stiege']);
|
|
if($stiege) {
|
|
$where .= " AND stiege.name = '$stiege'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("strasse", $filter)) {
|
|
$strasse = FronkDB::singleton()->escape($filter['strasse']);
|
|
if($strasse) {
|
|
$where .= " AND Strasse.name = '$strasse'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("strasse%", $filter)) {
|
|
$strasse = FronkDB::singleton()->escape($filter['strasse%']);
|
|
if($strasse) {
|
|
$where .= " AND Strasse.name like '%$strasse%'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("visibility", $filter)) {
|
|
$visibility = $filter['visibility'];
|
|
if(is_array($visibility)) {
|
|
$where .= " AND Hausnummer.visibility IN ('".implode("','", $visibility)."')";
|
|
} else {
|
|
$visibility = FronkDB::singleton()->escape($visibility);
|
|
$where .= " AND Hausnummer.visibility = '$visibility'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("rollout", $filter)) {
|
|
$rollout = FronkDB::singleton()->escape($filter['rollout']);
|
|
if($rollout) {
|
|
$where .= " AND Hausnummer.rollout = '$rollout'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("rollout%", $filter)) {
|
|
$rollout = FronkDB::singleton()->escape($filter['rollout%']);
|
|
if($rollout) {
|
|
$where .= " AND Hausnummer.rollout like '%$rollout%'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("rollout_info", $filter)) {
|
|
$rollout_info = FronkDB::singleton()->escape($filter['rollout_info']);
|
|
if($rollout_info) {
|
|
$where .= " AND Hausnummer.rollout_info = '$rollout_info'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("rollout_info%", $filter)) {
|
|
$rollout_info = FronkDB::singleton()->escape($filter['rollout_info%']);
|
|
if($rollout_info) {
|
|
$where .= " AND Hausnummer.rollout_info like '%$rollout_info%'";
|
|
}
|
|
}
|
|
|
|
//var_dump($filter, $where);exit;
|
|
return $where;
|
|
}
|
|
|
|
}
|