Files
thetool/application/ADBHausnummerStatusflagValue/ADBHausnummerStatusflagValue.php
2025-08-20 16:28:12 +02:00

83 lines
3.4 KiB
PHP

<?php
class ADBHausnummerStatusflagValue extends mfBaseModel {
private $flag;
public function init() {
$this->db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$this->table = "HausnummerStatusflagValue";
}
protected function afterSave() {
$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_hausnummer_id" => $this->hausnummer_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 = mfValuecache::singleton()->get("mfObjectmodel-ADBStatusflag-".$this->flag_id);
if(!$flag) {
$flag = new ADBStatusflag($this->flag_id);
if ($flag->id) {
$this->flag = $flag;
mfValuecache::singleton()->set("mfObjectmodel-ADBStatusflag-" . $flag->id, $flag);
}
} else {
$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;
}
}