Files
thetool/application/ADBStatusflag/ADBStatusflag.php
2024-11-06 13:12:32 +01:00

77 lines
2.7 KiB
PHP

<?php
class ADBStatusflag extends mfBaseModel {
private $value;
public $hausnummer_id;
public $wohneinheit_id;
public function init() {
$this->db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$this->table = "Statusflag";
}
public function getProperty($name) {
if($this->$name == null) {
if($name == "value") {
if(!$this->hausnummer_id && !$this->wohneinheit_id) return null;
if($this->hausnummer_id) {
$value = ADBHausnummerStatusflagValueModel::getFirst(["hausnummer_id" => $this->hausnummer_id, "flag_id" => $this->id]);
if(!$value) {
$value = ADBHausnummerStatusflagValueModel::create([
"hausnummer_id" => $this->hausnummer_id,
"flag_id" => $this->id
]);
}
} elseif($this->wohneinheit_id) {
$value = ADBWohneinheitStatusflagValueModel::getFirst(["wohneinheit_id" => $this->wohneinheit_id, "flag_id" => $this->id]);
if(!$value) {
$value = ADBWohneinheitStatusflagValueModel::create([
"wohneinheit_id" => $this->wohneinheit_id,
"flag_id" => $this->id
]);
}
}
$this->value = $value;
return $this->value;
}
if($name == "creator") {
$user = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
if($user) {
$this->creator = $user;
return $this->creator;
}
$this->creator = new User($this->create_by);
if($this->creator->id) {
mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator);
}
return $this->creator;
}
if($name == "editor") {
$this->editor = new User($this->edit_by);
return $this->editor;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
if(!$this->$name) {
$this->$name = new $classname($this->$idfield);
}
if($this->$name->id) {
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
}