Auto Calculating LAEA and code in Building::save

This commit is contained in:
Frank Schubert
2021-07-15 19:09:29 +02:00
parent dc56881ddd
commit e77dd8b263
6 changed files with 119 additions and 5 deletions

View File

@@ -90,7 +90,7 @@
<div class="form-group row"> <div class="form-group row">
<label class="col-lg-2 col-form-label" for="code">Objekt ID</label> <label class="col-lg-2 col-form-label" for="code">Objekt ID</label>
<div class="col-lg-10"> <div class="col-lg-10">
<input type="text" class="form-control" name="code" id="code" value="<?=$building->code?>" /> <input type="text" class="form-control" name="code" id="code" value="<?=$building->code?>" readonly="readonly" />
</div> </div>
</div> </div>
@@ -131,6 +131,13 @@
</div> </div>
</div> </div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="laea">LAEA Koordinaten</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="laea" id="laea" value="<?=$building->laea?>" readonly="readonly" />
</div>
</div>
<div class="form-group row"> <div class="form-group row">
<label class="col-lg-2 col-form-label" for="contact">Kontakt</label> <label class="col-lg-2 col-form-label" for="contact">Kontakt</label>
<div class="col-lg-10"> <div class="col-lg-10">
@@ -159,6 +166,18 @@
</div> </div>
</div> </div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="status_id">Status</label>
<div class="col-lg-10">
<select class="select2 form-control " name="status_id" id="type_id" <?=(!$me->is("Admin")) ? "disabled='disabled'" : ""?>>
<option></option>
<?php foreach($statuses as $status): ?>
<option value="<?=$status->id?>" <?=($building->status_id == $status->id) ? "selected='selected'" : ""?>><?=__($status->name)?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</div> </div>
</div> </div>
@@ -195,7 +214,7 @@
<script type="text/javascript"> <script type="text/javascript">
$("#network_id").select2({placeholder: ""}); $("#network_id").select2({placeholder: ""});
$("#pop_id").select2({placeholder: ""}); $("#pop_id").select2({placeholder: "", allowClear: true,});
$("#type_id").select2({placeholder: ""}); $("#type_id").select2({placeholder: ""});
// disable mousewheel on input number field when in focus // disable mousewheel on input number field when in focus

View File

@@ -1,7 +1,7 @@
<?php <?php
class Address extends mfBaseModel { class Address extends mfBaseModel {
protected $forcestr = ['company','zip','phone','fax','mobile','note']; protected $forcestr = ['street','company','zip','phone','fax','mobile','note'];
private $types; private $types;
private $attributes; private $attributes;

View File

@@ -1,6 +1,8 @@
<?php <?php
class Building extends mfBaseModel { class Building extends mfBaseModel {
protected $forcestr = ['street','zip','phone','gps_lat','gps_long','email','note'];
private $network; private $network;
private $pop; private $pop;
private $type; private $type;
@@ -39,4 +41,79 @@ class Building extends mfBaseModel {
return $this->$name; 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;
}
} }

View File

@@ -23,6 +23,7 @@ class BuildingController extends mfBaseController {
$this->layout()->setTemplate("Building/Form"); $this->layout()->setTemplate("Building/Form");
$this->layout()->set("networks", NetworkModel::getAll()); $this->layout()->set("networks", NetworkModel::getAll());
$this->layout()->set("types", BuildingtypeModel::getAll()); $this->layout()->set("types", BuildingtypeModel::getAll());
$this->layout()->set("statuses", BuildingstatusModel::getAll());
} }
protected function editAction() { protected function editAction() {
@@ -83,7 +84,6 @@ class BuildingController extends mfBaseController {
$data['description'] = $r->description; $data['description'] = $r->description;
$data['note'] = $r->note; $data['note'] = $r->note;
$data['edit_by'] = 1; $data['edit_by'] = 1;
if($mode == "add") { if($mode == "add") {
@@ -102,6 +102,16 @@ class BuildingController extends mfBaseController {
$this->layout()->set("building", $building); $this->layout()->set("building", $building);
return $this->add(); return $this->add();
} }
// generate object code and LAEA coords
if(!$building->code) {
$building->code = $building->getNewObjectCode();
$building->save();
}
if(!$building->laea) {
$building->laea = $building->getLaeaCoordinates();
$building->save();
}
$this->layout()->setFlash("Objekt erfolgreich gespeichert.", "success"); $this->layout()->setFlash("Objekt erfolgreich gespeichert.", "success");

View File

@@ -140,7 +140,13 @@ class BuildingModel {
} }
} }
}
if(array_key_exists("code", $filter)) {
$code = FronkDB::singleton()->escape($filter['code']);
if($code) {
$where .= "AND Building.`code`='$code'";
}
} }
//var_dump($filter, $where);exit; //var_dump($filter, $where);exit;

View File

@@ -21,4 +21,6 @@ $l['billing'] = "Verrechnungsadresse";
$l['business'] = "Business"; $l['business'] = "Business";
$l['residential'] = "Residential"; $l['residential'] = "Residential";
$l['created'] = "Erstellt";
$lang['de'] = $l; $lang['de'] = $l;