WIP Preorder Status Notifications

This commit is contained in:
Frank Schubert
2024-11-26 15:10:27 +01:00
parent 30530a0177
commit 9a3eca761e
6 changed files with 128 additions and 0 deletions

View File

@@ -376,6 +376,24 @@
</div> </div>
</div> </div>
<h4>Emailbenachrichtigungen</h4>
<div class="card">
<div class="card-body">
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="from_email_name">Absender Name</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="from_email_name" id="from_email_name" value="<?= $campaign->from_email_name ?>"/>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="from_email">Absender Emailadresse</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="from_email" id="from_email" value="<?= $campaign->from_email ?>"/>
</div>
</div>
</div>
</div>
<h4>API-User</h4> <h4>API-User</h4>
<div class="card"> <div class="card">

View File

@@ -153,6 +153,8 @@ class Preorder extends mfBaseModel {
$this->log->error("config TT_PREORDER_STATUS_MATRIX not defined!"); $this->log->error("config TT_PREORDER_STATUS_MATRIX not defined!");
} }
$actions = [];
// run every trigger bnetween old and new status code // run every trigger bnetween old and new status code
foreach(TT_PREORDER_STATUS_MATRIX as $intermediate_code => $status) { foreach(TT_PREORDER_STATUS_MATRIX as $intermediate_code => $status) {
if($intermediate_code <= $old_status->code) continue; if($intermediate_code <= $old_status->code) continue;
@@ -180,12 +182,38 @@ class Preorder extends mfBaseModel {
$trigger = new $classname($this, $new_status); $trigger = new $classname($this, $new_status);
$trigger->run(); $trigger->run();
if(array_key_exists("action", $status) && is_array($status) && property_exists($trigger, "run_action") && $trigger->run_action) {
foreach($status["action"] as $type => $action) {
if(!array_key_exists($type, $actions)) {
$actions[$type] = [];
}
$actions[$type][] = $trigger;
}
}
// run last email action
if(array_key_exists("email", $actions) && is_array($actions["email"]) && count($actions["email"])) {
$email_action = array_pop($actions["email"]);
$this->runTriggerEmailAction($email_action);
}
} }
return true; return true;
}
private function runTriggerEmailAction($action) {
if(!array_key_exists("template", $action)) return false;
if(!array_key_exists("from", $action)) return false;
//if(!array_key_exists("to", $action)) return false;
//if(!array_key_exists("data", $action)) return false;
} }
/* /*

View File

@@ -0,0 +1,46 @@
<?php
class Preorder_Statustrigger_140 {
private $log;
private $preorder;
private $new_status;
public $run_action = true;
public function __construct(Preorder $preorder, Preorderstatus $new_status) {
$this->log = mfLoghandler::singleton();
$this->preorder = $preorder;
$this->new_status = $new_status;
}
public function run() {
$this->log->debug(__METHOD__.": running trigger");
$changes = false;
if(!$this->preorder->ciftoken) {
$this->preorder->ciftoken = $this->preorder->createCiftoken();
$changes = true;
}
/*if(!$this->preorder->ciftoken) {
$this->log->warning("Error creating ciftoken for preorder ".$this->preorder->id);
return true;
}*/
if(!$this->preorder->cifurl) {
$this->preorder->cifurl = $this->preorder->generateCifUrl();
$changes = true;
}
if(!$this->preorder->cifcableurl) {
$this->preorder->cifcableurl = $this->preorder->generateCifCableUrl();
$changes = true;
}
if($changes) {
$this->preorder->save();
}
return true;
}
}

View File

@@ -236,6 +236,8 @@ class PreordercampaignController extends mfBaseController {
$data['homes_total'] = (int)$r->homes_total; $data['homes_total'] = (int)$r->homes_total;
$data["cifurl"] = trim($r->cifurl); $data["cifurl"] = trim($r->cifurl);
$data["cifcableurl"] = trim($r->cifcableurl); $data["cifcableurl"] = trim($r->cifcableurl);
$data["from_email_name"] = trim($r->from_email_name);
$data["from_email"] = trim($r->from_email);
if($r->from) { if($r->from) {
$data['from'] = self::dateToTimestamp($r->from); $data['from'] = self::dateToTimestamp($r->from);

View File

@@ -19,6 +19,8 @@ class PreordercampaignModel {
public $allow_unit_update; public $allow_unit_update;
public $cifurl; public $cifurl;
public $cifcableurl; public $cifcableurl;
public $from_email_name;
public $from_email;
public $banned_rimo_fcp; public $banned_rimo_fcp;
public $note; public $note;

View File

@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class PreordercampaignAddEmailFrom extends AbstractMigration
{
public function up(): void
{
if($this->getEnvironment() == "thetool") {
$table = $this->table('Preordercampaign');
$table->addColumn('from_email_name', 'string', ["null" => true, "default" => null, 'limit' => 64, "after" => "cifcableurl"]);
$table->addColumn('from_email', 'string', ["null" => true, "default" => null, 'limit' => 64, "after" => "from_email_name"]);
$table->update();
}
if($this->getEnvironment() == "addressdb") {
}
}
public function down(): void
{
if($this->getEnvironment() == "thetool") {
}
if($this->getEnvironment() == "addressdb") {
}
}
}