Faserplanung

* Schächte/Verteiler
 * Rohrplanung
This commit is contained in:
Spitzer Daniel
2024-04-16 16:55:16 +02:00
parent f2ac8e9d70
commit e3f8c2326e
17 changed files with 2806 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
<?php
class FiberPlanPipe extends mfBaseModel
{
private $editor;
private $creator;
private $network;
private $fiberPlanPipeManufacturer;
private $fiberPlanPipeTemplate;
public function getProperty($name)
{
if ($this->$name == null) {
if (!$this->id) {
return null;
}
if($name == "creator") {
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
if($this->creator === null) {
$this->creator = new User($this->create_by);
if($this->creator->id) {
mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator);
}
}
return $this->creator;
}
if($name == "editor") {
$this->editor = mfValuecache::singleton()->get("Worker-id-".$this->edit_by);
if($this->editor === null) {
$this->editor = new User($this->edit_by);
if($this->editor->id) {
mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor);
}
}
return $this->editor;
}
$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;
}
}

View File

@@ -0,0 +1,281 @@
<?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()
{
$networks = NetworkModel::getAll();
$this->layout()->setTemplate("FiberPlanPipe/Index");
$fiberplanpipes = FiberPlanPipeModel::getAll();
$pipworkeraddresses = FiberPlanPipeModel::getPipeworkerAddresses();
$buildings = FiberPlanPipeModel::getBuildingInfoAll();
$this->layout()->set("networks", $networks);
$this->layout()->set("buildings", $buildings);
$this->layout()->set("pipworkeraddresses", $pipworkeraddresses);
$this->layout()->set("fiberplanpipes", $fiberplanpipes);
}
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;
default:
$return = false;
}
}
protected function detailAction()
{
$id = $this->request->id;
$networks = NetworkModel::getAll();
$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");
}
$this->layout()->set("fiberplanpipes", $fiberplanpipes);
$pipworkeraddresses = FiberPlanPipeModel::getPipeworkerAddresses();
$buildings = FiberPlanPipeModel::getBuildingInfoAll();
$fiberplanpipeendpoints = FiberPlanPipeEndpointModel::search(['fiberPlanPipe_id' => $id]);
$this->layout()->set("networks", $networks);
$this->layout()->set("buildings", $buildings);
$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;
var_dump($r->get());
die();
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['startpoint']) {
$data['startpoint'] = NULL;
}
if (!$data['endpoint']) {
$data['endpoint'] = 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)) {
$counter = 1;
foreach ($endpoint as $key => $Endpoint) {
if ($endpoint_type[$key] == 4) {
$endpointarray['fiberPlanDispatcher_id'] = $Endpoint;
} else if ($endpoint_type[$key] == 2) {
$endpointarray['pop_id'] = $Endpoint;
}
$endpointarray['fiberPlanPipe_id'] = $id;
$endpointarray['sort'] = $counter;
if ($endpoint_id[$key]) {
$fiberplanpipeendpoint = new FiberPlanPipeEndpoint($id);
$fiberplanpipeendpoint->update($endpointarray);
} 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);
}
}

View File

