177 lines
4.4 KiB
PHP
177 lines
4.4 KiB
PHP
<?php
|
|
|
|
class NetworkModel {
|
|
public $name;
|
|
public $owner_id ;
|
|
public $adb_netzgebiet_id;
|
|
public $opsystem;
|
|
public $sytemowner_action_status;
|
|
public $note;
|
|
|
|
public $create_by;
|
|
public $edit_by;
|
|
public $create;
|
|
public $edit;
|
|
|
|
|
|
public static function create(Array $data) {
|
|
$model = new Network();
|
|
|
|
foreach($data as $field => $value) {
|
|
if(property_exists(get_called_class(), $field)) {
|
|
$model ->$field = $value;
|
|
}
|
|
}
|
|
|
|
$me = new User();
|
|
$me->loadMe();
|
|
|
|
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("Network", "*", "id=$id LIMIT 1");
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
$item = new Network($data);
|
|
}
|
|
return $item;
|
|
}
|
|
|
|
public static function getAll() {
|
|
$items = [];
|
|
|
|
$db = FronkDB::singleton();
|
|
|
|
$res = $db->select("Network", "*", "1=1 ORDER BY name");
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new Network($data);
|
|
}
|
|
}
|
|
return $items;
|
|
|
|
}
|
|
|
|
public static function getFirst($filter = false) {
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$res = $db->select("Network", "*", "$where ORDER BY name, owner_id");
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
$item = new Network($data);
|
|
if($item->id) {
|
|
return $item;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static function count($filter = []) {
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT COUNT(*) as cnt FROM Network
|
|
WHERE $where
|
|
";
|
|
|
|
mfLoghandler::singleton()->debug($sql);
|
|
|
|
$res = $db->query($sql);
|
|
if ($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
return (int)$data->cnt;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public static function search($filter) {
|
|
$items = [];
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$res = $db->select("Network", "*", "$where ORDER BY name, owner_id");
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new Network($data);
|
|
}
|
|
}
|
|
return $items;
|
|
}
|
|
|
|
private static function getSqlFilter($filter) {
|
|
$where = "1=1 ";
|
|
|
|
//var_dump($filter);exit;
|
|
|
|
if(array_key_exists("name", $filter)) {
|
|
$name = FronkDB::singleton()->escape($filter['name']);
|
|
if($name) {
|
|
$where .= " AND Network.`name` = '$name'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("name%", $filter)) {
|
|
$name = FronkDB::singleton()->escape($filter['name%']);
|
|
if($name) {
|
|
$where .= " AND Network.`name` LIKE '$name%'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("owner_id", $filter)) {
|
|
$owner_id = $filter['owner_id'];
|
|
if(is_numeric($owner_id)) {
|
|
$where .= " AND owner_id=$owner_id";
|
|
} elseif(is_array($owner_id) && count($owner_id)) {
|
|
$where .= " AND owner_id IN (". implode(",", $owner_id).")";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("adb_network_id", $filter)) {
|
|
$adb_network_id = $filter['adb_network_id'];
|
|
if(is_numeric($adb_network_id)) {
|
|
$where .= " AND adb_netzgebiet_id=$adb_network_id";
|
|
} elseif(is_array($adb_network_id) && count($adb_network_id)) {
|
|
$where .= " AND adb_netzgebiet_id IN (". implode(",", $adb_network_id).")";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("adb_netzgebiet_id", $filter)) {
|
|
$adb_netzgebiet_id = $filter['adb_netzgebiet_id'];
|
|
if(is_numeric($adb_netzgebiet_id)) {
|
|
$where .= " AND adb_netzgebiet_id=$adb_netzgebiet_id";
|
|
} elseif(is_array($adb_netzgebiet_id) && count($adb_netzgebiet_id)) {
|
|
$where .= " AND adb_netzgebiet_id IN (". implode(",", $adb_netzgebiet_id).")";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("opsystem", $filter)) {
|
|
$opsystem = FronkDB::singleton()->escape($filter['opsystem']);
|
|
if($opsystem) {
|
|
$where .= " AND Network.`opsystem` = '$opsystem'";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//var_dump($filter, $where);exit;
|
|
return $where;
|
|
}
|
|
|
|
} |