Merge branch 'fronkdev' into 'master'
Added ADB Gwrgst table and auto EZ in ConstructionConsent See merge request fronk/thetool!1055
This commit is contained in:
266
application/ADBGwrgst/ADBGwrgst.php
Normal file
266
application/ADBGwrgst/ADBGwrgst.php
Normal file
@@ -0,0 +1,266 @@
|
||||
<?php
|
||||
|
||||
class ADBGwrgst extends mfBaseModel {
|
||||
protected $forcestr = ["gstnr", "g", "ba", "nu", "tind", "ind", "flaeche", "emz", "gfn", "gft", "kgez", "ez"];
|
||||
|
||||
protected function init() {
|
||||
$this->db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
$this->table = "Gwrgst";
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
|
||||
if($this->$name->id) {
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
/*
|
||||
* Static Model function
|
||||
*/
|
||||
|
||||
/********************************
|
||||
* Begin static Model functions
|
||||
*/
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new ADBGwrgst();
|
||||
|
||||
$table_fields = [
|
||||
"kgnr", "gstnr", "g", "ba", "nu", "tind", "ind", "flaeche", "emz", "gfn", "gft", "kgez", "ez",
|
||||
"create","edit"
|
||||
];
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(in_array($field, $table_fields)) {
|
||||
$model->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
$res = $db->select("Gwrgst", "*", "1 = 1 ORDER BY id");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Gwrgst($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst($filter) {
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT Gwrgst.* FROM Gwrgst
|
||||
WHERE $where
|
||||
ORDER BY id
|
||||
LIMIT 1";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new ADBGwrgst($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
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 Gwrgst
|
||||
WHERE $where
|
||||
ORDER BY id
|
||||
";
|
||||
|
||||
//mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$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, $order = false) {
|
||||
//var_dump($filter);exit;
|
||||
$items = [];
|
||||
|
||||
if(!$order) {
|
||||
$order = "id ASC";
|
||||
}
|
||||
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT Gwrgst.* FROM Gwrgst
|
||||
WHERE $where
|
||||
GROUP BY Gwrgst.id
|
||||
ORDER BY $order";
|
||||
|
||||
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'];
|
||||
}
|
||||
}
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new ADBGwrgst($data);
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
|
||||
if(array_key_exists("constructionconsent_id", $filter)) {
|
||||
$constructionconsent_id = $filter["constructionconsent_id"];
|
||||
if(is_numeric($constructionconsent_id)) {
|
||||
$where .= " AND constructionconsent_id='$constructionconsent_id'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("kgnr", $filter)) {
|
||||
$kgnr = $db->escape($filter["kgnr"]);
|
||||
if($kgnr) {
|
||||
$where .= " AND `kgnr`='$kgnr'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("gstnr", $filter)) {
|
||||
$gstnr = $db->escape($filter["gstnr"]);
|
||||
if($gstnr) {
|
||||
$where .= " AND `gstnr`='$gstnr'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("g", $filter)) {
|
||||
$g = $db->escape($filter["g"]);
|
||||
if($g) {
|
||||
$where .= " AND `g`='$g'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("ba", $filter)) {
|
||||
$ba = $db->escape($filter["ba"]);
|
||||
if($ba) {
|
||||
$where .= " AND `ba`='$ba'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("nu", $filter)) {
|
||||
$nu = $db->escape($filter["nu"]);
|
||||
if($nu) {
|
||||
$where .= " AND `nu`='$nu'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("tind", $filter)) {
|
||||
$tind = $db->escape($filter["tind"]);
|
||||
if($tind) {
|
||||
$where .= " AND `tind`='$tind'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("ind", $filter)) {
|
||||
$ind = $db->escape($filter["ind"]);
|
||||
if($ind) {
|
||||
$where .= " AND `ind`='$ind'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("flaeche", $filter)) {
|
||||
$flaeche = $db->escape($filter["flaeche"]);
|
||||
if($flaeche) {
|
||||
$where .= " AND `flaeche`='$flaeche'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("emz", $filter)) {
|
||||
$emz = $db->escape($filter["emz"]);
|
||||
if($emz) {
|
||||
$where .= " AND `emz`='$emz'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("gfn", $filter)) {
|
||||
$gfn = $db->escape($filter["gfn"]);
|
||||
if($gfn) {
|
||||
$where .= " AND `gfn`='$gfn'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("gft", $filter)) {
|
||||
$gft = $db->escape($filter["gft"]);
|
||||
if($gft) {
|
||||
$where .= " AND `gft`='$gft'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("kgez", $filter)) {
|
||||
$kgez = $db->escape($filter["kgez"]);
|
||||
if($kgez) {
|
||||
$where .= " AND `kgez`='$kgez'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("ez", $filter)) {
|
||||
$ez = $db->escape($filter["ez"]);
|
||||
if($ez) {
|
||||
$where .= " AND `ez`='$ez'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists("add-where", $filter)) {
|
||||
$where .= " ".$filter['add-where'];
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
}
|
||||
@@ -492,6 +492,9 @@ class ConstructionConsentController extends mfBaseController {
|
||||
case "deleteRimoPlan":
|
||||
$return = $this->deleteRimoPlanApi();
|
||||
break;
|
||||
case "getEz":
|
||||
$return = $this->getEzApi();
|
||||
break;
|
||||
default:
|
||||
$this->log->warn(__METHOD__ . ": Called API function '$do' does not exist");
|
||||
$return = false;
|
||||
@@ -506,6 +509,22 @@ class ConstructionConsentController extends mfBaseController {
|
||||
$this->returnJson($data);
|
||||
}
|
||||
|
||||
private function getEzApi() {
|
||||
$kg = trim($this->request->kg);
|
||||
$gst = trim($this->request->gst);
|
||||
|
||||
if(!$kg || !$gst) return false;
|
||||
|
||||
$ez = ADBGwrgst::getFirst(["kgnr" => $kg, "gstnr" => $gst]);
|
||||
//var_dump($ez);exit;
|
||||
if(!$ez) {
|
||||
return ["ez" => ""];
|
||||
}
|
||||
|
||||
return ["ez" => $ez->ez];
|
||||
}
|
||||
|
||||
|
||||
private function findStreetApi() {
|
||||
$addresses = [];
|
||||
$search = trim($this->request->q);
|
||||
|
||||
Reference in New Issue
Block a user