Merge branch 'fronkdev' into 'master'
ADB status change & RTR Reporting a10 See merge request fronk/thetool!780
This commit is contained in:
@@ -35,6 +35,8 @@ class ADBHausnummer extends mfBaseModel {
|
||||
$this->getGpsCoords();
|
||||
}
|
||||
|
||||
$this->logChanges();
|
||||
|
||||
|
||||
// Statuschange from Rimo statuschange for all units
|
||||
foreach(ADBWohneinheitModel::search(["hausnummer_id" => $this->id]) as $wohneinheit) {
|
||||
@@ -42,6 +44,34 @@ class ADBHausnummer extends mfBaseModel {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function resetSaveNesting() {
|
||||
mfValuecache::singleton()->delete("adbhausnummer-save-nesting-level-" . $this->id);
|
||||
}
|
||||
|
||||
private function logChanges() {
|
||||
$changes = $this->getChangedFields();
|
||||
if(!count($changes)) return true;
|
||||
|
||||
$logstr = "";
|
||||
|
||||
foreach($changes as $key) {
|
||||
if($key == "status_id") {
|
||||
$old_status = new ADBStatus($this->_old_data->status_id);
|
||||
$new_status = new ADBStatus($this->data->status_id);
|
||||
$logstr .= "| '$key' => FROM '".$this->_old_data->$key."' TO '".$this->data->$key."' [".$old_status->code." => ".$new_status->code."]";
|
||||
} else {
|
||||
$logstr .= "| '$key' => FROM '".$this->_old_data->$key."' TO '".$this->data->$key."'";
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->log->info(__CLASS__." Changes: User ".$me->username." $logstr");
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public function getBuildingType() {
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
class ADBRimoFcp extends mfBaseModel {
|
||||
|
||||
protected function init() {
|
||||
$this->db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
$this->table = "RimoFcp";
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
/********************************
|
||||
* Begin static Model functions
|
||||
*/
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new ADBRimoFcp();
|
||||
|
||||
$table_fields = [
|
||||
"netzgebiet_id", "name", "rimo_id", "label", "building_type", "rimo_ex_state", "rimo_op_state", "gps_lat", "gps_long",
|
||||
"create","edit"
|
||||
];
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(in_array($field, $table_fields)) {
|
||||
$model->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getFirst($filter) {
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT RimoFcp.* FROM RimoFcp
|
||||
WHERE $where
|
||||
ORDER BY name
|
||||
LIMIT 1";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new ADBRimoFcp($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("RimoFcp", "*", "1=1 ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new ADBRimoFcp($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 RimoFcp
|
||||
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) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT RimoFcp.* FROM RimoFcp
|
||||
WHERE $where
|
||||
ORDER BY name";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
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'];
|
||||
}
|
||||
}
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new ADBRimoFcp($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
if(array_key_exists("netzgebiet_id", $filter)) {
|
||||
$netzgebiet_id = $filter['netzgebiet_id'];
|
||||
if(is_numeric($netzgebiet_id)) {
|
||||
$where .= " AND netzgebiet_id=$netzgebiet_id";
|
||||
} elseif(is_array($netzgebiet_id) && count($netzgebiet_id)) {
|
||||
$where .= " AND netzgebiet_id IN (". implode(",", $netzgebiet_id).")";
|
||||
} elseif($netzgebiet_id === null) {
|
||||
$where .= " AND netzgebiet_id IS NULL";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("name", $filter)) {
|
||||
$name = $db->escape($filter['name']);
|
||||
if($name) {
|
||||
$where .= " AND RimoFcp.name='$name'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("label", $filter)) {
|
||||
$label = $db->escape($filter['label']);
|
||||
if($label) {
|
||||
$where .= " AND RimoFcp.label='$label'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("building_type", $filter)) {
|
||||
$building_type = $db->escape($filter['building_type']);
|
||||
if($building_type) {
|
||||
$where .= " AND RimoFcp.building_type='$building_type'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("rimo_ex_state", $filter)) {
|
||||
$rimo_ex_state = $db->escape($filter['rimo_ex_state']);
|
||||
if($rimo_ex_state) {
|
||||
$where .= " AND RimoFcp.rimo_ex_state='$rimo_ex_state'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("rimo_op_state", $filter)) {
|
||||
$rimo_op_state = $db->escape($filter['rimo_op_state']);
|
||||
if($rimo_op_state) {
|
||||
$where .= " AND RimoFcp.rimo_op_state='$rimo_op_state'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("rimo_id", $filter)) {
|
||||
$rimo_id = $db->escape($filter['rimo_id']);
|
||||
if($rimo_id) {
|
||||
$where .= " AND RimoFcp.rimo_id='$rimo_id'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
}
|
||||
@@ -120,6 +120,7 @@ class ADBStatusModel {
|
||||
$where = "1=1 ";
|
||||
|
||||
//var_dump($filter);exit;
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
if(array_key_exists("code", $filter)) {
|
||||
$code = $filter['code'];
|
||||
@@ -127,6 +128,20 @@ class ADBStatusModel {
|
||||
$where .= " AND code=$code";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("type", $filter)) {
|
||||
$type = $db->escape($filter['type']);
|
||||
if($type) {
|
||||
$where .= " AND type='$type'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("!type", $filter)) {
|
||||
$type = $db->escape($filter['!type']);
|
||||
if($type) {
|
||||
$where .= " AND (type IS NULL OR NOT type='$type')";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
|
||||
@@ -30,6 +30,7 @@ class ADBWohneinheit extends mfBaseModel {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->logChanges();
|
||||
// Statuschange from Rimo statuschange
|
||||
AddressDB::handleRimoStatusUpdate($this->id);
|
||||
|
||||
@@ -77,6 +78,34 @@ class ADBWohneinheit extends mfBaseModel {
|
||||
|
||||
}
|
||||
|
||||
public function resetSaveNesting() {
|
||||
mfValuecache::singleton()->delete("adbwohneinheit-save-nesting-level-" . $this->id);
|
||||
}
|
||||
|
||||
private function logChanges() {
|
||||
$changes = $this->getChangedFields();
|
||||
if(!count($changes)) return true;
|
||||
|
||||
$logstr = "";
|
||||
|
||||
foreach($changes as $key) {
|
||||
if($key == "status_id") {
|
||||
$old_status = new ADBStatus($this->_old_data->status_id);
|
||||
$new_status = new ADBStatus($this->data->status_id);
|
||||
$logstr .= "| '$key' => FROM '".$this->_old_data->$key."' TO '".$this->data->$key."' [".$old_status->code." => ".$new_status->code."]";
|
||||
} else {
|
||||
$logstr .= "| '$key' => FROM '".$this->_old_data->$key."' TO '".$this->data->$key."'";
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->log->info(__CLASS__." Changes: User ".$me->username." $logstr");
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public function setNewStatusCode($new_status_code) {
|
||||
if(!$new_status_code) return false;
|
||||
|
||||
|
||||
@@ -27,11 +27,54 @@ class Address extends mfBaseModel {
|
||||
|
||||
$this->generateFibuAccountNumber();
|
||||
$this->syncToFibuMerge();
|
||||
$this->getCoords();
|
||||
|
||||
$this->in_after_save--;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function getCoords() {
|
||||
$update_needed = false;
|
||||
if($this->id) {
|
||||
$changes = $this->getChangedFields();
|
||||
foreach($changes as $key => $change) {
|
||||
if($key == "street" || $key == "zip" || $key == "city") {
|
||||
$update_needed = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$update_needed = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(!$this->gps_lat || !$this->gps_long || !$this->laea) {
|
||||
$update_needed = true;
|
||||
}
|
||||
|
||||
if(!$update_needed) return true;
|
||||
|
||||
|
||||
$gps_search = [
|
||||
'country' => $this->getProperty("country")->isocode,
|
||||
'city' => $this->city,
|
||||
'zip' => $this->zip,
|
||||
'street' => $this->street
|
||||
];
|
||||
|
||||
$gps = Gmaps_Geocoding::getCoords($gps_search);
|
||||
if(!is_array($gps) || !count($gps) == 2) return false;
|
||||
|
||||
$this->gps_lat = $gps[0];
|
||||
$this->gps_long = $gps[1];
|
||||
|
||||
$this->laea = (new Building())->getLaeaCoordinates($this->gps_lat, $this->gps_long);
|
||||
$this->save();
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function generateFibuAccountNumber() {
|
||||
if($this->fibu_account_number) {
|
||||
return true;
|
||||
|
||||
@@ -742,6 +742,12 @@ class AddressDBController extends mfBaseController {
|
||||
case "findAddress":
|
||||
$return = $this->findAddressApi();
|
||||
break;
|
||||
case "updateAddressStatus":
|
||||
$return = $this->updateAddressStatusApi();
|
||||
break;
|
||||
case "updateUnitStatus":
|
||||
$return = $this->updateUnitStatusApi();
|
||||
break;
|
||||
case "getFilteredBuildings":
|
||||
$return = $this->getFilteredBuildingsApi();
|
||||
break;
|
||||
@@ -783,7 +789,117 @@ class AddressDBController extends mfBaseController {
|
||||
$data['result'] = $return;
|
||||
$this->returnJson($data);
|
||||
}
|
||||
|
||||
|
||||
private function updateAddressStatusApi() {
|
||||
$address_id = $this->request->id;
|
||||
|
||||
if(!is_numeric($address_id) || $address_id < 1) {
|
||||
return ["error" => 1];
|
||||
return false;
|
||||
}
|
||||
|
||||
$address = new ADBHausnummer($address_id);
|
||||
if(!$address->id) {
|
||||
return ["error" => 2];
|
||||
return false;
|
||||
}
|
||||
|
||||
$status_id = $this->request->status_id;
|
||||
if(!is_numeric($status_id) || $status_id < 1) {
|
||||
return ["error" => 3];
|
||||
return false;
|
||||
}
|
||||
|
||||
$status = new ADBStatus($status_id);
|
||||
if(!$status->id) {
|
||||
return ["error" => 4];
|
||||
return false;
|
||||
}
|
||||
|
||||
$address->status_id = $status_id;
|
||||
$address->save();
|
||||
|
||||
$update = [
|
||||
"id" => $address_id,
|
||||
"status_id" => $status_id,
|
||||
"status_code" => $status->code,
|
||||
"status_text" => $status->name,
|
||||
"units" => []
|
||||
];
|
||||
|
||||
foreach(ADBWohneinheitModel::search(["hausnummer_id" => $address->id]) as $affected_unit) {
|
||||
$up = [
|
||||
"id" => $affected_unit->id,
|
||||
"status_id" => $affected_unit->status_id,
|
||||
"status_code" => $affected_unit->status->code,
|
||||
"status_text" => $affected_unit->status->name,
|
||||
];
|
||||
|
||||
$update["units"][] = $up;
|
||||
}
|
||||
|
||||
return ["message" => "Status saved successfully", "id" => $address_id, "updates" => $update];
|
||||
}
|
||||
|
||||
private function updateUnitStatusApi() {
|
||||
$unit_id = $this->request->id;
|
||||
|
||||
if(!is_numeric($unit_id) || $unit_id < 1) {
|
||||
return ["error" => 1];
|
||||
return false;
|
||||
}
|
||||
|
||||
$unit = new ADBWohneinheit($unit_id);
|
||||
if(!$unit->id) {
|
||||
return ["error" => 2];
|
||||
return false;
|
||||
}
|
||||
|
||||
$status_id = $this->request->status_id;
|
||||
if(!is_numeric($status_id) || $status_id < 1) {
|
||||
return ["error" => 3];
|
||||
return false;
|
||||
}
|
||||
|
||||
$status = new ADBStatus($status_id);
|
||||
if(!$status->id) {
|
||||
return ["error" => 4];
|
||||
return false;
|
||||
}
|
||||
|
||||
$linkes_units = [];
|
||||
foreach(ADBWohneinheitModel::search(["hausnummer_id" => $unit->hausnummer_id]) as $lu) {
|
||||
$linkes_units[$lu->id] = $lu->status_id;
|
||||
}
|
||||
|
||||
$unit->status_id = $status_id;
|
||||
$unit->save();
|
||||
|
||||
$update = [
|
||||
"id" => $unit_id,
|
||||
"status_id" => $status_id,
|
||||
"status_code" => $status->code,
|
||||
"status_text" => $status->name,
|
||||
"units" => []
|
||||
];
|
||||
|
||||
foreach(ADBWohneinheitModel::search(["hausnummer_id" => $unit->hausnummer_id]) as $affected_unit) {
|
||||
if(!array_key_exists($affected_unit->id, $linkes_units)) continue;
|
||||
if($linkes_units[$affected_unit->id] == $affected_unit->status_id) continue;
|
||||
|
||||
$up = [
|
||||
"id" => $affected_unit->id,
|
||||
"status_id" => $affected_unit->status_id,
|
||||
"status_code" => $affected_unit->status->code,
|
||||
"status_text" => $affected_unit->status->name,
|
||||
];
|
||||
|
||||
$update["units"][] = $up;
|
||||
}
|
||||
|
||||
return ["message" => "Status saved successfully", "id" => $unit_id, "updates" => $update];
|
||||
}
|
||||
|
||||
private function getUnitApi() {
|
||||
$id = $this->request->id;
|
||||
if(!$id) return false;
|
||||
|
||||
@@ -47,6 +47,37 @@ class AdminController extends mfBaseController {
|
||||
$this->layout()->set("xinon_active_customers_total", $xinon_active_customers_total);
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function rtrReporting() {
|
||||
require_once(realpath(dirname(__FILE__)."/functions")."/RtrReporting.php");
|
||||
|
||||
$this->layout()->setTemplate("Admin/RtrReporting/Index");
|
||||
|
||||
$rtrreporting = new Admin_RtrReporting($this->request);
|
||||
$response = $rtrreporting->runRequest();
|
||||
|
||||
foreach(["info", "success", "warning", "error"] as $level) {
|
||||
if(array_key_exists($level, $response) && $response[$level]) {
|
||||
$this->layout()->setFlash($response[$level], $level);
|
||||
}
|
||||
}
|
||||
|
||||
if($response["redirect"]) {
|
||||
$this->redirect($response["redirect"]);
|
||||
}
|
||||
|
||||
if($response["template"]) {
|
||||
$this->layout()->setTemplate($response["template"]);
|
||||
}
|
||||
|
||||
if(is_array($response["templateVars"]) && count($response["templateVars"])) {
|
||||
foreach($response["templateVars"] as $key => $value) {
|
||||
$this->layout()->set($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function createNetworkAddressForNetowner() {
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
class Admin_RtrReporting {
|
||||
private $request;
|
||||
private $db;
|
||||
private $log;
|
||||
private $flash = [];
|
||||
|
||||
public function __construct($request = false) {
|
||||
$this->request = $request;
|
||||
$this->db = FronkDB::singleton();
|
||||
$this->log = mfLoghandler::singleton();
|
||||
|
||||
}
|
||||
|
||||
public function runRequest() {
|
||||
$action = $this->request->do;
|
||||
if(!$action) {
|
||||
return $this->indexAction();
|
||||
} else {
|
||||
$method = $action."Action";
|
||||
if(method_exists($this, $method)) {
|
||||
return $this->$method();
|
||||
} else {
|
||||
throw new Exception("Method not found", "404");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function indexAction() {
|
||||
|
||||
return [
|
||||
"template" => "Admin/RtrReporting/Index",
|
||||
"redirect" => "",
|
||||
"templateVars" => []
|
||||
];
|
||||
}
|
||||
|
||||
public function a10reportAction() {
|
||||
// alle anschlüsse
|
||||
|
||||
$rasterpunkte = [];
|
||||
foreach(BuildingModel::getAll() as $building) {
|
||||
$raster = $building->laea;
|
||||
if(!$raster) continue;
|
||||
|
||||
$prod_code = 14310;
|
||||
$bb = "1000,00"; // glas = 1000, funk = 50
|
||||
//$user_count = TerminationModel::count(["building_id" => $building->id]);
|
||||
$rtr100m = Rtr100mRaster::getFirst(["raster" => $raster]);
|
||||
if(!$rtr100m) {
|
||||
die("RTR Raster fehlt ".$raster);
|
||||
}
|
||||
$user_count = $rtr100m->unit_count;
|
||||
|
||||
if(!array_key_exists($raster, $rasterpunkte)) {
|
||||
$rasterpunkte[$raster] = [];
|
||||
}
|
||||
if(!array_key_exists($prod_code, $rasterpunkte[$raster])) {
|
||||
$rasterpunkte[$raster][$prod_code] = [
|
||||
"bb" => $bb,
|
||||
"user_count" => 0
|
||||
];
|
||||
}
|
||||
$rasterpunkte[$raster][$prod_code]["user_count"] += $user_count;
|
||||
}
|
||||
|
||||
$building = new Building();
|
||||
$eigen_product_ids = $this->getEigenProductIds();
|
||||
foreach(ContractModel::search(["product_id" => $eigen_product_ids]) as $contract) {
|
||||
if($contract->termination_id) continue;
|
||||
|
||||
$address = $contract->owner;
|
||||
if(!$address->gps_lat || !$address->gps_long || !$address->laea) {
|
||||
$address->save(); // gets gps and laea
|
||||
}
|
||||
|
||||
$raster = $address->laea;
|
||||
if(!$raster) continue;
|
||||
|
||||
$rtr_code = $contract->product->attributes["rtr_tech_code"]->value;
|
||||
if(substr($rtr_code, 0, 4) == 1431) {
|
||||
$prod_code = 14310;
|
||||
$bb = "1000,00";
|
||||
} elseif(substr($rtr_code, 0, 4) == 1042) {
|
||||
$prod_code = 10420;
|
||||
$bb = "50,00";
|
||||
} else {
|
||||
continue; // incompatible product
|
||||
}
|
||||
|
||||
if(!array_key_exists($raster, $rasterpunkte)) {
|
||||
$rasterpunkte[$raster] = [];
|
||||
}
|
||||
if(!array_key_exists($prod_code, $rasterpunkte[$raster])) {
|
||||
$rasterpunkte[$raster][$prod_code] = [
|
||||
"bb" => $bb,
|
||||
"user_count" => 0
|
||||
];
|
||||
}
|
||||
|
||||
$rtr100m = Rtr100mRaster::getFirst(["raster" => $raster]);
|
||||
if(!$rtr100m) {
|
||||
$this->log->warn(__METHOD__.": RTR Raster fehlt ".$raster);
|
||||
continue;
|
||||
}
|
||||
|
||||
$rasterpunkte[$raster][$prod_code]["user_count"] += $rtr100m->unit_count;
|
||||
|
||||
}
|
||||
|
||||
$csv_header = "rasterid;code;dl_min_max_bb;dl_q25_max_bb;dl_avg_max_bb;dl_max_max_bb;ul_min_max_bb;ul_q25_max_bb;ul_avg_max_bb;ul_max_max_bb;dl_min_n_bb;dl_q25_n_bb;dl_avg_n_bb;dl_avg_n_bb;ul_min_n_bb;ul_q25_n_bb;ul_avg_n_bb;ul_avg_n_bb;anz_anschl_cov";
|
||||
$csv = $csv_header."\n";
|
||||
foreach($rasterpunkte as $rastercode => $raster) {
|
||||
foreach($raster as $prod_code => $data) {
|
||||
$csv .= $rastercode . ";";
|
||||
$csv .= $prod_code . ";";
|
||||
for($i = 0; $i < 16; $i++) {
|
||||
$csv .= $data["bb"] . ";";
|
||||
}
|
||||
$csv .= $data["user_count"];
|
||||
$csv .= "\n";
|
||||
}
|
||||
}
|
||||
|
||||
header("Content-type: text/csv; charset=utf-8");
|
||||
header('Content-disposition: attachment; filename="rtr-A10-report-'.date('Y-m-d_H-i-s').'.csv"');
|
||||
|
||||
echo $csv;
|
||||
exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* 1042% = radio
|
||||
* 1431% = fiber
|
||||
*/
|
||||
private function getEigenProductIds() {
|
||||
$product_ids = [];
|
||||
|
||||
$sql = "SELECT product_id FROM `ProductAttribute`
|
||||
LEFT JOIN ProducttechAttribute ON (ProductAttribute.producttechattribute_id = ProducttechAttribute.id)
|
||||
WHERE ProducttechAttribute.name='rtr_tech_code'
|
||||
AND (ProductAttribute.value LIKE '1042%' OR ProductAttribute.value LIKE '1431%')";
|
||||
|
||||
$res = $this->db->query($sql);
|
||||
while($data = $this->db->fetch_object($res)) {
|
||||
$product_ids[] = $data->product_id;
|
||||
}
|
||||
|
||||
return $product_ids;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -200,11 +200,17 @@ class Building extends mfBaseModel {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getLaeaCoordinates() {
|
||||
if(!$this->gps_lat || !$this->gps_lat) {
|
||||
return false;
|
||||
public function getLaeaCoordinates($gps_lat = 0, $gps_long = 0) {
|
||||
if(!$gps_lat || !$gps_long) {
|
||||
$gps_lat = $this->gps_lat;
|
||||
$gps_long = $this->gps_long;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(!$gps_lat || !$gps_long) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Elipsenparameter der Erdoberfläche
|
||||
$a = 6378137;
|
||||
$e = 0.081819191;
|
||||
@@ -221,8 +227,8 @@ class Building extends mfBaseModel {
|
||||
$PI = M_PI;
|
||||
|
||||
// Umrechnung der Eingabekoordinaten in rad
|
||||
$Lat = $this->gps_lat * $PI / 180;
|
||||
$Lon = $this->gps_long * $PI / 180;
|
||||
$Lat = $gps_lat * $PI / 180;
|
||||
$Lon = $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)))));
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
class Rtr100mRaster extends mfBaseModel {
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
|
||||
if(!$this->$name) {
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
}
|
||||
|
||||
if($this->$name->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
/********************************
|
||||
* Begin static Model functions
|
||||
*/
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new Rtr100mRaster();
|
||||
|
||||
$table_fields = [
|
||||
"raster", "unit_count",
|
||||
"create_by","edit_by","create","edit"
|
||||
];
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(in_array($field, $table_fields)) {
|
||||
$model->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
|
||||
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 getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Rtr100mRaster", "*",);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Rtr100mRaster($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT * FROM Rtr100mRaster
|
||||
WHERE $where
|
||||
LIMIT 1";
|
||||
//var_dump($sql);exit;
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Rtr100mRaster($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) as cnt FROM Rtr100mRaster
|
||||
WHERE $where";
|
||||
|
||||
//mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$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, $order = false) {
|
||||
//var_dump($filter);exit;
|
||||
$items = [];
|
||||
|
||||
if(!$order) {
|
||||
$order = "";
|
||||
} else {
|
||||
$order = "ORDER BY $order";
|
||||
}
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT * FROM Rtr100mRaster
|
||||
WHERE $where
|
||||
$order";
|
||||
|
||||
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)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new Rtr100mRaster($data);
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
if(array_key_exists("raster", $filter)) {
|
||||
$raster = FronkDB::singleton()->escape($filter["raster"]);
|
||||
if($raster) {
|
||||
$where .= " AND raster='$raster'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists("add-where", $filter)) {
|
||||
$where .= " ".$filter['add-where'];
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user