Files
thetool/application/Building/Building.php

119 lines
3.0 KiB
PHP

<?php
class Building extends mfBaseModel {
protected $forcestr = ['street','zip','phone','email','note'];
private $network;
private $pop;
private $type;
private $status;
private $pipeworker;
public function getProperty($name) {
if($this->$name == null) {
if($name == "type") {
$this->type = new Buildingtype($this->type_id);
return $this->type;
}
if($name == "status") {
$this->status = new Buildingstatus($this->status_id);
return $this->status;
}
if($name == "pipeworker") {
$this->pipeworker = new Address($this->pipeworker_id);
return $this->pipeworker;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = new $classname($this->$idfield);
if($this->$name->id) {
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
public function getNewObjectCode() {
if(!$this->zip) {
return false;
}
$cc = "AT";
$zip = $this->zip;
for($try = 16; $try > 0; $try--) {
$rnd[0] = random_int(0, 255);
$rnd[1] = random_int(0, 255);
$rnd[2] = random_int(0, 255);
$rnd[3] = random_int(0, 255);
$code = "$cc-$zip-";
foreach($rnd as $r) {
$code .= dechex($r);
}
if(BuildingModel::search(['code' => $code])) {
$this->log->warn(__FILE__."::getNewObjectCode: New Code already in use. Trying again for a maximum of $try times.");
} else {
// code is unique
break;
}
}
//var_dump($code);
//var_dump($try);exit;
if($try == 0) {
return null;
}
return $code;
}
public function getLaeaCoordinates() {
if(!$this->gps_lat || !$this->gps_lat) {
return false;
}
// Elipsenparameter der Erdoberfläche
$a = 6378137;
$e = 0.081819191;
// Lage des Ausgangspunktes in natürlichen Koordinaten und Korrekturwerte in Meter
$latO = 0.907571211;
$lonO = 0.174532925;
$FE = 4321000;
$FN = 3210000;
// Mathematische Konstanten
$qP = 1.99553108748562;
$qO = 1.56982570415136;
$PI = M_PI;
// Umrechnung der Eingabekoordinaten in rad
$Lat = $this->gps_lat * $PI / 180;
$Lon = $this->gps_long * $PI / 180;
// Berechnungen
$q = (1 - $e ** 2) * ((sin($Lat) / (1 - $e ** 2 * sin($Lat) ** 2)) - ((1 / (2 * $e)) * log((1 - $e * sin($Lat)) / (1 + $e * sin($Lat)))));
$beta = asin($q / $qP);
$betaO = asin($qO / $qP);
$Rq = $a * ($qP / 2) ** 0.5;
$b = $Rq * (2 / (1 + Sin($betaO) * Sin($beta) + Cos($betaO) * Cos($beta) * Cos($Lon - $lonO))) ** 0.5;
$D = $a * (Cos($latO) / (1 - $e ** 2 * Sin($latO) ** 2) ** 0.5) / ($Rq * Cos($betaO));
$East = floor(($FE + (($b * $D) * (Cos($beta) * Sin($Lon - $lonO))))/100);
$North = floor(($FN + ($b / $D) * ((Cos($betaO) * Sin($beta)) - (Sin($betaO) * Cos($beta) * Cos($Lon - $lonO))))/100);
$Gridcell = "100mN{$North}E{$East}";
return $Gridcell;
}
}