Features:

* Komplettes kabelmanagement auf Rack He Modul Basis
This commit is contained in:
Daniel Spitzer
2025-12-02 12:48:51 +01:00
parent 3677a21fc5
commit 68f29ab995
12 changed files with 7531 additions and 681 deletions

View File

@@ -25,7 +25,11 @@ class FiberPlanCableModel
private $address_id;
private $network_id;
private $comment;
private $parent_cable_id;
private $is_branch_cable;
private $branch_from_location;
private $branch_to_location;
private $coordinates;
public static $fibersArray = array(1 => 4, 2 => 12, 3 => 24, 4 => 24, 5 => 48, 6 => 96, 7 => 144, 8 => 144, 9 => 192, 10 => 288);
public static function find($data)
@@ -132,12 +136,26 @@ class FiberPlanCableModel
private static function getSqlFilter($filter)
{
$where = "1=1 ";
if (array_key_exists("description", $filter) && $filter['description']) {
$description = $filter['description'];
$where .= " AND description='$description'";
}
//var_dump($filter);exit;
if (array_key_exists("network_id", $filter)) {
$networkid = $filter['network_id'];
if (is_numeric($networkid)) {
$where .= " AND network_id=$networkid";
if (is_array($filter['network_id'])) {
$ids = array_map('intval', $filter['network_id']);
$ids = array_filter($ids, function($id) { return $id > 0; });
if (!empty($ids)) {
$idList = implode(',', $ids);
$where .= " AND network_id IN ($idList)";
}
} else {
$network_id = intval($filter['network_id']);
if ($network_id > 0) {
$where .= " AND network_id=$network_id";
} elseif ($network_id === 0) {
$where .= " AND (network_id IS NULL OR network_id=0)";
}
}
}
@@ -239,7 +257,51 @@ INNER JOIN `Address` ON (`Address`.`id`=`Addresstype`.`address_id`)
return $items;
}
public static function getCableRoute($cable_id) {
$route = [];
$db = FronkDB::singleton();
// SQL-Abfrage mit object_type für Dispatcher
$sql = "SELECT
fcs.station_order,
fcs.station_type,
fcs.station_id,
CASE
WHEN fcs.station_type = 'pop' THEN p.name
WHEN fcs.station_type = 'dispatcher' THEN d.description
END as station_name,
CASE
WHEN fcs.station_type = 'pop' THEN p.gps_lat
WHEN fcs.station_type = 'dispatcher' THEN d.gps_lat
END as gps_lat,
CASE
WHEN fcs.station_type = 'pop' THEN p.gps_long
WHEN fcs.station_type = 'dispatcher' THEN d.gps_long
END as gps_long,
d.object_type
FROM FiberPlanCableStation fcs
LEFT JOIN Pop p ON fcs.station_type = 'pop' AND fcs.station_id = p.id
LEFT JOIN FiberPlanDispatcher d ON fcs.station_type = 'dispatcher' AND fcs.station_id = d.id
WHERE fcs.cable_id = " . intval($cable_id) . "
ORDER BY fcs.station_order ASC";
$res = $db->query($sql);
if ($db->num_rows($res)) {
while ($data = $db->fetch_array($res)) {
$route[] = [
'order' => $data['station_order'],
'type' => $data['station_type'],
'id' => $data['station_id'],
'name' => $data['station_name'],
'gps_lat' => $data['gps_lat'],
'gps_long' => $data['gps_long'],
'object_type' => $data['object_type'] // Neu: object_type hinzugefügt
];
}
}
return $route;
}
public static function generateEndpoint($endpoint, $destination, $html = 1)
{

View File

@@ -0,0 +1,126 @@
<?php
class FiberPlanFiber extends mfBaseModel
{
private $editor;
private $creator;
private $cable;
private $branch_cable;
private $splitter;
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;
}
if ($name == "cable" && $this->cable_id) {
$this->cable = mfValuecache::singleton()->get("FiberPlanCable-id-" . $this->cable_id);
if (!$this->cable) {
$this->cable = new FiberPlanCable($this->cable_id);
if ($this->cable->id) {
mfValuecache::singleton()->set("FiberPlanCable-id-" . $this->cable_id, $this->cable);
}
}
return $this->cable;
}
if ($name == "branch_cable" && $this->branch_cable_nr) {
$this->branch_cable = mfValuecache::singleton()->get("Cable-nr-" . $this->branch_cable_nr);
if (!$this->branch_cable) {
$cables = FiberPlanCableModel::search(['description' => $this->branch_cable_nr]);
if (count($cables) > 0) {
$this->branch_cable = $cables[0];
mfValuecache::singleton()->set("Cable-nr-" . $this->branch_cable_nr, $this->branch_cable);
}
}
return $this->branch_cable;
}
$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;
}
public function isBranchCable()
{
return ($this->branch_type == "Abzweigkabel");
}
public function isCustomerConnection()
{
return (!empty($this->home_id));
}
public function getFullPath()
{
$path = [];
$current = $this;
$path[] = [
'cable' => $current->cable,
'fiber' => $current,
'type' => 'main'
];
if ($current->isBranchCable() && $current->branch_cable) {
$branch_fiber = FiberPlanFiberModel::findByFiberNr(
$current->branch_cable->id,
$current->branch_fiber_nr,
$current->branch_bundle_nr,
$current->branch_fiber_in_bundle
);
if ($branch_fiber) {
$path[] = [
'cable' => $current->branch_cable,
'fiber' => $branch_fiber,
'type' => 'branch'
];
if ($branch_fiber->isBranchCable()) {
$sub_path = $branch_fiber->getFullPath();
$path = array_merge($path, array_slice($sub_path, 1));
}
}
}
return $path;
}
}

