Added general history in Preorder
This commit is contained in:
@@ -39,6 +39,7 @@ class Preorder extends mfBaseModel {
|
||||
$this->creator = null;
|
||||
$this->editor = null;
|
||||
|
||||
// prevent potential infinite loop
|
||||
$nesting_level = mfValuecache::singleton()->get("preorder-save-nesting-level-".$this->id);
|
||||
if(!$nesting_level) {
|
||||
$nesting_level = 1;
|
||||
@@ -51,9 +52,6 @@ class Preorder extends mfBaseModel {
|
||||
return true;
|
||||
}
|
||||
|
||||
// prevent potential infinite loop
|
||||
//if($this->in_after_save) return true;
|
||||
//$this->in_after_save++;
|
||||
// update preorder OAID if it's different from the unit OAID
|
||||
// but only if the unit OAID is of the same origin as the campaign
|
||||
$old_oaid = $this->oaid;
|
||||
@@ -64,10 +62,9 @@ class Preorder extends mfBaseModel {
|
||||
}
|
||||
|
||||
//TODO: history start
|
||||
if($this->status_id != $this->_old_data->status_id) {
|
||||
//if($this->status_id != $this->_old_data->status_id) {
|
||||
$this->createHistoryEntry();
|
||||
$this->_old_data->status_id = $this->status_id;
|
||||
}
|
||||
//}
|
||||
|
||||
// run triggers based on new status
|
||||
$this->runStatusTrigger();
|
||||
@@ -79,13 +76,22 @@ class Preorder extends mfBaseModel {
|
||||
}
|
||||
|
||||
public function createHistoryEntry() {
|
||||
$history = PreorderHistoryModel::create([
|
||||
"preorder_id" => $this->id,
|
||||
"key" => 'preorderstatus_id',
|
||||
"old_value" => $this->_old_data->status_id,
|
||||
"new_value" => $this->status_id
|
||||
]);
|
||||
$history->save();
|
||||
if(!$this->id) return true;
|
||||
|
||||
$changed = $this->getChangedFields();
|
||||
|
||||
foreach($changed as $field) {
|
||||
$this->log->debug(__METHOD__.": $field changed from '".$this->_old_data->$field."' to '".$this->data->$field."'");
|
||||
$history = PreorderHistoryModel::create([
|
||||
"preorder_id" => $this->id,
|
||||
"key" => $field,
|
||||
"old_value" => $this->_old_data->$field,
|
||||
"new_value" => $this->data->$field
|
||||
]);
|
||||
$history->save();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function runStatusTrigger() {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
class PreorderHistory extends mfBaseModel {
|
||||
protected $forcestr = ["old_value", "new_value"];
|
||||
private $preorder;
|
||||
private $creator;
|
||||
private $editor;
|
||||
@@ -25,14 +26,54 @@ class PreorderHistory extends mfBaseModel {
|
||||
if(preg_match('/(.+)_id/', $this->key, $m)) {
|
||||
if(array_key_exists(1, $m)) {
|
||||
$object = ucfirst($m[1]);
|
||||
|
||||
$value = new $object($value);
|
||||
if(!$value->id) return null;
|
||||
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 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<br />";
|
||||
}
|
||||
return $attribs;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
|
||||
@@ -41,7 +41,7 @@ class PreorderHistoryModel {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("PreorderHistory", "*", "$where ORDER BY preorder_id,`key`,`create` LIMIT 1");
|
||||
$res = $db->select("PreorderHistory", "*", "$where ORDER BY `create`,`key` LIMIT 1");
|
||||
if ($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new PreorderHistory($data);
|
||||
@@ -59,7 +59,7 @@ class PreorderHistoryModel {
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("PreorderHistory", "*", "1=1 ORDER BY preorder_id,`key`,`create`");
|
||||
$res = $db->select("PreorderHistory", "*", "1=1 ORDER BY `create`,`key`");
|
||||
if ($db->num_rows($res)) {
|
||||
while ($data = $db->fetch_object($res)) {
|
||||
$items[] = new PreorderHistory($data);
|
||||
@@ -91,7 +91,7 @@ class PreorderHistoryModel {
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT * FROM PreorderHistory
|
||||
WHERE $where
|
||||
ORDER BY preorder_id,`key`,`create`";
|
||||
ORDER BY `create`,`key`";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
if (is_array($limit) && count($limit)) {
|
||||
|
||||
Reference in New Issue
Block a user