createHistoryEntry(); } protected function createHistoryEntry() { if(!$this->id) return true; $changed = $this->getChangedFields(); if($this->key == "status_id" && in_array("changed", $changed) && $this->_old_data->changed) { try { $status = new Preorderstatus($this->new_value); if(!$status->id) return true; $this->log->debug(__METHOD__ . ": 'changed' changed from '" . $this->_old_data->changed . "' to '" . $this->data->changed . "'"); $history = PreorderHistoryModel::create([ "preorder_id" => $this->preorder_id, "key" => "status_changed-".$status->code, "old_value" => $this->_old_data->changed, "new_value" => $this->data->changed, "changed" => date("U") ]); $history->save(); } catch(Exception $e) { $this->log->debug($e->getTraceAsString()); } } } public function getValue($type = "new", $raw = false) { if($type != "old" && $type != "new") return null; if($type == "new") { $value = $this->new_value; } else { $value = $this->old_value; } if($raw) { return $value; } $m = []; if(preg_match('/(.+)_id/', $this->key, $m)) { if(array_key_exists(1, $m)) { $object = ucfirst($m[1]); if($object == "Status") $object = "Preorderstatus"; if($object == "Partner") $object = "Address"; if($object == "Adb_hausnummer") $object = "ADBHausnummer"; if($object == "Adb_wohneinheit") $object = "ADBWohneinheit"; if(class_exists($object)) { $value = new $object($value); if(!$value->id) return null; } } } 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->code." - ".$psf->name; } } if(preg_match('/status_changed-(\d+)/', $key, $m)) { if(array_key_exists(1, $m)) { $code = $m[1]; $ps = PreorderstatusModel::getFirst(["code" => $code]); if($code == 500) { return "Aktivierungsdatum (Status 500)"; } return "Status ".$ps->code." Timestamp"; } } return $key; } public function getText($type = "new") { $value = $this->getValue($type); if($value === null) return ""; if($this->key == "attributes") { $attribs = ""; $jdec = json_decode($value); if(is_object($jdec)) { foreach(get_object_vars($jdec) as $k => $v) { $attribs .= "$k: $v
"; } return $attribs; } } if($this->key == "order_date" && $value) { return date("d.m.Y", $value); } if(preg_match('/^status_changed-/', $this->key)) { return date("d.m.Y", $value); } if(!is_object($value)) { return $value; } if(get_class($value) == "Preorderstatus") { return $value->code." - ".$value->name; } if(get_class($value) == "Address") { return $value->getCompanyOrName(); } if(get_class($value) == "ADBHausnummer") { return $value->getAddress(); } if(get_class($value) == "ADBWohneinheit") { return $value->id." - ".(string)$value; } if(get_class($value) == "Preordercampaign") { return $value->name; } return ""; } public function getProperty($name) { if($this->$name == null) { if($name == "old" || $name == "new") { return $this->getValue($name, false); } if($name == "old_raw") { return $this->getValue("old", true); } if($name == "new_raw") { return $this->getValue("new", true); } if($name == "creator") { $this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by); if($this->creator === null) { $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 = mfValuecache::singleton()->get("Worker-id-".$this->edit_by); if($this->editor === null) { $this->editor = new User($this->edit_by); if($this->editor->id) { mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor); } } return $this->editor; } $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; } }