View File

@@ -0,0 +1,186 @@
<?php
class FiberPlanFiberController 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("FiberPlanFiber/Index");
$fiberplanfibers = FiberPlanFiberModel::getAll();
$this->layout()->set("fiberplanfibers", $fiberplanfibers);
}
protected function addAction()
{
$cables=CableModel::getAll();
$this->layout()->set("cables", $cables);
$this->layout()->setTemplate("FiberPlanFiber/Form");
}
protected function editAction()
{
$id = $this->request->id;
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Faser nicht gefunden", "error");
$this->redirect("FiberPlanFiber");
}
$fiberplanfibers = new FiberPlanFiber($id);
if ($fiberplanfibers->id != $id) {
$this->layout()->setFlash("Faser nicht gefunden", "error");
$this->redirect("FiberPlanFiber");
}
$this->layout()->set("fiberplanfibers", $fiberplanfibers);
return $this->addAction();
}
protected function getCustomerLocationAction()
{
header('Content-Type: application/json');
$address = $this->request->address;
$network_id = intval($this->request->network_id);
if (!$address) {
echo json_encode(['success' => false, 'error' => 'Keine Adresse angegeben']);
return;
}
$db = FronkDB::singleton();
$address_escaped = $db->escape($address);
$sql = "SELECT gps_lat, gps_long
FROM FiberPlanAddress
WHERE address LIKE '%$address_escaped%'
AND network_id = $network_id
AND gps_lat IS NOT NULL
AND gps_long IS NOT NULL
LIMIT 1";
$res = $db->query($sql);
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
echo json_encode([
'success' => true,
'gps_lat' => $data->gps_lat,
'gps_long' => $data->gps_long
]);
} else {
echo json_encode([
'success' => false,
'error' => 'Keine GPS-Koordinaten gefunden'
]);
}
exit;
}
protected function saveAction()
{
$r = $this->request;
$id = $r->id;
if (is_numeric($id) && $id > 0) {
$mode = "edit";
$fiberplanfibers = new FiberPlanFiber($id);
if (!$fiberplanfibers->id) {
$this->layout()->setFlash("Fasern nicht gefunden", "error");
$this->redirect("FiberPlanFiber");
}
} else {
$mode = "add";
}
$data = [];
$data['cable_id'] = trim($r->cable_id);
$data['sheet_range'] = trim($r->sheet_range);
$data['connector_nr'] = trim($r->connector_nr);
$data['fiber_nr_cable'] = trim($r->fiber_nr_cable);
$data['bundle_nr'] = trim($r->bundle_nr);
$data['fiber_nr_bundle'] = trim($r->fiber_nr_bundle);
$data['fiber_color'] = trim($r->fiber_color);
$data['branch_type'] = trim($r->branch_type);
$data['branch_cable_nr'] = trim($r->branch_cable_nr);
$data['branch_fiber_count'] = trim($r->branch_fiber_count);
$data['branch_fiber_nr'] = trim($r->branch_fiber_nr);
$data['branch_bundle_nr'] = trim($r->branch_bundle_nr);
$data['branch_fiber_in_bundle'] = trim($r->branch_fiber_in_bundle);
$data['branch_from_location'] = trim($r->branch_from_location);
$data['branch_to_location'] = trim($r->branch_to_location);
$data['branch_gis_id'] = trim($r->branch_gis_id);
$data['address'] = trim($r->address);
$data['name'] = trim($r->name);
$data['home_id'] = trim($r->home_id);
$data['location'] = trim($r->location);
$data['rack_unit'] = trim($r->rack_unit);
$data['termination_type'] = trim($r->termination_type);
$data['customer_cable_type'] = trim($r->customer_cable_type);
$data['customer_cable_fiber_nr'] = trim($r->customer_cable_fiber_nr);
$data['customer_connector_type'] = trim($r->customer_connector_type);
$data['customer_cable_spec'] = trim($r->customer_cable_spec);
$data['customer_fiber_range'] = trim($r->customer_fiber_range);
$data['splitter_location'] = trim($r->splitter_location);
$data['splitter_factor'] = trim($r->splitter_factor);
$data['uuid_qgis_kabel'] = trim($r->uuid_qgis_kabel);
$data['status'] = trim($r->status);
$data['comment'] = trim($r->comment);
foreach ($data as $key => $value) {
if ($value === '') {
$data[$key] = NULL;
}
}
if ($mode == "edit") {
$fiberplanfibers->update($data);
} else {
$fiberplanfibers = FiberPlanFiberModel::create($data);
}
$id = $fiberplanfibers->save();
if (!$id) {
$this->layout()->setFlash("Faser konnte nicht angelegt werden", "error");
$this->redirect("FiberPlanFiber");
}
if ($mode == "edit") {
$this->layout()->setFlash("Faser erfolgreich geändert", "success");
} else if ($mode = "add") {
$this->layout()->setFlash("Faser erfolgreich angelegt", "success");
}
$this->redirect("FiberPlanFiber");
}
protected function deleteAction()
{
$id = $this->request->id;
$fiberplanfibers = new FiberPlanFiber($id);
if (!$fiberplanfibers->id || $fiberplanfibers->id != $id) {
$this->layout()->setFlash("Faser nicht gefunden.", "error");
$this->redirect("FiberPlanFiber");
}
$fiberplanfibers->delete();
$this->redirect("FiberPlanFiber");
}
}

