76 lines
3.0 KiB
PHP
76 lines
3.0 KiB
PHP
<?php
|
|
|
|
class ADBWohneinheitStatusflagValue extends mfBaseModel {
|
|
private $flag;
|
|
|
|
public function init() {
|
|
$this->db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
|
$this->table = "WohneinheitStatusflagValue";
|
|
}
|
|
|
|
protected function afterSave($_params = []) {
|
|
$this->log->debug("[".$this->_ruid."] "."-----------------------------------------");
|
|
$this->log->debug("[".$this->_ruid."] ".__METHOD__.": statusflagvalue_id: ".$this->id);
|
|
|
|
if(!property_exists($this->_old_data, "value") || $this->_old_data->value != $this->data->value) {
|
|
// cascade new status to all preorders
|
|
foreach(PreorderModel::search(["adb_wohneinheit_id" => $this->wohneinheit_id]) as $preorder) {
|
|
// get PreorederStatusflag
|
|
$pflag = PreorderStatusflagModel::getFirst(["code" => $this->getProperty("flag")->code]);
|
|
if(!$pflag) {
|
|
$this->log->debug("[".$this->_ruid."] ".__METHOD__ . ": Preorder statusflag " . $this->getProperty("flag")->code . " not found");
|
|
return true;
|
|
}
|
|
|
|
// find PreorderStatusflagValue or create it
|
|
$new = false;
|
|
$pflagval = PreorderStatusflagValueModel::getFirst(["preorder_id" => $preorder->id, "flag_id" => $pflag->id]);
|
|
if(!$pflagval) {
|
|
$new = true;
|
|
$pflagval = PreorderStatusflagValueModel::create([
|
|
"preorder_id" => $preorder->id,
|
|
"flag_id" => $pflag->id,
|
|
"value" => 0
|
|
]);
|
|
}
|
|
if($new || $pflagval->value != $this->value) {
|
|
$pflagval->value = $this->value;
|
|
//$this->log->debug("[".$this->_ruid."] ".__METHOD__.": ".print_r($pflagval, true));
|
|
$pflagval->save();
|
|
$this->log->debug("[".$this->_ruid."] ".__METHOD__ . ": statusflag " . $this->getProperty("flag")->code . " saved for preorder " . $preorder->id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public function getProperty($name) {
|
|
if($this->$name == null) {
|
|
|
|
if($name == "flag") {
|
|
if(!$this->flag_id) return null;
|
|
$flag = new ADBStatusflag($this->flag_id);
|
|
if($flag->id) {
|
|
$this->flag = $flag;
|
|
}
|
|
return $this->flag;
|
|
}
|
|
|
|
$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;
|
|
}
|
|
} |