Files
thetool/application/Poprackmodule/PoprackmoduleModel.php
Daniel Spitzer 75e9ac6dbb Pop Update
* Rückseite der Pop-Racks können nun auch mit HEs bestückt werden
2025-08-27 12:54:09 +02:00

103 lines
2.9 KiB
PHP

<?php
class PoprackmoduleModel
{
public $poprack_id = null;
public $type = null;
public $device_id = null;
public $name = null;
public $start_he = null;
public $end_he = null;
public $width = null;
public $ports = null;
public $plug = null;
public $position = null;
public $side = null;
public $create_by = null;
public $edit_by = null;
public $create = null;
public $edit = null;
public static function create(array $data)
{
$model = new Poprackmodule();
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 getpoprackmodule($poprack_id)
{
$items = [];
$db = FronkDB::singleton();
$sql = "SELECT `id`, `name`, `start_he`,`end_he`,`plug`,`ports` FROM `Poprackmodule` WHERE `poprack_id`='" . $poprack_id . "' AND type ='0' ORDER by start_he";
$res = $db->query($sql);
if ($db->num_rows($res)) {
while ($data = $db->fetch_array($res)) {
$items[] = $data;
}
$response['data'] = $items;
$response['success'] = true;
} else {
$response['success'] = false;
}
echo json_encode($response);
exit;
}
public static function getpoprackmoduleall($pop_id)
{
$items = [];
$db = FronkDB::singleton();
$sql = "SELECT `Poprackmodule`.`id`, `Poprackmodule`.`name`, `Poprackmodule`.`start_he`,`Poprackmodule`.`end_he`,`Poprackmodule`.`plug`,`Poprackmodule`.`ports`,`Poprack`.id poprackid ,`Poprack`.name poprackname FROM `Poprackmodule` INNER JOIN
`Poprack` ON (`Poprack`.`id` = `Poprackmodule`.`poprack_id`)
WHERE `Poprack`.`pop_id`='" . $pop_id . "' AND `Poprackmodule`.`type` ='0' ORDER by `Poprack`.`sort`,`Poprackmodule`.`start_he`,`Poprackmodule`.`position`";
$res = $db->query($sql);
if ($db->num_rows($res)) {
while ($data = $db->fetch_array($res)) {
$items[$data['poprackname']][] = $data;
}
$response['data'] = $items;
$response['success'] = true;
} else {
$response['success'] = false;
}
echo json_encode($response);
exit;
}
}