db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME); $this->table = "Hausnummer"; } /* public static function parseAddresszusatz($text) { $zusatz = ""; $text = trim($text); if(!$text) return $data; $text = " ".$text; $m = []; if(preg_match('/((?:gesch(?:ae|ä)ft|betrieb und wohnungen|paketlogistik|cafe|pavillon|pfarrheim|[^ ]*haus|[^ ]*geb(?:ae|ä)ude|[^ ]*halle)(?:\s+[a-z0-9]+)?)/i', $text, $m)) { $zusatz = $m[1]; $text = str_replace($m[0], "", $text); } $text = trim(preg_replace('/\s{2,}/', "", $text)); if($text) { $data['zusatz'] = $text; } return $data; }*/ public function getAddress() { $address = "[".$this->getProperty("strasse")->gemeinde->name."]"; $address .= " ".$this->getProperty("plz")->plz; $address .= " ".$this->getProperty("ortschaft")->name.","; $address .= " ".$this->getProperty("strasse")->name; $address .= " ".$this->hausnummer; return $address; } public function getNewOAID() { if(!$this->plz_id) { return false; } $cc = "AT"; $zip = $this->getProperty("plz")->plz; for($try = 16; $try > 0; $try--) { $rnd[0] = random_int(0, 255); $rnd[1] = random_int(0, 255); $rnd[2] = random_int(0, 255); $rnd[3] = random_int(0, 255); $code = "$cc-$zip-"; foreach($rnd as $r) { $code .= str_pad(dechex($r), 2, "0", STR_PAD_LEFT); } if(ADBHausnummerModel::search(['oaid' => $code])) { $this->log->warn(__FILE__."::getNewObjectCode: New Code already in use. Trying again for a maximum of $try times."); } else { // code is unique break; } } if($try == 0) { return null; } return $code; } public function getProperty($name) { if($this->$name == null) { if($name == "freigaben") { $this->freigaben = json_decode($this->freigabe); if(!is_array($this->freigaben)) { $this->freigaben = []; } return $this->freigaben; } if($name == "netzgebiet") { $this->netzgebiet = mfValuecache::singleton()->getMfObject("ADBNetzgebiet", $this->netzgebiet_id); return $this->netzgebiet; } if($name == "ortschaft") { $this->ortschaft = mfValuecache::singleton()->getMfObject("ADBOrtschaft", $this->ortschaft_id); return $this->ortschaft; } if($name == "strasse") { $this->strasse = mfValuecache::singleton()->getMfObject("ADBStrasse", $this->strasse_id); return $this->strasse; } if($name == "plz") { $this->plz = mfValuecache::singleton()->getMfObject("ADBPlz", $this->plz_id); return $this->plz; } if($name == "wohneinheiten") { $this->wohneinheiten = mfValuecache::singleton()->get("adbWohneinheiten-hausnummer-".$this->id); if($this->wohneinheiten === null) { $this->wohneinheiten = ADBWohneinheitModel::search(['hausnummer_id' => $this->id]); if($this->wohneinheiten) { mfValuecache::singleton()->set("adbWohneinheiten-hausnummer-".$this->id, $this->wohneinheiten); } } return $this->wohneinheiten; } $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; } }