175 lines
4.7 KiB
PHP
175 lines
4.7 KiB
PHP
<?php
|
|
|
|
class ADBNetzgebietModel {
|
|
public $name;
|
|
public $extref;
|
|
public $source;
|
|
public $source_id;
|
|
public $rimo_id;
|
|
public $freigabe;
|
|
|
|
public $create = null;
|
|
public $edit = null;
|
|
|
|
public static function create(Array $data) {
|
|
$model = new ADBNetzgebiet();
|
|
|
|
foreach($data as $field => $value) {
|
|
if(property_exists(get_called_class(), $field)) {
|
|
$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 getFirst($filter) {
|
|
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$res = $db->select("Netzgebiet", "*", "$where ORDER BY name LIMIT 1");
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
$item = new ADBNetzgebiet($data);
|
|
if($item->id) {
|
|
return $item;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static function getAll($indexed_by_id = false) {
|
|
$items = [];
|
|
|
|
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
|
|
|
$res = $db->select("Netzgebiet", "*", "1=1 ORDER BY name");
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
if($indexed_by_id) {
|
|
$items[$data->id] = new ADBNetzgebiet($data);
|
|
} else {
|
|
$items[] = new ADBNetzgebiet($data);
|
|
}
|
|
|
|
}
|
|
}
|
|
return $items;
|
|
|
|
}
|
|
|
|
|
|
public static function count($filter) {
|
|
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT COUNT(*) as cnt FROM Netzgebiet
|
|
WHERE $where
|
|
";
|
|
|
|
$res = $db->query($sql);
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
return $data->cnt;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public static function search($filter, $limit = false) {
|
|
$items = [];
|
|
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT Netzgebiet.* FROM Netzgebiet
|
|
WHERE $where
|
|
ORDER BY name";
|
|
|
|
mfLoghandler::singleton()->debug($sql);
|
|
if(is_array($limit) && count($limit)) {
|
|
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
|
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
|
} elseif(is_numeric($limit['count'])) {
|
|
$sql .= " LIMIT ".$limit['count'];
|
|
}
|
|
}
|
|
|
|
$res = $db->query($sql);
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new ADBNetzgebiet($data);
|
|
}
|
|
}
|
|
return $items;
|
|
}
|
|
|
|
private static function getSqlFilter($filter) {
|
|
$where = "1=1 ";
|
|
|
|
if(array_key_exists("netzgebiet_id", $filter)) {
|
|
$netzgebiet_id = $filter['netzgebiet_id'];
|
|
if(is_numeric($netzgebiet_id)) {
|
|
$where .= " AND Netzgebiet.id=$netzgebiet_id";
|
|
} elseif(is_array($netzgebiet_id) && count($netzgebiet_id)) {
|
|
$where .= " AND Netzgebiet.id IN (". implode(",", $netzgebiet_id).")";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("name", $filter)) {
|
|
$name = FronkDB::singleton()->escape($filter['name']);
|
|
if($name) {
|
|
$where .= " AND Netzgebiet.`name` = '$name'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("name%", $filter)) {
|
|
$name = FronkDB::singleton()->escape($filter['name%']);
|
|
if($name) {
|
|
$where .= " AND Netzgebiet.`name` LIKE '$name%'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("extref", $filter)) {
|
|
$extref = FronkDB::singleton()->escape($filter['extref']);
|
|
if($extref) {
|
|
$where .= " AND Netzgebiet.`extref` = '$extref'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("rimo_id", $filter)) {
|
|
$rimo_id = FronkDB::singleton()->escape($filter['rimo_id']);
|
|
if($rimo_id) {
|
|
$where .= " AND Netzgebiet.`rimo_id` LIKE '%$rimo_id%'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("borderpoly", $filter)) {
|
|
$borderpoly = $filter['borderpoly'];
|
|
if($borderpoly === true) {
|
|
$where .= " AND Netzgebiet.`borderpoly` IS NOT NULL";
|
|
} elseif($borderpoly === false || $borderpoly === null) {
|
|
$where .= " AND (Netzgebiet.`borderpoly` IS NULL OR Netzgebiet.`borderpoly` = '')";
|
|
}
|
|
}
|
|
|
|
//var_dump($filter, $where);exit;
|
|
return $where;
|
|
}
|
|
|
|
}
|