Added preorderTrigger / added cif api docs

This commit is contained in:
Frank Schubert
2024-02-26 23:13:30 +01:00
parent 26d022441d
commit 2af51a2f57
7 changed files with 425 additions and 186 deletions
+56
View File
@@ -48,6 +48,8 @@ class Preorder extends mfBaseModel {
$this->save();
}
// run triggers based on new status
$this->runStatusTrigger();
// Cascade status changes down to adb_hausnummer and adb_wohneinheit
$this->cascadeStatus();
// Cascade status changes down all active preorders with the same hausnummer
@@ -56,6 +58,59 @@ class Preorder extends mfBaseModel {
$this->in_after_save--;
}
public function runStatusTrigger() {
if(!$this->id) return true;
if($this->status_id == $this->_old_data->status_id) return true;
$this->log->debug(__METHOD__." running");
$new_status = $this->getProperty("status");
$old_status = new Preorderstatus($this->_old_data->status_id);
if(!$new_status->id || !$old_status->id) return true;
$this->log->debug(__METHOD__." status changed from '".($old_status ? $old_status->code : "")."' to '".$new_status->code."'");
if($new_status->code <= $old_status->code) return true;
if(!defined("TT_PREORDER_STATUS_MATRIX") || !TT_PREORDER_STATUS_MATRIX) {
$this->log->error("config TT_PREORDER_STATUS_MATRIX not defined!");
}
// run every trigger bnetween old and new status code
foreach(TT_PREORDER_STATUS_MATRIX as $intermediate_code => $status) {
if($intermediate_code <= $old_status->code) continue;
if($intermediate_code > $new_status->code) continue;
$code = $intermediate_code;
// find trigger for new status code
$classname = "Preorder_Statustrigger_$code";
$filepath = __DIR__."/statustrigger/$code.php";
$this->log->debug(__METHOD__.": Looking for $classname in $filepath");
if(!file_exists($filepath)) {
$this->log->debug(__METHOD__.": $filepath not found");
continue;
}
require_once $filepath;
if(!class_exists($classname)) {
$this->log->debug(__METHOD__.": $classname not found");
continue;
}
$trigger = new $classname($this, $new_status);
$trigger->run();
}
return true;
}
/*
* Cascade status changes down to adb_hausnummer and adb_wohneinheit
*/
@@ -400,6 +455,7 @@ class Preorder extends mfBaseModel {
$hausnummer = $this->getProperty("adb_hausnummer");
$wohneinheit = $this->getProperty("adb_wohneinheit");
$campaign = $this->getProperty("campaign");
$a = [];
$a["ciftoken"] = $this->ciftoken;