@@ -0,0 +1,376 @@
<?php
class FiberPlanPipeModel
{
private $network_id;
private $description;
private $gisid;
private $type;
private $type_description;
private $fiberplanpipetemplate_id;
private $length;
private $startpoint_type;
private $startpoint_network_id;
private $startpoint;
private $midpoint;
private $endpoint_network_id;
private $entpoint_type;
private $endpoint;
private $status;
private $responsible;
private $responsible_text;
private $address_id;
private $comment;
public static $type_descrition_definition = array(1 => "MR7", 2 => "MR14", 3 => "MR16", 4 => "MR20", 5 => "PE32", 6 => "PE40", 7 => "PE50", 8 => "KSR50", 9 => "KSR80", 10 => "KSR100");
public static $type_definition = array(1 => "Enzel", 2 => "Schutzrohr", 3 => "Verband");
public static function find($data)
{
}
public static function create(array $data)
{
$model = new FiberPlanPipe();
foreach ($data as $field => $value) {
if (property_exists(get_called_class(), $field)) {
if (substr($field, 0, 5) == "vlan_" && !$value) {
$model->$field = null;
continue;
}
$model->$field = $value;
}
}
$me = mfValuecache::singleton()->get("me");
if (!$me) {
$me = new User();
$me->loadMe();
mfValuecache::singleton()->set("me", $me);
}
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 getOne($id)
{
if (!is_numeric($id) || !$id) {
throw new Exception("Invalid number", 400);
}
$item = [];
$db = FronkDB::singleton();
$res = $db->select("FiberPlanPipe", "*", "id=$id LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new FiberPlanPipe($data);
}
return $item;
}
public static function getAll()
{
$items = [];
$db = FronkDB::singleton();
$res = $db->select("FiberPlanPipe", "*", "1=1");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanPipe($data);
}
}
return $items;
}
public static function getAllPipeManufacturer()
{
$items = [];
$db = FronkDB::singleton();
$res = $db->select("FiberPlanPipeManufacturer", "*", "1=1");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanPipe($data);
}
}
return $items;
}
public static function getAllPipe()
{
$items = [];
$db = FronkDB::singleton();
$sql = "SELECT `FiberPlanPipe`.`id`,`FiberPlanPipe`.`description`,`FiberPlanPipe`.`type`,`FiberPlanPipe`.`type_description`,`FiberPlanPipe`.`startpoint_network_id`, `FiberPlanPipe`.`endpoint_network_id`,`FiberPlanPipeTemplate`. `fiberPlanPipeManufacturer_id`,`FiberPlanPipeTemplate`.`pipe7x4`,`FiberPlanPipeTemplate`.`pipe14x10` FROM `FiberPlanPipe`
LEFT JOIN `FiberPlanPipeTemplate` ON `FiberPlanPipe`.`fiberPlanPipeTemplate_id`=`FiberPlanPipeTemplate`.id";
$res = $db->query($sql);
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanPipe($data);
}
}
return $items;
}
public static function getFirst()
{
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("FiberPlanPipe", "*", "$where ");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new FiberPlanPipe($data);
if ($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function search($filter)
{
$items = [];
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("FiberPlanPipe", "*", "$where");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanPipe($data);
}
}
return $items;
}
private static function getSqlFilter($filter)
{
$where = "1=1 ";
//var_dump($filter);exit;
if (array_key_exists("network_id", $filter)) {
$networkid = $filter['network_id'];
if (is_numeric($networkid)) {
$where .= " AND network_id=$networkid";
}
}
//var_dump($filter, $where);exit;
return $where;
}
public static function getTemplates()
{
$items = [];
$db = FronkDB::singleton();
$sql = "SELECT `FiberPlanPipeTemplate`.id,FiberPlanPipeTemplate.pipe7x4,FiberPlanPipeTemplate.pipe14x10,FiberPlanPipeManufacturer.name FROM `FiberPlanPipeTemplate` INNER JOIN FiberPlanPipeManufacturer ON FiberPlanPipeManufacturer.id=FiberPlanPipeTemplate.fiberPlanPipeManufacturer_id ";
$res = $db->query($sql);
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanPipe($data);
}
}
return $items;
}
public static function getPipeworkerAddresses()
{
$items = [];
$db = FronkDB::singleton();
$sql = "SELECT `Addresstype`.`id`,`Address`.`company` FROM `Addresstype`
INNER JOIN `Address` ON (`Address`.`id`=`Addresstype`.`address_id`)
WHERE `type` = 'pipeworker' ORDER by `Address`.`company` ";
$res = $db->query($sql);
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanPipe($data);
}
}
return $items;
}
public static function getBuildingInfo($network, $bdtype, $api = 1)
{
$items = [];
$db = FronkDB::singleton();
if ($bdtype == "1") {
$sql = "SELECT `id`,`description` `name` FROM `FiberPlanDispatcher` WHERE network_id='" . $network . "' AND `object_type`='3' ";
} else if ($bdtype == "2") {
$sql = "SELECT `Pop`.`id`,`Pop`.`name` FROM `PopNetwork`
INNER JOIN `Pop` ON (`Pop`.`id`=`PopNetwork`.`pop_id`)
WHERE `PopNetwork`.`network_id`='" . $network . "'";
} else if ($bdtype == "3") {
$sql = "SELECT `id`,`code` ,`street`, `zip`, `city` name FROM Building WHERE network_id='" . $network . "' ORDER by street";
} else if ($bdtype == "4") {
$sql = "SELECT `id`,`description` `name` FROM `FiberPlanDispatcher` WHERE network_id='" . $network . "' AND (`object_type`='1' OR `object_type`='2') ";
}
$res = $db->query($sql);
if ($db->num_rows($res)) {
$counter = 0;
while ($data = $db->fetch_array($res)) {
$items[$counter]['id'] = $data['id'];
if ($bdtype == "3") {
$items[$counter]['name'] = $data['street'] . " " . $data['zip'] . " " . $data['city'];
} else {
$items[$counter]['name'] = $data['name'];
}
$counter++;
}
}
if ($api === 1) {
echo json_encode($items);
exit;
} else {
return $items;
}
}
public static function getBuildingInfoAll()
{
$items = [];
$db = FronkDB::singleton();
$sql = "SELECT `id`, `fiberPlanDispatcher_id`, `name` FROM `FiberPlanDispatchersleeve` ORDER by id";
$res = $db->query($sql);
if ($db->num_rows($res)) {
while ($data = $db->fetch_array($res)) {
$sleeves[$data['fiberPlanDispatcher_id']][$data['id']] = $data['name'];
}
}
$sql = "SELECT '1' as `type`,'Greenfield' as `typename`,`id`,`description` as `name`,`gps_lat`,`gps_long` FROM `FiberPlanDispatcher` WHERE `object_type`='3'
UNION
SELECT '2' as `type`,'Pop' as `typename`,`id`,`name`,`gps_lat`,`gps_long` FROM `Pop`
UNION
SELECT '3' as `type`,'Building' as `typename`,`id`,CONCAT_WS(' ',`street`, `zip`, `city`) as name,`gps_lat`,`gps_long` FROM Building
UNION
SELECT '4' as `type`,'Schacht-Verteiler' as `typename`,`id`,`description` as `name`,`gps_lat`,`gps_long` FROM `FiberPlanDispatcher` WHERE (`object_type`='1' OR `object_type`='2')";
$res = $db->query($sql);
if ($db->num_rows($res)) {
while ($data = $db->fetch_array($res)) {
$items[$data['type']][$data['id']] = $data;
if ($data['type'] == 4) {
$items[$data['type']][$data['id']]['sleeves'] = $sleeves[$data['id']];
}
}
}
return $items;
}
public static function generateEndpoints($endpoints, $networks)
{
foreach ($networks as $network) {
$Network[$network->id] = $network->name;
}
$counter = 1;
$endpointuparrow = "";
$typeArray[1] = 'Greenfield';
$typeArray[2] = 'POP';
$typeArray[3] = 'Building';
$typeArray[4] = 'Schacht-Verteiler';
// print_r($buildings);
$counter = 1;
foreach ($endpoints as $Endpoint) {
if ($Endpoint->pop_id) {
$networkid = $Endpoint->pop->network_id;
$endpointid = $Endpoint->pop->id;
$endpointtype = 2;
} else if ($Endpoint->fiberPlanDispatcher_id) {
$networkid = $Endpoint->fiberPlanDispatcher->network_id;
$endpointid = $Endpoint->fiberPlanDispatcher->id;
if ($Endpoint->fiberPlanDispatcher->object_type == 3) {
$endpointtype = 1;
} else {
$endpointtype = 4;
}
} else if ($Endpoint->building_id) {
$networkid = $Endpoint->building->network_id;
$endpointid = $Endpoint->building->id;
$endpointtype = 3;
}
$randid = rand(1000, 10000);
if ($counter > 1) {
$Endpointuparrow = '<i title="nach oben verschieben" class="fa-sharp fa-solid fa-up move-endpoint-up"></i>';
}
if ($counter == 1) {
$endpointType = "Startpunkt";
$endpointsymbol = '<span class="endpointsymbol"><i id="add-endpoint" class="fa-regular fa-circle-plus"></i></span>';
}
else if (count($endpoints)==2)
{
$endpointcount = $counter - 1;
$endpointType = "Standort " . $endpointcount;
$endpointsymbol='<span class="endpointsymbol">';
}
else {
$endpointcount = $counter - 1;
$endpointType = "Standort " . $endpointcount;
$endpointsymbol = '<span class="endpointsymbol"><i class="fa-regular fa-circle-minus remove-endpoint"></i></span>';
}
$html = '<div class="form-group row endpoint-maindiv">
<label class="col-lg-2 col-form-label endpoint-label" for="' . $randid . '_endpoint_network_id"><span class="label-text">' . $endpointType . ' * </span>' . $Endpointuparrow . $endpointsymbol . '</label>
<div class="col-lg-2"><select id="' . $randid . '_endpoint_network_id" required="required" name="endpoint_network_id[]" class="select2 form-control endpoint_network_id">';
foreach ($networks as $network) {
if ($network->id == $networkid) {
$html .= '<option selected="selected" value="' . $network->id . '">' . $network->name . '</option>';
} else {
$html .= '<option value="' . $network->id . '">' . $network->name . '</option>';
}
}
$html .= '</select></div>
<div class="col-lg-2 ">
<select id="' . $randid . '_endpoint_type" name="endpoint_type[]" required="required" class="select2 form-control endpoint_type" >';
foreach ($typeArray as $key => $type) {
if ($key == $endpointtype) {
$html .= '<option selected="selected" value="' . $key . '">' . $type . '</option>';
} else {
$html .= '<option value="' . $key . '">' . $type . '</option>';
}
}
$html .= '</select></div>
<div class="col-lg-2" id="' . $randid . '_end-point-building">
<select id=' . $randid . '_endpoint" required="required" name="endpoint[]" class="select2 form-control">';
$buildings = FiberPlanPipeModel::getBuildingInfo($networkid, $endpointtype, 0);
foreach ($buildings as $key => $building) {
if ($building['id'] == $endpointid) {
$html .= '<option selected="selected" value="' . $building['id'] . '">' . $building['name'] . '</option>';
} else {
$html .= '<option value="' . $building['id'] . '">' . $building['name'] . '</option>';
}
}
$html .= '</select><input type="hidden" name="endpointid[]" value="' . $Endpoint->id . '" ></div></div>';
echo $html;
$counter++;
}
}
}