Files
thetool/application/FiberPlanCable/FiberPlanCableController.php
Daniel Spitzer 1554d6cf72 Faserplanung Vorbereitung für Kabelverschaltung
* Menüpunkt Kabelverschaltung hinzugefügt
 * Initialfiles für Kabelverschaltung
2024-06-30 12:01:56 +02:00

426 lines
18 KiB
PHP

<?php
class FiberPlanCableController 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("FiberPlanCable/Index");
$fiberplanpipemanufacturers = FiberPlanPipeModel::getAllPipeManufacturer();
$fiberplanpipes = FiberPlanPipeModel::getAllPipe();
$fiberplancables = FiberPlanCableModel::getAll();
$type_descrition_definition = FiberPlanPipeModel::$type_descrition_definition;
$lineworkeraddresses = FiberPlanCableModel::getLineworkerAddresses();
$networks = NetworkModel::getAll();
$this->layout()->set("lineworkeraddresses", $lineworkeraddresses);
$this->layout()->set("networks", $networks);
$this->layout()->set("type_descrition_definition", $type_descrition_definition);
$this->layout()->set("fiberplanpipemanufacturers", $fiberplanpipemanufacturers);
$this->layout()->set("fiberplanpipes", $fiberplanpipes);
$this->layout()->set("fiberplancables", $fiberplancables);
}
protected function apiAction()
{
$do = $this->request->do;
$fiberplanpipe_id = $this->request->fiberplanpipe_id;
$network_id = $this->request->network_id;
$pop_id = $this->request->pop_id;
$dispatcher_id = $this->request->dispatcher_id;
$poprack_id = $this->request->poprack_id;
$bdtype = $this->request->bdtype;
switch ($do) {
case "FiberPlanPipe":
$return = $this->getFiberPlanPipe($network_id);
break;
case "FiberPlanPipeSub":
$return = $this->getFiberPlanPipeSub($fiberplanpipe_id);
break;
case "getPops":
$return = $this->getPops($network);
break;
case "poprack":
$return = $this->getpoprack($pop_id);
break;
case "poprackmodule":
$return = $this->getpoprackmodule($poprack_id);
break;
case "poprackmoduleall":
$return = $this->getpoprackmoduleall($pop_id);
break;
case "dispatchersleeve":
$return = $this->getdispatchersleeve($dispatcher_id);
break;
default:
$return = false;
}
}
protected function detailAction()
{
$id = $this->request->id;
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Kabelverzeichnis nicht gefunden", "error");
$this->redirect("FiberPlanCable");
}
$fiberplancables = new FiberPlanCable($id);
if ($fiberplancables->id != $id) {
$this->layout()->setFlash("Kabelverzeichnis nicht gefunden", "error");
$this->redirect("FiberPlanCable");
}
$fiberPlanCablePipes = FiberPlanCablePipeModel::search(['fiberPlanCable_id' => $id]);
if ($fiberPlanCablePipes) {
foreach ($fiberPlanCablePipes as $fiberPlanCablePipe) {
$fiberPlanPipesEndpoints[] = FiberPlanPipeEndpointModel::search(['fiberPlanPipe_id' => $fiberPlanCablePipe->fiberPlanPipe_id]);
}
}
$fiberPlanCableEndpoints = FiberPlanCableEndpointModel::search(['fiberPlanCable_id' => $id]);
//$fiberPlanPipeSub = FiberPlanCableModel::getFiberPlanPipeSub($fiberplancables->data->fiberPlanPipe_id, 1);
$fiberPlanPipeTemplates = FiberPlanPipeTemplateModel::getAll();
$lineworkeraddresses = FiberPlanCableModel::getLineworkerAddresses();
$fiberplanpipemanufacturers = FiberPlanPipeManufacturerModel::getOne(1);
$this->layout()->set("lineworkeraddresses", $lineworkeraddresses);
$this->layout()->set("fiberplanpipemanufacturers", $fiberplanpipemanufacturers);
// $this->layout()->set("fiberPlanPipeSub", $fiberPlanPipeSub);
$this->layout()->set("fiberplancables", $fiberplancables);
$this->layout()->set("fiberPlanPipeTemplates", $fiberPlanPipeTemplates);
$this->layout()->set("fiberPlanCablePipes", $fiberPlanCablePipes);
$this->layout()->set("fiberPlanPipesEndpoints", $fiberPlanPipesEndpoints);
$this->layout()->set("fiberPlanCableEndpoints", $fiberPlanCableEndpoints);
}
protected function getFiberPlanPipe($network_id)
{
FiberPlanCableModel::getFiberPlanPipe($network_id);
}
protected function getFiberPlanPipeSub($fiberplanpipe_id)
{
FiberPlanCableModel::getFiberPlanPipeSub($fiberplanpipe_id);
}
protected function getpoprack($pop_id)
{
PoprackModel::getpoprack($pop_id);
}
protected function getdispatchersleeve($dispatcher_id)
{
PoprackModel::getdispatchersleeve($dispatcher_id);
}
protected function getpoprackmodule($poprack_id)
{
PoprackmoduleModel::getpoprackmodule($poprack_id);
}
protected function getpoprackmoduleall($pop_id)
{
PoprackmoduleModel::getpoprackmoduleall($pop_id);
}
protected function addAction()
{
$networks = NetworkModel::getAll();
$fiberPlanPipes = FiberPlanPipeModel::getAll();
$lineworkeraddresses = FiberPlanCableModel::getLineworkerAddresses();
$this->layout()->set("networks", $networks);
$this->layout()->set("fiberPlanPipes", $fiberPlanPipes);
$this->layout()->set("lineworkeraddresses", $lineworkeraddresses);
$this->layout()->setTemplate("FiberPlanCable/Form");
}
protected function editAction()
{
$id = $this->request->id;
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Kabelverzeichnis nicht gefunden", "error");
$this->redirect("FiberPlanCable");
}
$fiberplancables = new FiberPlanCable($id);
if ($fiberplancables->id != $id) {
$this->layout()->setFlash("Kabelverzeichnis nicht gefunden", "error");
$this->redirect("FiberPlanCable");
}
$fiberPlanCablePipes = FiberPlanCablePipeModel::search(['fiberPlanCable_id' => $id]);
foreach ($fiberPlanCablePipes as $fiberPlanCablePipe) {
$fiberPlanPipeNetworks[$fiberPlanCablePipe->fiberPlanPipe_id] = FiberPlanPipeEndpointModel::searchNetworks(['fiberPlanPipe_id' => $fiberPlanCablePipe->fiberPlanPipe_id]);
}
if ($fiberPlanCablePipes) {
foreach ($fiberPlanCablePipes as $fiberPlanCablePipe) {
$fiberPlanPipesEndpoints[] = FiberPlanPipeEndpointModel::search(['fiberPlanPipe_id' => $fiberPlanCablePipe->fiberPlanPipe_id]);
}
}
$fiberPlanCableEndpoints = FiberPlanCableEndpointModel::search(['fiberPlanCable_id' => $id]);
$this->layout()->set("fiberplancables", $fiberplancables);
$this->layout()->set("fiberPlanPipeNetworks", $fiberPlanPipeNetworks);
$this->layout()->set("fiberPlanCablePipes", $fiberPlanCablePipes);
$this->layout()->set("fiberPlanPipesEndpoints", $fiberPlanPipesEndpoints);
$this->layout()->set("fiberPlanCableEndpoints", $fiberPlanCableEndpoints);
return $this->addAction();
}
protected function saveAction()
{
$r = $this->request;
$id = $r->id;
if (is_numeric($id) && $id > 0) {
$mode = "edit";
$fiberplancables = new FiberPlanCable($id);
if (!$fiberplancables->id) {
$this->layout()->setFlash("Kabelverzeichnis nicht gefunden", "error");
$this->redirect("FiberPlanCable");
}
} else {
$mode = "add";
}
// $destinationendpoint_sleeve_id = $r->destinationendpoint_sleeve_id;
// $destinationendpoint_sleeve_start = $r->destinationendpoint_sleeve_start;
// $destinationendpoint_sleeve_end = $r->destinationendpoint_sleeve_end;
// if (!empty($destinationendpoint_sleeve_id)) {
// $counter = 0;
// foreach ($destinationendpoint_sleeve_id as $key => $sleeve) {
// if ($destinationendpoint_sleeve_start[$key] && $destinationendpoint_sleeve_end[$key] && $sleeve) {
//
// $endpoint['data'][$counter]['sleeve_id'] = $sleeve;
// $endpoint['data'][$counter]['startport'] = $destinationendpoint_sleeve_start[$key];
// $endpoint['data'][$counter]['endport'] = $destinationendpoint_sleeve_end[$key];
// }
// }
// }
// $endpoint = json_encode($endpoint);
// $destinationstartpoint_poprackmodule_id = $r->destinationstartpoint_poprackmodule_id;
// $destinationstartpoint_poprackmodule_start = $r->destinationstartpoint_poprackmodule_start;
// $destinationstartpoint_poprackmodule_end = $r->destinationstartpoint_poprackmodule_end;
// $destinationstartpoint_poprackmodule_rackid = $r->destinationstartpoint_poprackmodule_rackid;
// $destinationendpoint_poprackmodule_id = $r->destinationendpoint_poprackmodule_id;
// $destinationendpoint_poprackmodule_start = $r->destinationendpoint_poprackmodule_start;
// $destinationendpoint_poprackmodule_end = $r->destinationendpoint_poprackmodule_end;
// $destinationendpoint_poprackmodule_rackid = $r->destinationendpoint_poprackmodule_rackid;
// if (!empty($destinationstartpoint_poprackmodule_id)) {
// $counter = 0;
// $startpoint['pop_id'] = $r->destinationstartpoint_id;
// foreach ($destinationstartpoint_poprackmodule_id as $key => $poprackmodule) {
// $startpoint['data'][$counter]['rack_id'] = $destinationstartpoint_poprackmodule_rackid[$key];
// $startpoint['data'][$counter]['module_id'] = $poprackmodule;
// $startpoint['data'][$counter]['startport'] = $destinationstartpoint_poprackmodule_start[$key];
// $startpoint['data'][$counter]['endport'] = $destinationstartpoint_poprackmodule_end[$key];
// $counter++;
// }
// $startpoint = json_encode($startpoint);
// }
// if (!empty($destinationendpoint_poprackmodule_id)) {
// $counter = 0;
// $endpoint['pop_id'] = $r->destinationendpoint_id;
// foreach ($destinationendpoint_poprackmodule_id as $key => $poprackmodule) {
// $endpoint['data'][$counter]['rack_id'] = $destinationendpoint_poprackmodule_rackid[$key];
// $endpoint['data'][$counter]['module_id'] = $poprackmodule;
// $endpoint['data'][$counter]['startport'] = $destinationendpoint_poprackmodule_start[$key];
// $endpoint['data'][$counter]['endport'] = $destinationendpoint_poprackmodule_end[$key];
// $counter++;
// }
// $endpoint = json_encode($endpoint);
// }
$data = [];
$data['description'] = trim($r->description);
$data['fibers'] = trim($r->fibers);
$data['diameter'] = trim($r->diameter);
$data['lenght'] = trim($r->lenght);
$data['state'] = trim($r->state);
$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 = "FiberPlanCable";
$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 .= 'FiberPlanCable';
}
$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($returnUrl, $returnAction, $returnVariables, $returnAnker);
}
if (!$data['fibers']) {
$this->layout()->setFlash("Fasern darf nicht leer sein", "error");
$this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker);
}
if (!$data['diameter']) {
$this->layout()->setFlash("Durchmesser (MM) darf nicht leer sein", "error");
$this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker);
}
if (!$data['lenght']) {
$this->layout()->setFlash("Länge (M) darf nicht leer sein", "error");
$this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker);
}
if (!$data['state']) {
$this->layout()->setFlash("Status darf nicht leer sein", "error");
$this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker);
}
if (!$data['responsible']) {
$this->layout()->setFlash("Zuständig darf nicht leer sein", "error");
$this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker);
}
if (!$data['responsible_text']) {
$data['responsible_text'] = NULL;
}
if (!$data['address_id']) {
$data['address_id'] = NULL;
}
if (!$data['comment']) {
$data['comment'] = NULL;
}
if ($mode == "edit") {
$fiberplancables->update($data);
} else {
$fiberplancables = FiberPlanCableModel::create($data);
}
$id = $fiberplancables->save();
if (!$id) {
$this->layout()->setFlash("Kabelverzeichnis konnte nicht angelegt werden", "error");
$this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker);
}
$fiberplanpipe = $r->fiberplanpipe;
$fiberplanpipe_id = $r->fiberplanpipe_id;
$fiberplanpipesub = $r->fiberplanpipesub;
if ($fiberplanpipe) {
$FiberPlanCablePipes = FiberPlanCablePipeModel::search(['fiberPlanCable_id' => $id]);
$counter = 1;
foreach ($fiberplanpipe as $key => $pipe) {
$data = [];
$data['fiberPlanCable_id'] = $id;
$data['fiberPlanPipe_id'] = $pipe;
$data['fiberPlanPipe_sub'] = $fiberplanpipesub[$key];
$data['sort'] = $counter;
$data['direction'] = 0;
if (is_numeric($fiberplanpipe_id[$key])) {
$fiberPlanCablePipe = new FiberPlanCablePipe($fiberplanpipe_id[$key]);
$fiberPlanCablePipe->update($data);
unset($FiberPlanCablePipes[$fiberplanpipe_id[$key]]);
} else {
$fiberPlanCablePipe = FiberPlanCablePipeModel::create($data);
}
$idfpp = $fiberPlanCablePipe->save();
$counter++;
}
foreach ($FiberPlanCablePipes as $FiberPlanCablePipe) {
$FiberPlanCablePipe->delete();
}
}
// if ($r->destinationstartpoint_poprackmodule_id) {
// PoprackmodulepatchModel::clearPort($id);
// $destinationstartpoint_poprackmodule_start = $r->destinationstartpoint_poprackmodule_start;
// $destinationstartpoint_poprackmodule_end = $r->destinationstartpoint_poprackmodule_end;
// foreach ($r->destinationstartpoint_poprackmodule_id as $key => $poprackmodule) {
// $startport = $destinationstartpoint_poprackmodule_start[$key];
// $endport = $destinationstartpoint_poprackmodule_end[$key];
// PoprackmodulepatchModel::updatebyPortRange($poprackmodule, $startport, $endport, $id);
// }
//
// }
// if ($r->destinationendpoint_poprackmodule_id) {
// PoprackmodulepatchModel::clearPort($id);
// $destinationendpoint_poprackmodule_start = $r->destinationendpoint_poprackmodule_start;
// $destinationendpoint_poprackmodule_end = $r->destinationendpoint_poprackmodule_end;
// foreach ($r->destinationendpoint_poprackmodule_id as $key => $poprackmodule) {
// $startport = $destinationendpoint_poprackmodule_start[$key];
// $endport = $destinationendpoint_poprackmodule_end[$key];
// PoprackmodulepatchModel::updatebyPortRange($poprackmodule, $startport, $endport, $id);
// }
//
// }
if ($mode == "edit") {
$this->layout()->setFlash("Kabelverzeichnis erfolgreich geändert", "success");
} else if ($mode = "add") {
$this->layout()->setFlash("Kabelverzeichnis erfolgreich angelegt", "success");
}
$this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker);
}
protected function deleteAction()
{
$id = $this->request->id;
$fiberplancables = new FiberPlanCable($id);
if (!$fiberplancables->id || $fiberplancables->id != $id) {
$this->layout()->setFlash("Kabelverzeichnis nicht gefunden.", "error");
$this->redirect("FiberPlanCable");
}
$fiberplancables->delete();
$this->redirect("FiberPlanCable");
}
}