View File

@@ -0,0 +1,314 @@
<?php
class FiberPlanFiberModel
{
private $cable_id;
private $sheet_range;
private $connector_nr;
private $fiber_nr_cable;
private $bundle_nr;
private $fiber_nr_bundle;
private $fiber_color;
private $bundle_color;
private $fiber_color_hex;
private $bundle_color_hex;
private $branch_bundle_color_hex;
private $branch_type;
private $branch_cable_nr;
private $branch_fiber_count;
private $branch_fiber_nr;
private $branch_bundle_nr;
private $branch_fiber_in_bundle;
private $branch_bundle_color;
private $branch_from_location;
private $branch_to_location;
private $branch_gis_id;
private $address;
private $name;
private $home_id;
private $location;
private $rack_unit;
private $termination_type;
private $customer_cable_type;
private $customer_cable_fiber_nr;
private $customer_connector_type;
private $customer_cable_spec;
private $customer_fiber_range;
private $splitter_location;
private $splitter_factor;
private $uuid_qgis_kabel;
private $status;
private $comment;
public static function find($data)
{
}
public static function create(array $data)
{
$model = new FiberPlanFiber();
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("FiberPlanFiber", "*", "id=$id LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new FiberPlanFiber($data);
}
return $item;
}
public static function getAll()
{
$items = [];
$db = FronkDB::singleton();
$res = $db->select("FiberPlanFiber", "*", "1=1");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanFiber($data);
}
}
return $items;
}
public static function getFirst()
{
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("FiberPlanFiber", "*", "$where ");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new FiberPlanFiber($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("FiberPlanFiber", "*", "$where");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanFiber($data);
}
}
return $items;
}
private static function getSqlFilter($filter)
{
$where = "1=1 ";
$db = FronkDB::singleton();
//var_dump($filter);exit;
if (array_key_exists("cable_id", $filter)) {
$cable_id = intval($filter['cable_id']);
if ($cable_id > 0) {
$where .= " AND cable_id=$cable_id";
}
}
if (array_key_exists("sheet_range", $filter)) {
$sheet_range = $db->escape($filter['sheet_range']);
if ($sheet_range) {
$where .= " AND sheet_range='$sheet_range'";
}
}
if (array_key_exists("connector_nr", $filter)) {
$connector_nr = $db->escape($filter['connector_nr']);
if ($connector_nr) {
$where .= " AND connector_nr='$connector_nr'";
}
}
if (array_key_exists("fiber_nr_cable", $filter)) {
$fiber_nr_cable = $db->escape($filter['fiber_nr_cable']);
if ($fiber_nr_cable) {
$where .= " AND fiber_nr_cable='$fiber_nr_cable'";
}
}
if (array_key_exists("home_id", $filter)) {
$home_id = $db->escape($filter['home_id']);
if ($home_id) {
$where .= " AND home_id='$home_id'";
}
}
if (array_key_exists("branch_type", $filter)) {
$branch_type = $db->escape($filter['branch_type']);
if ($branch_type) {
$where .= " AND branch_type='$branch_type'";
}
}
if (array_key_exists("status", $filter)) {
$status = $db->escape($filter['status']);
if ($status) {
$where .= " AND status='$status'";
}
}
//var_dump($filter, $where);exit;
return $where;
}
public static function findByFiberNr($cable_id, $fiber_nr_cable)
{
$db = FronkDB::singleton();
$cable_id = intval($cable_id);
$fiber_nr_cable = $db->escape($fiber_nr_cable);
$where = "cable_id=$cable_id AND fiber_nr_cable='$fiber_nr_cable'";
$res = $db->select("FiberPlanFiber", "*", "$where LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
return new FiberPlanFiber($data);
}
return null;
}
public static function getByCableAndSheet($cable_id, $sheet_range = null)
{
$items = [];
$db = FronkDB::singleton();
$where = "cable_id=$cable_id";
if ($sheet_range) {
$sheet_range = $db->escape($sheet_range);
$where .= " AND sheet_range='$sheet_range'";
}
$res = $db->select("FiberPlanFiber", "*", "$where ORDER BY connector_nr ASC");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanFiber($data);
}
}
return $items;
}
public static function getBranchFibers($cable_id)
{
$items = [];
$db = FronkDB::singleton();
$res = $db->select("FiberPlanFiber", "*", "cable_id=$cable_id AND branch_type='Abzweigkabel'");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanFiber($data);
}
}
return $items;
}
public static function getCustomerConnections($cable_id)
{
$items = [];
$db = FronkDB::singleton();
$res = $db->select("FiberPlanFiber", "*", "cable_id=$cable_id AND home_id IS NOT NULL AND home_id != ''");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanFiber($data);
}
}
return $items;
}
public static function findByPosition($cable_id, $sheet_range, $connector_nr)
{
$db = FronkDB::singleton();
$cable_id = intval($cable_id);
$sheet_range = $db->escape($sheet_range);
$connector_nr = $db->escape($connector_nr);
$where = "cable_id=$cable_id AND sheet_range='$sheet_range' AND connector_nr='$connector_nr'";
$res = $db->select("FiberPlanFiber", "*", "$where LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
return new FiberPlanFiber($data);
}
return null;
}
public static function findByBranch($cable_id, $sheet_range, $branch_cable_nr, $branch_fiber_nr)
{
$db = FronkDB::singleton();
$cable_id = intval($cable_id);
$sheet_range = $db->escape($sheet_range);
$branch_cable_nr = $db->escape($branch_cable_nr);
$branch_fiber_nr = $db->escape($branch_fiber_nr);
$where = "cable_id=$cable_id AND sheet_range='$sheet_range' AND branch_cable_nr='$branch_cable_nr' AND branch_fiber_nr='$branch_fiber_nr'";
$res = $db->select("FiberPlanFiber", "*", "$where LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
return new FiberPlanFiber($data);
}
return null;
}
}

File diff suppressed because it is too large Load Diff