69 lines
1.4 KiB
PHP
69 lines
1.4 KiB
PHP
<?php
|
|
|
|
class ADBGemeinde extends mfBaseModel {
|
|
public $plz = [];
|
|
|
|
|
|
protected function init() {
|
|
$this->db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
|
}
|
|
|
|
|
|
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->plz as $plz) {
|
|
$list[$plz->id] = $plz->plz;
|
|
}
|
|
return $list;
|
|
}
|
|
}
|