Added PreorderStatusflags to PreorderHistory

This commit is contained in:
Frank Schubert
2024-07-29 16:13:04 +02:00
parent 4abaa50f56
commit 0dce17ac25
4 changed files with 33 additions and 2 deletions
@@ -37,9 +37,23 @@ class PreorderHistory extends mfBaseModel {
}
}
return $value;
}
public function getKey() {
$key = $this->key;
if(preg_match('/^preorderstatusflag-(\d+)-/', $key, $m)) {
if(array_key_exists(1, $m)) {
$id = $m[1];
$psf = new Preorderstatusflag($id);
return "Status Flag ".$psf->name;
}
}
return $key;
}
public function getText($type = "new") {
$value = $this->getValue($type);
if($value === null) return "";
@@ -10,6 +10,12 @@ class PreorderStatusflag extends mfBaseModel {
if($name == "value") {
if(!$this->preorder_id) return null;
$value = PreorderStatusflagValueModel::getFirst(["preorder_id" => $this->preorder_id, "flag_id" => $this->id]);
if(!$value) {
$value = PreorderStatusflagValueModel::create([
"preorder_id" => $this->preorder_id,
"flag_id" => $this->id
]);
}
$this->value = $value;
return $this->value;
}
@@ -2,4 +2,15 @@
class PreorderStatusflagValue extends mfBaseModel {
protected function afterSave() {
if($this->_old_data->value != $this->value) {
$history = PreorderHistoryModel::create([
"preorder_id" => $this->preorder_id,
"key" => "preorderstatusflag-".$this->flag_id."-value",
"old_value" => $this->_old_data->value,
"new_value" => $this->data->value
]);
$history->save();
}
}
}