101 lines
2.1 KiB
PHP
101 lines
2.1 KiB
PHP
<?php
|
|
|
|
class ADBGemeinde extends mfBaseModel {
|
|
public $plzs = [];
|
|
private $ortschaften = [];
|
|
|
|
protected function init() {
|
|
$this->db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
|
$this->table = "Gemeinde";
|
|
}
|
|
|
|
|
|
public function loadByGemeindeCode($code) {
|
|
$res = $this->db->select("Gemeinde","*","code=$code");
|
|
if($this->db->num_rows($res)) {
|
|
$data = $this->db->fetch_object($res);
|
|
$this->load($data);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function find($search) {
|
|
$seach = $this->db->escape($search);
|
|
if(!$search) {
|
|
return false;
|
|
}
|
|
|
|
$results = [];
|
|
|
|
$res = $this->db->select("Gemeinde", "*", "name like '%$search%'");
|
|
if($this->db->num_rows($res)) {
|
|
while($data = $this->db->fetch_object($res)) {
|
|
$results[] = new ADBGemeinde($data);
|
|
}
|
|
}
|
|
|
|
return $results;
|
|
}
|
|
|
|
public function afterLoad() {
|
|
//$this->loadPlz();
|
|
}
|
|
|
|
/*public function loadPlz() {
|
|
if(!$this->id) {
|
|
return false;
|
|
}
|
|
|
|
$plz = [];
|
|
|
|
$res = $this->db->select("Plz","*","gemeinde_id=".$this->id);
|
|
if($this->db->num_rows($res)) {
|
|
while($data = $this->db->fetch_object($res)) {
|
|
$this->plz[] = new ADBPlz($data);
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}*/
|
|
|
|
public function getPlzList() {
|
|
$list = [];
|
|
foreach($this->plzs as $plz) {
|
|
$list[$plz->id] = $plz->plzs;
|
|
}
|
|
return $list;
|
|
}
|
|
|
|
public function getProperty($name) {
|
|
if($this->$name == null) {
|
|
|
|
if(!$this->id) {
|
|
return null;
|
|
}
|
|
|
|
if($name == "types") {
|
|
$this->loadAddresstypes();
|
|
return $this->types;
|
|
}
|
|
|
|
if($name == "ortschaften") {
|
|
$this->ortschaften = ADBOrtschaftModel::search(["gemeinde_id" => $this->id]);
|
|
return $this->ortschaften;
|
|
}
|
|
|
|
$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;
|
|
}
|
|
}
|