Files
thetool/application/FiberPlanPipe/FiberPlanPipeModel.php
Spitzer Daniel e3f8c2326e Faserplanung
* Schächte/Verteiler
 * Rohrplanung
2024-04-16 16:55:16 +02:00

377 lines
14 KiB
PHP

<?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++;
}
}
}