Features:

* Komplettes kabelmanagement auf Rack He Modul Basis
This commit is contained in:
Daniel Spitzer
2025-10-12 12:19:54 +02:00
parent e17e638263
commit 4ef8e733a3
10 changed files with 1505 additions and 306 deletions
+14 -3
View File
@@ -21,9 +21,20 @@ class PoprackController extends mfBaseController
case "sortRack":
$return = $this->sortRack();
break;
case "generateRack";
$return = $this->generateRack();
break;
case "generateRack":
$rack_id = $this->request->id;
$side = $this->request->side ?? 'front';
$rackDataArray = PoprackModel::getAllbyRack($rack_id);
$rackData = $rackDataArray[0] ?? null;
if ($rackData) {
$modules_to_render = $rackData['modules'][$side] ?? [];
$rack_he = $rackData['rack']['he'];
$plugs[1] = "LC/APC";
$plugs[2] = "SC/APC";
$plugs[3] = "E2000/APC";
include(dirname(__FILE__) . "/../../Layout/default/Pop/_rack_body.php");
}
exit;
default:
$return = false;
}
+34 -66
View File
@@ -42,28 +42,11 @@ class PoprackModel
return $model;
}
public static function getAllbyPop($pop_id)
private static function _processRackData($res)
{
$items = [];
$db = FronkDB::singleton();
$sql = "(SELECT `Poprackmodule`.`type`,`Poprack`.`id`,`Poprack`.`sort`, `Poprack`.`name`, `Poprack`.`he`,`Poprackmodule`.start_he,`Poprackmodule`.end_he,`Poprackmodule`.`name` as `modulname`,device_id ,`Poprackmodule`.`id` as moduleid,`Poprackmodule`.`width` as modulewidth,`Poprackmodule`.`position` as moduleposition,`Poprackmodule`.`side` as moduleside,`Poprackmodule`.`ports` as moduleports,`Poprackmodule`.`plug` as moduleplug FROM `Poprack`
LEFT JOIN `Poprackmodule` ON (`Poprackmodule`.`poprack_id`=`Poprack`.`id` AND `Poprackmodule`.`type`!=1)
WHERE `Poprack`.`pop_id`='" . $pop_id . "' ORDER by `Poprack`.`sort`,`Poprack`.`name`,`Poprackmodule`.start_he,`Poprackmodule`.position)
UNION
(SELECT `Poprackmodule`.`type`,`Poprack`.`id`,`Poprack`.`sort`, `Poprack`.`name`, `Poprack`.`he`,`Poprackmodule`.start_he,`Poprackmodule`.end_he,`Device`.`name` as `modulname`,device_id,`Poprackmodule`.`id` as moduleid,`Poprackmodule`.`width` as modulewidth,`Poprackmodule`.`position` as moduleposition,`Poprackmodule`.`side` as moduleside,`Poprackmodule`.`ports` as moduleports,`Poprackmodule`.`plug` as moduleplug FROM `Poprack`
LEFT JOIN `Poprackmodule` ON (`Poprackmodule`.`poprack_id`=`Poprack`.`id` AND `Poprackmodule`.`type`=1)
LEFT JOIN `Device` ON (`Device`.`id`=`Poprackmodule`.`device_id`)
WHERE `Poprack`.`pop_id`='" . $pop_id . "' ORDER by `Poprack`.`sort`,`Poprack`.`name`,`Poprackmodule`.start_he,`Poprackmodule`.position)
ORDER BY sort,name,start_he,moduleposition
";
//
// $sql = "SELECT `Poprack`.`id`, `Poprack`.`name`, `Poprack`.`he`,`Poprackmodule`.start_he,`Poprackmodule`.end_he,`Poprackmodule`.`name` as `modulname` FROM `Poprack`
// LEFT JOIN `Poprackmodule` ON (`Poprackmodule`.`poprack_id`=`Poprack`.`id`)
// WHERE `Poprack`.`pop_id`='" . $pop_id . "' ORDER by `Poprack`.`sort`,`Poprack`.`name`,`Poprackmodule`.`start_he`";
$res = $db->query($sql);
if ($db->num_rows($res)) {
$oldrackid = "";
$counter = -1;
@@ -73,7 +56,6 @@ class PoprackModel
$items[$counter]['rack']['id'] = $data['id'];
$items[$counter]['rack']['name'] = $data['name'];
$items[$counter]['rack']['he'] = $data['he'];
$modulecounter = 0;
}
// if ($data['modulname']) {
if ($data['device_id']) {
@@ -88,71 +70,57 @@ class PoprackModel
$items[$counter]['modules'][$data['moduleside']][$data['start_he']]['slots'][$data['moduleid']]['position'] = $data['moduleposition'];
$items[$counter]['modules'][$data['moduleside']][$data['start_he']]['slots'][$data['moduleid']]['ports'] = $data['moduleports'];
$items[$counter]['modules'][$data['moduleside']][$data['start_he']]['slots'][$data['moduleid']]['plug'] = $data['moduleplug'];
$modulecounter++;
}
$items[$counter]['modules'][$data['moduleside']][$data['start_he']]['slots'][$data['moduleid']]['status'] = $data['status'];
if ($data['type'] == 0) {
$cables = PoprackmodulecableModel::getForModule($data['moduleid']);
$cableData = [];
foreach ($cables as $cable) {
$cleanCable = (array)$cable->data;
$cleanCable['id'] = $cable->id;
$cableData[] = $cleanCable;
}
$items[$counter]['modules'][$data['moduleside']][$data['start_he']]['slots'][$data['moduleid']]['cables'] = $cableData;
}
// }
$oldrackid = $data['id'];
}
}
return $items;
}
public static function getAllbyPop($pop_id)
{
$db = FronkDB::singleton();
$sql = "(SELECT `Poprackmodule`.`type`,`Poprack`.`id`,`Poprack`.`sort`, `Poprack`.`name`, `Poprack`.`he`,`Poprackmodule`.start_he,`Poprackmodule`.end_he,`Poprackmodule`.`name` as `modulname`,device_id ,`Poprackmodule`.`id` as moduleid,`Poprackmodule`.`width` as modulewidth,`Poprackmodule`.`position` as moduleposition,`Poprackmodule`.`side` as moduleside,`Poprackmodule`.`ports` as moduleports,`Poprackmodule`.`plug` as moduleplug,Poprackmodule.status FROM `Poprack`
LEFT JOIN `Poprackmodule` ON (`Poprackmodule`.`poprack_id`=`Poprack`.`id` AND `Poprackmodule`.`type`!=1)
WHERE `Poprack`.`pop_id`='" . $pop_id . "' ORDER by `Poprack`.`sort`,`Poprack`.`name`,`Poprackmodule`.start_he,`Poprackmodule`.position)
UNION
(SELECT `Poprackmodule`.`type`,`Poprack`.`id`,`Poprack`.`sort`, `Poprack`.`name`, `Poprack`.`he`,`Poprackmodule`.start_he,`Poprackmodule`.end_he,`Device`.`name` as `modulname`,device_id,`Poprackmodule`.`id` as moduleid,`Poprackmodule`.`width` as modulewidth,`Poprackmodule`.`position` as moduleposition,`Poprackmodule`.`side` as moduleside,`Poprackmodule`.`ports` as moduleports,`Poprackmodule`.`plug` as moduleplug,Poprackmodule.status FROM `Poprack`
LEFT JOIN `Poprackmodule` ON (`Poprackmodule`.`poprack_id`=`Poprack`.`id` AND `Poprackmodule`.`type`=1)
LEFT JOIN `Device` ON (`Device`.`id`=`Poprackmodule`.`device_id`)
WHERE `Poprack`.`pop_id`='" . $pop_id . "' ORDER by `Poprack`.`sort`,`Poprack`.`name`,`Poprackmodule`.start_he,`Poprackmodule`.position)
ORDER BY sort,name,start_he,moduleposition
";
$res = $db->query($sql);
return self::_processRackData($res);
}
public static function getAllbyRack($rack_id)
{
$items = [];
$db = FronkDB::singleton();
$sql = "(SELECT `Poprackmodule`.`type`,`Poprack`.`id`,`Poprack`.`sort`, `Poprack`.`name`, `Poprack`.`he`,`Poprackmodule`.start_he,`Poprackmodule`.end_he,`Poprackmodule`.`name` as `modulname`,device_id ,`Poprackmodule`.`id` as moduleid,`Poprackmodule`.`width` as modulewidth,`Poprackmodule`.`position` as moduleposition,`Poprackmodule`.`side` as moduleside,`Poprackmodule`.`ports` as moduleports,`Poprackmodule`.`plug` as moduleplug FROM `Poprack`
$sql = "(SELECT `Poprackmodule`.`type`,`Poprack`.`id`,`Poprack`.`sort`, `Poprack`.`name`, `Poprack`.`he`,`Poprackmodule`.start_he,`Poprackmodule`.end_he,`Poprackmodule`.`name` as `modulname`,device_id ,`Poprackmodule`.`id` as moduleid,`Poprackmodule`.`width` as modulewidth,`Poprackmodule`.`position` as moduleposition,`Poprackmodule`.`side` as moduleside,`Poprackmodule`.`ports` as moduleports,`Poprackmodule`.`plug` as moduleplug,Poprackmodule.status FROM `Poprack`
LEFT JOIN `Poprackmodule` ON (`Poprackmodule`.`poprack_id`=`Poprack`.`id` AND `Poprackmodule`.`type`!=1)
WHERE `Poprack`.`id`='" . $rack_id . "' ORDER by `Poprack`.`sort`,`Poprack`.`name`,`Poprackmodule`.start_he,`Poprackmodule`.position)
UNION
(SELECT `Poprackmodule`.`type`,`Poprack`.`id`,`Poprack`.`sort`, `Poprack`.`name`, `Poprack`.`he`,`Poprackmodule`.start_he,`Poprackmodule`.end_he,`Device`.`name` as `modulname`,device_id,`Poprackmodule`.`id` as moduleid,`Poprackmodule`.`width` as modulewidth,`Poprackmodule`.`position` as moduleposition,`Poprackmodule`.`side` as moduleside,`Poprackmodule`.`ports` as moduleports,`Poprackmodule`.`plug` as moduleplug FROM `Poprack`
(SELECT `Poprackmodule`.`type`,`Poprack`.`id`,`Poprack`.`sort`, `Poprack`.`name`, `Poprack`.`he`,`Poprackmodule`.start_he,`Poprackmodule`.end_he,`Device`.`name` as `modulname`,device_id,`Poprackmodule`.`id` as moduleid,`Poprackmodule`.`width` as modulewidth,`Poprackmodule`.`position` as moduleposition,`Poprackmodule`.`side` as moduleside,`Poprackmodule`.`ports` as moduleports,`Poprackmodule`.`plug` as moduleplug ,Poprackmodule.status FROM `Poprack`
LEFT JOIN `Poprackmodule` ON (`Poprackmodule`.`poprack_id`=`Poprack`.`id` AND `Poprackmodule`.`type`=1)
LEFT JOIN `Device` ON (`Device`.`id`=`Poprackmodule`.`device_id`)
WHERE `Poprack`.`id`='" . $rack_id . "' ORDER by `Poprack`.`sort`,`Poprack`.`name`,`Poprackmodule`.start_he,`Poprackmodule`.position)
ORDER BY sort,name,start_he,moduleposition
";
//
// $sql = "SELECT `Poprack`.`id`, `Poprack`.`name`, `Poprack`.`he`,`Poprackmodule`.start_he,`Poprackmodule`.end_he,`Poprackmodule`.`name` as `modulname` FROM `Poprack`
// LEFT JOIN `Poprackmodule` ON (`Poprackmodule`.`poprack_id`=`Poprack`.`id`)
// WHERE `Poprack`.`pop_id`='" . $pop_id . "' ORDER by `Poprack`.`sort`,`Poprack`.`name`,`Poprackmodule`.`start_he`";
";
$res = $db->query($sql);
if ($db->num_rows($res)) {
$oldrackid = "";
$counter = -1;
while ($data = $db->fetch_array($res)) {
if ($oldrackid != $data['id']) {
$counter++;
$items[$counter]['rack']['id'] = $data['id'];
$items[$counter]['rack']['name'] = $data['name'];
$items[$counter]['rack']['he'] = $data['he'];
$modulecounter = 0;
}
if ($data['modulname']) {
if ($data['device_id']) {
$items[$counter]['modules'][$data['start_he']]['slots'][$data['moduleid']]['device_id'] = $data['device_id'];
}
$items[$counter][$data['moduleside']]['modules'][$data['start_he']]['start_he'] = $data['start_he'];
$items[$counter][$data['moduleside']]['modules'][$data['start_he']]['end_he'] = $data['end_he'];
$items[$counter][$data['moduleside']]['modules'][$data['start_he']]['slots'][$data['moduleid']]['modulname'] = $data['modulname'];
$items[$counter][$data['moduleside']]['modules'][$data['start_he']]['slots'][$data['moduleid']]['moduleid'] = $data['moduleid'];
$items[$counter][$data['moduleside']]['modules'][$data['start_he']]['slots'][$data['moduleid']]['type'] = $data['type'];
$items[$counter][$data['moduleside']]['modules'][$data['start_he']]['slots'][$data['moduleid']]['width'] = $data['modulewidth'];
$items[$counter][$data['moduleside']]['modules'][$data['start_he']]['slots'][$data['moduleid']]['position'] = $data['moduleposition'];
$items[$counter][$data['moduleside']]['modules'][$data['start_he']]['slots'][$data['moduleid']]['ports'] = $data['moduleports'];
$items[$counter][$data['moduleside']]['modules'][$data['start_he']]['slots'][$data['moduleid']]['plug'] = $data['moduleplug'];
$modulecounter++;
}
$oldrackid = $data['id'];
}
}
return $items;
return self::_processRackData($res);
}
public static function getpoprack($pop_id)
@@ -21,7 +21,6 @@ class PoprackmoduleController extends mfBaseController
default:
$return = false;
}
if (!is_array($return) || !count($return)) {
$data = ["status" => "error"];
$this->returnJson($data);
@@ -54,7 +53,7 @@ class PoprackmoduleController extends mfBaseController
$data['width'] = $r->width;
$data['position'] = ($r->position) ? $r->position : null;
$data['side'] = ($r->side) ? $r->side : 'front';
$data['status'] = ($r->status) ? $r->status : 'productive';
$poprackmodule = PoprackmoduleModel::create($data);
$new_id = $poprackmodule->save();
@@ -119,6 +118,7 @@ class PoprackmoduleController extends mfBaseController
$data['type'] = $r->type;
}
$data['name'] = ($r->name);
$data['status'] = ($r->status);
$poprackmodule->update($data);
$new_id = $poprackmodule->save();
if (!$new_id) {
@@ -14,6 +14,7 @@ class PoprackmoduleModel
public $plug = null;
public $position = null;
public $side = null;
public $status = null;
public $create_by = null;
public $edit_by = null;
public $create = null;
@@ -99,5 +100,4 @@ class PoprackmoduleModel
exit;
}
}
@@ -0,0 +1,60 @@
<?php
class Poprackmodulecable extends mfBaseModel
{
private $editor;
private $creator;
private $poprackmodule;
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;
}
}
@@ -0,0 +1,283 @@
<?php
class PoprackmodulecableController 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 apiAction()
{
$do = $this->request->do;
$me = new User(); // Annahme, dass der User geladen werden muss für create_by etc.
$me->loadMe();
switch ($do) {
case "addCable":
$data = [
'poprackmodule_id' => $this->request->poprackmodule_id,
'cable_name' => trim($this->request->cable_name),
'port_start' => (int)$this->request->port_start,
'port_end' => (int)$this->request->port_end,
'fiber_start' => ($this->request->fiber_start) ? (int)$this->request->fiber_start : null,
'fiber_end' => ($this->request->fiber_end) ? (int)$this->request->fiber_end : null,
'description' => trim($this->request->description) ?: null,
'create_by' => $this->me->id,
'edit_by' => $this->me->id,
];
$module = new Poprackmodule($data['poprackmodule_id']);
if (!$module->id) {
$this->returnJson(['success' => false, 'error' => 'Modul nicht gefunden.']);
return;
}
if (empty($data['cable_name']) || empty($data['port_start']) || empty($data['port_end'])) {
$this->returnJson(['success' => false, 'error' => 'Alle Felder sind Pflichtfelder.']);
return;
}
if ($data['port_start'] > $data['port_end'] || $data['port_start'] < 1 || $data['port_end'] > $module->ports) {
$this->returnJson(['success' => false, 'error' => 'Ungültiger Port-Bereich. Ports müssen zwischen 1 und ' . $module->ports . ' liegen.']);
return;
}
if ($data['fiber_start'] && $data['fiber_end']) {
if ($data['fiber_start'] > $data['fiber_end']) {
$this->returnJson(['success' => false, 'error' => 'Faser-Start muss kleiner oder gleich Faser-Ende sein.']);
return;
}
$portCount = $data['port_end'] - $data['port_start'] + 1;
$fiberCount = $data['fiber_end'] - $data['fiber_start'] + 1;
if ($fiberCount > $portCount) {
$this->returnJson(['success' => false, 'error' => 'Anzahl der Fasern (' . $fiberCount . ') darf nicht größer als die der Ports (' . $portCount . ') sein.']);
return;
}
}
$existingCables = PoprackmodulecableModel::getForModule($data['poprackmodule_id']);
$newStart = $data['port_start'];
$newEnd = $data['port_end'];
foreach ($existingCables as $existingCable) {
// Die Formel zur Prüfung auf Überlappung lautet: (StartA <= EndeB) und (EndeA >= StartB)
if ($newStart <= $existingCable->port_end && $newEnd >= $existingCable->port_start) {
$this->returnJson([
'success' => false,
'error' => 'Port-Bereich (' . $newStart . '-' . $newEnd . ') kollidiert mit Kabel "' . $existingCable->cable_name . '" (' . $existingCable->port_start . '-' . $existingCable->port_end . ').'
]);
return; // Wichtig: Abbruch, wenn eine Kollision gefunden wurde
}
}
$cable = PoprackmodulecableModel::create($data);
$newId = $cable->save();
$this->returnJson(['success' => (bool)$newId]);
break;
case "updateCable":
$cable_id = $this->request->id;
$cable = new Poprackmodulecable($cable_id);
if (!$cable->id) {
$this->returnJson(['success' => false, 'error' => 'Kabel nicht gefunden']);
return;
}
$data = [
'cable_name' => trim($this->request->cable_name),
'port_start' => (int)$this->request->port_start,
'port_end' => (int)$this->request->port_end,
'fiber_start' => ($this->request->fiber_start) ? (int)$this->request->fiber_start : null,
'fiber_end' => ($this->request->fiber_end) ? (int)$this->request->fiber_end : null,
'description' => trim($this->request->description) ?: null, // NEU
'edit_by' => $this->me->id,
];
$module = new Poprackmodule($cable->poprackmodule_id);
if (!$module->id) {
$this->returnJson(['success' => false, 'error' => 'Zugehöriges Modul nicht gefunden.']);
return;
}
if (empty($data['cable_name']) || empty($data['port_start']) || empty($data['port_end'])) {
$this->returnJson(['success' => false, 'error' => 'Alle Felder sind Pflichtfelder.']);
return;
}
if ($data['port_start'] > $data['port_end'] || $data['port_start'] < 1 || $data['port_end'] > $module->ports) {
$this->returnJson(['success' => false, 'error' => 'Ungültiger Port-Bereich. Ports müssen zwischen 1 und ' . $module->ports . ' liegen.']);
return;
}
if (($data['fiber_start'] && $data['fiber_end'])) {
if ($data['fiber_start'] > $data['fiber_end']) {
$this->returnJson(['success' => false, 'error' => 'Faser-Start muss kleiner oder gleich Faser-Ende sein.']);
return;
}
$portCount = $data['port_end'] - $data['port_start'] + 1;
$fiberCount = $data['fiber_end'] - $data['fiber_start'] + 1;
if ($fiberCount > $portCount) {
$this->returnJson(['success' => false, 'error' => 'Anzahl der Fasern (' . $fiberCount . ') darf nicht größer als die der Ports (' . $portCount . ') sein.']);
return;
}
}
$existingCables = PoprackmodulecableModel::getForModule($cable->poprackmodule_id);
$newStart = $data['port_start'];
$newEnd = $data['port_end'];
foreach ($existingCables as $existingCable) {
if ($existingCable->id == $cable_id) {
continue;
}
if ($newStart <= $existingCable->port_end && $newEnd >= $existingCable->port_start) {
$this->returnJson([
'success' => false,
'error' => 'Port-Bereich (' . $newStart . '-' . $newEnd . ') kollidiert mit Kabel "' . $existingCable->cable_name . '" (' . $existingCable->port_start . '-' . $existingCable->port_end . ').'
]);
return;
}
}
$cable->update($data);
$cable->save();
$this->returnJson(['success' => true]);
break;
case "removeCable":
$cable_id = $this->request->id;
if (!is_numeric($cable_id)) {
$this->returnJson(['success' => false, 'error' => 'Ungültige ID.']);
return;
}
$cable = new Poprackmodulecable($cable_id);
if ($cable->id) {
$cable->delete();
$this->returnJson(['success' => true]);
} else {
$this->returnJson(['success' => false, 'error' => 'Kabel nicht gefunden']);
}
break;
default:
$this->returnJson(['success' => false, 'error' => 'Unbekannte Aktion']);
break;
}
}
protected function indexAction()
{
$this->layout()->setTemplate("Poprackmodulecable/Index");
$poprackmodulecables = PoprackmodulecableModel::getAll();
$this->layout()->set("poprackmodulecables", $poprackmodulecables);
}
protected function addAction()
{
$poprackmodules=PoprackmoduleModel::getAll();
$this->layout()->set("poprackmodules", $poprackmodules);
$this->layout()->setTemplate("Poprackmodulecable/Form");
}
protected function editAction()
{
$id = $this->request->id;
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("dfsdf nicht gefunden", "error");
$this->redirect("Poprackmodulecable");
}
$poprackmodulecables = new Poprackmodulecable($id);
if ($poprackmodulecables->id != $id) {
$this->layout()->setFlash("dfsdf nicht gefunden", "error");
$this->redirect("Poprackmodulecable");
}
$this->layout()->set("poprackmodulecables", $poprackmodulecables);
return $this->addAction();
}
protected function saveAction()
{
$r = $this->request;
$id = $r->id;
//var_dump($r->get());exit;
if (is_numeric($id) && $id > 0) {
$mode = "edit";
$poprackmodulecables = new Poprackmodulecable($id);
if (!$poprackmodulecables->id) {
$this->layout()->setFlash("dfsdf nicht gefunden", "error");
$this->redirect("Poprackmodulecable");
}
} else {
$mode = "add";
}
$data = [];
$data['poprackmodule_id'] = trim($r->poprackmodule_id);
$data['cable_name'] = trim($r->cable_name);
$data['port_start'] = trim($r->port_start);
$data['port_end'] = trim($r->port_end);
if (!$data['poprackmodule_id']) {
$data['poprackmodule_id']=NULL;
}
if (!$data['cable_name']) {
$data['cable_name']=NULL;
}
if (!$data['port_start']) {
$data['port_start']=NULL;
}
if (!$data['port_end']) {
$data['port_end']=NULL;
}
// var_dump($_FILES);
// var_dump($upload);
// exit;
if ($mode == "edit") {
$poprackmodulecables->update($data);
} else {
$poprackmodulecables = PoprackmodulecableModel::create($data);
}
// var_dump($filestore);
// exit;
$id = $poprackmodulecables->save();
if (!$id) {
$this->layout()->setFlash("dfsdf konnte nicht angelegt werden", "error");
$this->redirect("Poprackmodulecable");
}
if ($mode == "edit") {
$this->layout()->setFlash("dfsdf erfolgreich geändert", "success");
} else if ($mode = "add") {
$this->layout()->setFlash("dfsdf erfolgreich angelegt", "success");
}
$this->redirect("Poprackmodulecable");
}
protected function deleteAction()
{
$id = $this->request->id;
$poprackmodulecables = new Poprackmodulecable($id);
if (!$poprackmodulecables->id || $poprackmodulecables->id != $id) {
$this->layout()->setFlash("dfsdf nicht gefunden.", "error");
$this->redirect("Poprackmodulecable");
}
$poprackmodulecables->delete();
$this->redirect("Poprackmodulecable");
}
}
@@ -0,0 +1,150 @@
<?php
class PoprackmodulecableModel
{
private $poprackmodule_id;
private $cable_name;
private $port_start;
private $port_end;
private $fiber_start;
private $fiber_end;
private $description;
public static function find($data)
{
}
public static function create(array $data)
{
$model = new Poprackmodulecable();
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 getForModule($poprackmodule_id)
{
$items = [];
if (!is_numeric($poprackmodule_id)) {
return $items;
}
$db = FronkDB::singleton();
$res = $db->select("Poprackmodulecable", "*", "poprackmodule_id = " . (int)$poprackmodule_id . " ORDER BY port_start ASC");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new Poprackmodulecable($data);
}
}
return $items;
}
public static function getOne($id)
{
if (!is_numeric($id) || !$id) {
throw new Exception("Invalid number", 400);
}
$item = [];
$db = FronkDB::singleton();
$res = $db->select("Poprackmodulecable", "*", "id=$id LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new Poprackmodulecable($data);
}
return $item;
}
public static function getAll()
{
$items = [];
$db = FronkDB::singleton();
$res = $db->select("Poprackmodulecable", "*", "1=1");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new Poprackmodulecable($data);
}
}
return $items;
}
public static function getFirst()
{
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("Poprackmodulecable", "*", "$where ");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new Poprackmodulecable($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("Poprackmodulecable", "*", "$where");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new Poprackmodulecable($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;
}
}