Merge branch 'fronkdev' into 'master'
ConstructionConsent: Plan from Mapbox with Rimo coords See merge request fronk/thetool!923
This commit is contained in:
@@ -247,24 +247,32 @@ class ConstructionConsentController extends mfBaseController {
|
||||
return $this->editAction();
|
||||
}
|
||||
|
||||
} else {
|
||||
if($r->submit_plan_file_id) {
|
||||
$file = new File($r->submit_plan_file_id);
|
||||
}
|
||||
}
|
||||
|
||||
if($file && $file->id) {
|
||||
$ccf = ConstructionConsentFile::create([
|
||||
'constructionconsent_id' => $id,
|
||||
'file_id' => $file->id,
|
||||
'filename' => "zustimmungserklärung-".$item->id."-plan.png",
|
||||
'filename' => "zustimmungserklärung-" . $item->id . "-plan.png",
|
||||
]);
|
||||
|
||||
// delete previous image
|
||||
$img = ConstructionConsentFile::getFirst(["constructionconsent_id" => $id]);
|
||||
if($img) {
|
||||
if ($img) {
|
||||
$img->file->delete();
|
||||
$img->delete();
|
||||
}
|
||||
|
||||
if(!$ccf->save()) {
|
||||
$this->layout()->setFlash("Fehler beim Hochladen", "warning");
|
||||
if (!$ccf->save()) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern des Plans", "warning");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->layout()->setFlash("Zustimmungserklärung erfolgreich gespeichert", "success");
|
||||
$this->redirect("ConstructionConsent", "View", ["id" => $id]);
|
||||
|
||||
@@ -281,6 +289,15 @@ class ConstructionConsentController extends mfBaseController {
|
||||
case "findStreet":
|
||||
$return = $this->findStreetApi();
|
||||
break;
|
||||
case "findAddress":
|
||||
$return = $this->findAddressApi();
|
||||
break;
|
||||
case "getRimoPlanPreview":
|
||||
$return = $this->getRimoPlanPreviewApi();
|
||||
break;
|
||||
case "saveRimoPlanPreview":
|
||||
$return = $this->saveRimoPlanPreviewApi();
|
||||
break;
|
||||
default:
|
||||
$this->log->warn(__METHOD__ . ": Called API function '$do' does not exist");
|
||||
$return = false;
|
||||
@@ -425,4 +442,276 @@ class ConstructionConsentController extends mfBaseController {
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
private function findAddressApi() {
|
||||
$addresses = [];
|
||||
$search = trim($this->request->q);
|
||||
$project_id = $this->request->project_id;
|
||||
$include_gst = $this->request->include_gst ? $this->request->include_gst : false;
|
||||
|
||||
$scluster_ids = [];
|
||||
|
||||
if($project_id) {
|
||||
$project = new ConstructionConsentProject($project_id);
|
||||
if(!$project->id) {
|
||||
header("Content-Type: application/json");
|
||||
echo json_encode(["results" => []]);
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach($project->adb_networks as $network) {
|
||||
$scluster_ids[] = $network->id;
|
||||
}
|
||||
} else {
|
||||
// get all salesclusters
|
||||
foreach(ADBNetzgebietModel::getAll() as $network) {
|
||||
$scluster_ids[] = $network->id;
|
||||
}
|
||||
}
|
||||
|
||||
$results = [];
|
||||
|
||||
$search_parts = explode(" ", $search);
|
||||
|
||||
$ort_search = $strasse_search = $plz_search = $hausnummer_search = $gst_search = [];
|
||||
|
||||
foreach($search_parts as $p) {
|
||||
$p = $this->db->escape(trim($p));
|
||||
if(!$p) continue;
|
||||
$ort_search[] = "ortschaft like '$p%'";
|
||||
$strasse_search[] = "strasse like '$p%'";
|
||||
$plz_search[] = "plz like '%$p%'";
|
||||
$hausnummer_search[] = "hausnummer like '%$p%'";
|
||||
$gst_search[] = "grund_nr like '%$p%'";
|
||||
}
|
||||
|
||||
$where = "1=1";
|
||||
if(count($scluster_ids)) {
|
||||
$where .= " AND netzgebiet_id IN (".implode(', ',$scluster_ids).")";
|
||||
}
|
||||
|
||||
if($include_gst) {
|
||||
$sql = "SELECT * FROM view_hausnummer WHERE $where AND ((".implode(" OR ", $ort_search).") OR (".implode(" OR ", $strasse_search).") OR (".implode(" OR ", $plz_search).") OR (".implode(" OR ", $hausnummer_search).") OR (".implode(" OR ", $gst_search).") ) ORDER BY strasse, LENGTH(hausnummer), hausnummer";
|
||||
} else {
|
||||
$sql = "SELECT * FROM view_hausnummer WHERE $where AND ((".implode(" OR ", $ort_search).") OR (".implode(" OR ", $strasse_search).") OR (".implode(" OR ", $plz_search).") OR (".implode(" OR ", $hausnummer_search).")) ORDER BY strasse, LENGTH(hausnummer), hausnummer";
|
||||
}
|
||||
|
||||
|
||||
$this->log->debug($sql);
|
||||
|
||||
$adb = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
$res = $adb->query($sql);
|
||||
$this->log->debug("done");
|
||||
|
||||
if(!$adb->num_rows($res)) {
|
||||
header("Content-Type: application/json");
|
||||
echo json_encode(["results" => []]);
|
||||
exit;
|
||||
}
|
||||
|
||||
while($data = $adb->fetch_object($res)) {
|
||||
$address_string = $data->plz." ".$data->ortschaft.", ".$data->strasse." ".$data->hausnummer;
|
||||
if($include_gst) {
|
||||
$address_string .= " | GST: ".$data->grund_nr;
|
||||
}
|
||||
$sort_key = $data->plz." ".$data->ortschaft." ".$data->strasse;
|
||||
|
||||
$address = [];
|
||||
$address['id'] = $data->hausnummer_id;
|
||||
$address["text"] = $address_string;
|
||||
$address['sort_key'] = $sort_key;
|
||||
$addresses[] = $address;
|
||||
}
|
||||
|
||||
|
||||
// sort results by most occurences of search strings
|
||||
$sort = [];
|
||||
foreach($addresses as $key => $address) {
|
||||
$includes_int = false;
|
||||
$count = 0;
|
||||
foreach($search_parts as $p) {
|
||||
$p = $this->db->escape(trim($p));
|
||||
if(!$p) continue;
|
||||
if(is_numeric(($p))) {
|
||||
$includes_int = true;
|
||||
if(substr_count(strtolower($address['text']), strtolower($p))) {
|
||||
$count++;
|
||||
}
|
||||
} else {
|
||||
$count += substr_count(strtolower($address['text']), strtolower($p));
|
||||
}
|
||||
}
|
||||
unset($address['sort_key']);
|
||||
//echo $address['text']." $p $count<br />\n";
|
||||
|
||||
if($includes_int && (($count + 1) - count($search_parts) ) < 1) {
|
||||
continue;
|
||||
}
|
||||
if(!array_key_exists($count, $sort)) {
|
||||
$sort[$count] = [];
|
||||
}
|
||||
$sort[$count][] = $address;
|
||||
}
|
||||
|
||||
ksort($sort, SORT_NUMERIC);
|
||||
$sort = array_reverse($sort, true);
|
||||
//var_dump($sort);exit;
|
||||
|
||||
foreach($sort as $res) {
|
||||
foreach($res as $a) {
|
||||
$results[] = $a;
|
||||
}
|
||||
}
|
||||
|
||||
header("Content-Type: application/json");
|
||||
echo json_encode(["results" => $results]);
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
private function getRimoPlanPreviewApi() {
|
||||
$adb_hausnummer_id = $this->request->building_id;
|
||||
|
||||
$hausnummer = new ADBHausnummer($adb_hausnummer_id);
|
||||
if(!$hausnummer->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$filename = "consent_plan_map_h{$adb_hausnummer_id}";
|
||||
|
||||
/*$bpi_file = PreorderFile::getFirst(["preorder_id" => $this->id, "filename" => $filename]);
|
||||
if($bpi_file) {
|
||||
return $bpi_file;
|
||||
}*/
|
||||
|
||||
// get trenches from rimo
|
||||
$geodataResponse = Rimoapi::getBuildingGeoJson($hausnummer->rimo_id);
|
||||
$this->log->debug(__METHOD__.": ".print_r($geodataResponse, true));
|
||||
//return false;
|
||||
|
||||
if (is_object($geodataResponse)) {
|
||||
if (property_exists($geodataResponse, "homeSection")) {
|
||||
if (property_exists($geodataResponse->homeSection, "features") && is_array($geodataResponse->homeSection->features)) {
|
||||
foreach ($geodataResponse->homeSection->features as $feature) {
|
||||
$home_trench = [];
|
||||
foreach ($feature->geometry->coordinates as $coords) {
|
||||
$long = $coords[0];
|
||||
$lat = $coords[1];
|
||||
$home_trench[] = [$lat, $long];
|
||||
}
|
||||
if ($hausnummer->home_trench != $home_trench) {
|
||||
$hausnummer->home_trench = json_encode($home_trench);
|
||||
$hausnummer->save();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (property_exists($geodataResponse, "borderPoint")) {
|
||||
if (property_exists($geodataResponse->borderPoint, "features") && is_array($geodataResponse->borderPoint->features)) {
|
||||
foreach ($geodataResponse->borderPoint->features as $feature) {
|
||||
$coords = $feature->geometry->coordinates;
|
||||
$long = $coords[0];
|
||||
$lat = $coords[1];
|
||||
if ($hausnummer->borderpoint_lat != $lat || $hausnummer->borderpoint_long != $long) {
|
||||
$hausnummer->borderpoint_lat = $lat;
|
||||
$hausnummer->borderpoint_long = $long;
|
||||
$hausnummer->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (property_exists($geodataResponse, "trenches") && $geodataResponse->trenches->features) {
|
||||
$trenches = [];
|
||||
foreach ($geodataResponse->trenches->features as $feature) {
|
||||
$feature_coords = [];
|
||||
foreach ($feature->geometry->coordinates as $coords) {
|
||||
$long = $coords[0];
|
||||
$lat = $coords[1];
|
||||
$feature_coords[] = [$lat, $long];
|
||||
}
|
||||
$trenches[] = $feature_coords;
|
||||
}
|
||||
if (count($trenches)) {
|
||||
$hausnummer->trenches = json_encode($trenches);
|
||||
$hausnummer->save();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// get new Borderpoint Image from Mapbox API
|
||||
$params = [
|
||||
"pin" => null,
|
||||
"gps_lat" => $hausnummer->gps_lat,
|
||||
"gps_long" => $hausnummer->gps_long,
|
||||
"zoom" => 19,
|
||||
"size_x" => 640,
|
||||
"size_y" => 640,
|
||||
"style" => "satellite-streets-v12",
|
||||
"paths" => "",
|
||||
"access_token" => TT_MAPBOX_TILE_API_TOKEN
|
||||
];
|
||||
|
||||
if($hausnummer->trenches) {
|
||||
$trenches = json_decode($hausnummer->trenches);
|
||||
|
||||
$params["paths"] = [
|
||||
"line_width" => 5,
|
||||
"line_color" => "ff0000",
|
||||
"line_opacity" => 1,
|
||||
"line_fill_color" => "ff0000",
|
||||
"line_fill_opacity" => 1,
|
||||
"coords" => $trenches
|
||||
];
|
||||
}
|
||||
|
||||
$image_content = Mapbox_StaticImageApi::getImageFileContent($params);
|
||||
if(!$image_content) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$fs_filename = "$filename.jpg";
|
||||
if(!file_put_contents(MFUPLOAD_FILE_SAVE_PATH."/".TT_CONSTRUCTIONCONSENT_FILE_UPLOAD_SUBFOLDER."/$fs_filename", $image_content)) {
|
||||
$this->log->error(__METHOD__.": Error saving Borderpoint Static Map Image File");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$file = FileModel::create([
|
||||
"name" => "consent_plan_map",
|
||||
"description" => $adb_hausnummer_id,
|
||||
"filename" => "$filename.jpg",
|
||||
"orig_filename" => "$filename.jpg",
|
||||
"store_filename" => $fs_filename,
|
||||
"subfolder" => TT_CONSTRUCTIONCONSENT_FILE_UPLOAD_SUBFOLDER,
|
||||
]);
|
||||
if(!$file->save()) {
|
||||
$this->log->error(__METHOD__.": Error saving File Object");
|
||||
return false;
|
||||
}
|
||||
|
||||
$file->mimetype = $file->getMimetype();
|
||||
$file->save();
|
||||
|
||||
return ["image_mimetype" => $file->mimetype, "image_base64" => base64_encode($image_content), "file_id" => $file->id];
|
||||
|
||||
/*$pf = PreorderFile::create([
|
||||
"preorder_id" => $this->id,
|
||||
"file_id" => $file->id,
|
||||
"filename" => $filename
|
||||
]);
|
||||
|
||||
if(!$pf->save()) {
|
||||
$this->log->error(__METHOD__.": Error saving PreorderFile Object");
|
||||
return false;
|
||||
}*/
|
||||
|
||||
//return $pf;
|
||||
}
|
||||
|
||||
private function saveRimoPlanPreviewApi() {
|
||||
$adb_hausnummer_id = $this->request->building_id;
|
||||
$consent_id = $this->request->constructionconsent_id;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user