Files
thetool/application/FiberPlanPipe/FiberPlanPipeController.php
Daniel Spitzer 8d74d30fba Faserplanung Update
* Umbau Rohrverzeichnis auf Ajax Table
 * Auslagerung der JS vom Rohrverzeichnis in eigene Datei
2024-07-08 21:03:13 +02:00

388 lines
17 KiB
PHP

<?php
class FiberPlanPipeController extends mfBaseController
{
protected function init()
{
$this->needlogin = true;
$me = new User();
$me->loadMe();
$this->me = $me;
$this->layout()->set("me", $me);
if (!$me->is(["Admin"])) {
$this->redirect("Dashboard");
}
}
protected function indexAction()
{
$this->layout()->setTemplate("FiberPlanPipe/Index");
}
protected function addAction()
{
$networks = NetworkModel::getAll();
$fiberplanpipetemplates = FiberPlanPipeModel::getTemplates();
$pipworkeraddresses = FiberPlanPipeModel::getPipeworkerAddresses();
$this->layout()->set("networks", $networks);
$this->layout()->set("pipworkeraddresses", $pipworkeraddresses);
$this->layout()->set("fiberplanpipetemplates", $fiberplanpipetemplates);
$this->layout()->setTemplate("FiberPlanPipe/Form");
}
protected function apiAction()
{
$do = $this->request->do;
$network = $this->request->network_id;
$bdtype = $this->request->bdtype;
switch ($do) {
case "getBuildingInfo":
$return = $this->getBuildingInfo($network, $bdtype);
break;
case "getPops":
$return = $this->getPops($network);
break;
case "getFiberPlanPipes":
$return = $this->getFiberPlanPipes();
break;
default:
$return = false;
}
}
protected function detailAction()
{
$id = $this->request->id;
$this->layout()->setTemplate("FiberPlanPipe/Detail");
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Rohrverzeichnis nicht gefunden", "error");
$this->redirect("FiberPlanPipe");
}
$fiberplanpipes = new FiberPlanPipe($id);
if ($fiberplanpipes->id != $id) {
$this->layout()->setFlash("Rohrverzeichnis nicht gefunden", "error");
$this->redirect("FiberPlanPipe");
}
$pipworkeraddresses = FiberPlanPipeModel::getPipeworkerAddresses();
$fiberplanpipeendpoints = FiberPlanPipeEndpointModel::search(['fiberPlanPipe_id' => $id]);
$this->layout()->set("fiberplanpipes", $fiberplanpipes);
$this->layout()->set("pipworkeraddresses", $pipworkeraddresses);
$this->layout()->set("fiberplanpipeendpoints", $fiberplanpipeendpoints);
}
protected function editAction()
{
$id = $this->request->id;
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Rohrverzeichnis nicht gefunden", "error");
$this->redirect("FiberPlanPipe");
}
$fiberplanpipes = new FiberPlanPipe($id);
if ($fiberplanpipes->id != $id) {
$this->layout()->setFlash("Rohrverzeichnis nicht gefunden", "error");
$this->redirect("FiberPlanPipe");
}
$fiberplanpipeendpoints = FiberPlanPipeEndpointModel::search(['fiberPlanPipe_id' => $id]);
$this->layout()->set("fiberplanpipeendpoints", $fiberplanpipeendpoints);
$this->layout()->set("fiberplanpipes", $fiberplanpipes);
return $this->addAction();
}
protected function saveAction()
{
$r = $this->request;
$id = $r->id;
if (is_numeric($id) && $id > 0) {
$mode = "edit";
$fiberplanpipes = new FiberPlanPipe($id);
if (!$fiberplanpipes->id) {
$this->layout()->setFlash("Rohrverzeichnisse nicht gefunden", "error");
$this->redirect("FiberPlanPipe");
}
} else {
$mode = "add";
}
$data = [];
$data['description'] = trim($r->description);
$data['gisid'] = trim($r->gisid);
$data['type'] = trim($r->type);
$data['type_description'] = trim($r->type_description);
$data['fiberplanpipetemplate_id'] = trim($r->fiberplanpipetemplate_id);
$data['length'] = trim($r->length);
$data['status'] = trim($r->status);
$data['responsible'] = trim($r->responsible);
$data['responsible_text'] = trim($r->responsible_text);
$data['address_id'] = trim($r->address_id);
$data['comment'] = trim($r->comment);
$returnUrl = "FiberPlanPipe";
$returnAction = "Index";
$returnVariables = array();
$returnAnker = "";
if ($this->request->returnto) {
if (strpos($this->request->returnto, "-") !== false) {
$urls = explode('-', $this->request->returnto);
$urlCounter = 0;
$returnUrlGen = "";
foreach ($urls as $url) {
if ($urlCounter > 0) {
$returnUrlGen .= "/";
$returnUrlGen .= ucfirst($url);
} else {
$returnUrlGen .= 'FiberPlanPipe';
}
$urlCounter++;
}
$returnAction = "";
$returnVariables['id'] = $id;
$returnUrl = $returnUrlGen;
} else {
$returnUrl = ucfirst($this->request->returnto);
}
}
if (!$data['description']) {
$this->layout()->setFlash("Bezeichnung darf nicht leer sein", "error");
$this->redirect("FiberPlanPipe");
}
if (!$data['type']) {
$data['type'] = NULL;
}
if (!$data['gisid']) {
$data['gisid'] = NULL;
}
if (!$data['responsible_text']) {
$data['responsible_text'] = NULL;
}
if (!$data['address_id']) {
$data['address_id'] = NULL;
}
if (!$data['type_description']) {
$data['type_description'] = NULL;
}
if (!$data['fiberplanpipetemplate_id']) {
$data['fiberplanpipetemplate_id'] = NULL;
}
if (!$data['length']) {
$data['length'] = NULL;
}
if (!$data['status']) {
$data['status'] = NULL;
}
if (!$data['responsible']) {
$data['responsible'] = NULL;
}
if (!$data['comment']) {
$data['comment'] = NULL;
}
// var_dump($_FILES);
// var_dump($upload);
// exit;
if ($mode == "edit") {
$fiberplanpipes->update($data);
} else {
$fiberplanpipes = FiberPlanPipeModel::create($data);
}
// var_dump($filestore);
// exit;
$id = $fiberplanpipes->save();
$endpoint_id = $r->endpointid;
$endpoint_type = $r->endpoint_type;
$endpoint = $r->endpoint;
if (!empty($endpoint)) {
$fiberplanpipeendpoints = FiberPlanPipeEndpointModel::search(['fiberPlanPipe_id' => $id]);
foreach ($fiberplanpipeendpoints as $fiberplanpipeendpoint) {
if (!in_array($fiberplanpipeendpoint->id, $endpoint_id)) {
$fiberplanpipeendpoint->delete();
}
}
$counter = 1;
foreach ($endpoint as $key => $Endpoint) {
unset($endpointarray);
$endpointarray = [];
$endpointarray['fiberPlanDispatcher_id'] = null;
$endpointarray['pop_id'] = null;
$endpointarray['building_id'] = null;
if ($endpoint_type[$key] == 4 || $endpoint_type[$key] == 1) {
$endpointarray['fiberPlanDispatcher_id'] = $Endpoint;
} else if ($endpoint_type[$key] == 2) {
$endpointarray['pop_id'] = $Endpoint;
} else if ($endpoint_type[$key] == 3) {
$endpointarray['building_id'] = $Endpoint;
}
$endpointarray['fiberPlanPipe_id'] = $id;
$endpointarray['sort'] = $counter;
// print_r($endpointarray);
// var_dump($endpoint_id[$key]);
// die();
if ($endpoint_id[$key]) {
$fiberplanpipeendpoint = new FiberPlanPipeEndpoint($endpoint_id[$key]);
$fiberplanpipeendpoint->update($endpointarray);
unset($endpoint_id[$key]);
} else {
$fiberplanpipeendpoint = FiberPlanPipeEndpointModel::create($endpointarray);
}
$fiberplanpipeendpoint->save();
$counter++;
}
}
if (!$id) {
$this->layout()->setFlash("Rohrverzeichnis konnte nicht angelegt werden", "error");
$this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker);
}
if ($mode == "edit") {
$this->layout()->setFlash("Rohrverzeichnis erfolgreich geändert", "success");
} else if ($mode = "add") {
$this->layout()->setFlash("Rohrverzeichnis erfolgreich angelegt", "success");
}
$this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker);
}
protected function deleteAction()
{
$id = $this->request->id;
$fiberplanpipes = new FiberPlanPipe($id);
if (!$fiberplanpipes->id || $fiberplanpipes->id != $id) {
$this->layout()->setFlash("Rohrverzeichnis nicht gefunden.", "error");
$this->redirect("FiberPlanPipe");
}
$fiberplanpipes->delete();
$this->redirect("FiberPlanPipe");
}
protected function getBuildingInfo($network, $bdtype)
{
FiberPlanPipeModel::getBuildingInfo($network, $bdtype);
}
protected function getFiberPlanPipes()
{
$fiberplanpipes = FiberPlanPipeModel::getAll();
$pipworkeraddresses = FiberPlanPipeModel::getPipeworkerAddresses();
$fiberplanpipeEndpoints = FiberPlanPipeEndpointModel::getAll();
$typeOption = FiberPlanPipeModel::$type_definition;
$statusOption = FiberPlanPipeModel::$status_definition;
$dimension_v1Option = FiberPlanPipeModel::$type_descrition_definition;
$responsibleOption[1] = "(F)";
$responsibleOption[2] = "(P)";
foreach ($pipworkeraddresses as $pipworkeraddress) {
$Pipeworker[$pipworkeraddress->id] = $pipworkeraddress->company;
}
$responsecount = count($fiberplanpipes);
foreach ($fiberplanpipes as $fiberplanpipe) {
unset($networks);
unset($endpoints);
// Performance Killer muss bereinigt werden
foreach ($fiberplanpipeEndpoints[$fiberplanpipe->id] as $fiberplanpipeEndpoint) {
if ($fiberplanpipeEndpoint->pop_id) {
$networks[$fiberplanpipeEndpoint->pop->network->name] = $fiberplanpipeEndpoint->pop->network->name;
$endpoints[] = '<span title="POP">(P) </span>' . $fiberplanpipeEndpoint->pop->name;
} else if ($fiberplanpipeEndpoint->building_id) {
$networks[$fiberplanpipeEndpoint->building->network->name] = $fiberplanpipeEndpoint->building->network->name;
$endpoints[] = '<span title="Building">(B) </span>' . $fiberplanpipeEndpoint->building->street . " " . $fiberplanpipeEndpoint->building->number;
} else if ($fiberplanpipeEndpoint->fiberPlanDispatcher_id) {
$networks[$fiberplanpipeEndpoint->fiberPlanDispatcher->network->name] = $fiberplanpipeEndpoint->fiberPlanDispatcher->network->name;
if ($fiberplanpipeEndpoint->fiberPlanDispatcher->object_type == "1") {
$endpoints[] = '<span title="Verteiler">(V) </span>' . $fiberplanpipeEndpoint->fiberPlanDispatcher->description;
} elseif ($fiberplanpipeEndpoint->fiberPlanDispatcher->object_type == "2") {
$endpoints[] = '<span title="Schacht">(S) </span>' . $fiberplanpipeEndpoint->fiberPlanDispatcher->description;
} else if ($fiberplanpipeEndpoint->fiberPlanDispatcher->object_type == "3") {
$endpoints[] = '<span title="Greenfield">(G) </span>' . $fiberplanpipeEndpoint->fiberPlanDispatcher->description;
} else if ($fiberplanpipeEndpoint->fiberPlanDispatcher->object_type == "4") {
$endpoints[] = '<span title="Abzweigepunkt">(A) </span>' . $fiberplanpipeEndpoint->fiberPlanDispatcher->description;
}
}
}
//....
if ($fiberplanpipe->type == "3") {
$name = "";
if ($fiberplanpipe->fiberPlanPipeTemplate->pipe7x4 && $fiberplanpipe->fiberPlanPipeTemplate->pipe14x10) {
$name = $fiberplanpipe->fiberPlanPipeTemplate->fiberPlanPipeManufacturer->name . " " . $fiberplanpipe->fiberPlanPipeTemplate->pipe7x4 . "*7x4" . "/" . $fiberplanpipe->fiberPlanPipeTemplate->pipe14x10 . "*14x10";
} else if ($fiberplanpipe->fiberPlanPipeTemplate->pipe7x4) {
$name = $fiberplanpipe->fiberPlanPipeTemplate->fiberPlanPipeManufacturer->name . " " . $fiberplanpipe->fiberPlanPipeTemplate->pipe7x4 . "*7x4";
} else if ($fiberplanpipe->fiberPlanPipeTemplate->pipe14x10) {
$name = $fiberplanpipe->fiberPlanPipeTemplate->fiberPlanPipeManufacturer->name . " " . $fiberplanpipe->fiberPlanPipeTemplate->pipe14x10 . "*14x10";
}
$typeDescription = $name;
//
} else {
$typeDescription = $dimension_v1Option[$fiberplanpipe->type_description];
}
$startpoint = '<span class="startpoint" data-toggle="modal" data-target="#pipemap" data-gpslat="' . $buildings[$fiberplanpipe->startpoint_type][$fiberplanpipe->startpoint]['gps_lat'] . '" data-gpslong="' . $buildings[$fiberplanpipe->startpoint_type][$fiberplanpipe->startpoint]['gps_long'] . '">' . $starting_pointOption[$fiberplanpipe->startpoint_type] . "/" . $buildings[$fiberplanpipe->startpoint_type][$fiberplanpipe->startpoint]['name'] . '</span>';
$endpoint = '<span class="endpoint" data-toggle="modal" data-target="#pipemap" data-gpslat="' . $buildings[$fiberplanpipe->entpoint_type][$fiberplanpipe->endpoint]['gps_lat'] . '" data-gpslong="' . $buildings[$fiberplanpipe->entpoint_type][$fiberplanpipe->endpoint]['gps_long'] . '">' . $starting_pointOption[$fiberplanpipe->entpoint_type] . "/" . $buildings[$fiberplanpipe->entpoint_type][$fiberplanpipe->endpoint]['name'] . '</span>';
$responsible = $responsibleOption[$fiberplanpipe->responsible];
if ($fiberplanpipe->address_id) {
$responsible .= " " . $Pipeworker[$fiberplanpipe->address_id];
if ($fiberplanpipe->responsible_text) {
$responsible .= " (" . $fiberplanpipe->responsible_text . ")";
}
} else {
$responsible .= " " . $fiberplanpipe->responsible_text;
}
if ($fiberplanpipe->startpoint_network_id == $fiberplanpipe->endpoint_network_id) {
$networkName = $Network[$fiberplanpipe->startpoint_network_id];
} else {
$networkName = $Network[$fiberplanpipe->startpoint_network_id] . " / " . $Network[$fiberplanpipe->endpoint_network_id];
}
$edit = '<a href="' . self::getUrl("FiberPlanPipe", "edit", ["id" => $fiberplanpipe->id]) . '"><i
class="far fa-edit" title="Bearbeiten"></i></a><a href="' . self::getUrl("FiberPlanPipe", "delete", ["id" => $fiberplanpipe->id]) . '"
onclick="if(!confirm("Rohrverzeichnis wirklich löschen?")) return false;"
class="text-danger"
title="Löschen"><i class="fas fa-trash"></i></a>';
$rows[] = array(
'description' => array('description' => '<a href="' . self::getUrl("FiberPlanPipe", "Detail", ["id" => $fiberplanpipe->id]) . '">' . $fiberplanpipe->description . '</a>', 'order' => $fiberplanpipe->description),
'typeOption' => array('typeOption' => $typeOption[$fiberplanpipe->type] . " / " . $typeDescription, 'order' => $typeOption[$fiberplanpipe->type] . " / " . $typeDescription),
'length' => array('length' => $fiberplanpipe->length, 'order' => $fiberplanpipe->length),
'networks' => array('networks' => implode(',', $networks), 'order' => implode(',', $networks)),
'startpoint' => array('startpoint' => $endpoints[0], 'order' => $endpoints[0]),
'endpoint' => array('endpoint' => $endpoints[count($endpoints) - 1], 'order' => $endpoints[count($endpoints) - 1]),
'responsible' => array('responsible' => $responsible, 'order' => $responsible),
'state' => array('state' => $statusOption[$fiberplanpipe->status], 'order' => $statusOption[$fiberplanpipe->status]),
'edit' => array('edit' => $edit, 'order' => ''),
);
}
$json['success'] = true;
$json['data'] = $rows;
$json['recordsFiltered'] = $responsecount;
$json['recordsTotal'] = $responsecount;
$json = json_encode($json);
echo trim($json);
die();
}
}