Finished sending of Preordernotifications

This commit is contained in:
Frank Schubert
2023-01-26 22:01:09 +01:00
parent b8d7bd3956
commit fe26e8f2bc
9 changed files with 288 additions and 81 deletions

View File

@@ -9,10 +9,16 @@ class Preordernotification extends mfBaseModel {
private $editor;
public function getPreorders() {
if(!$this->preordercampaign_id) return false;
$preorder_filter = json_decode($this->preorder_filter, true);
$preorder_filter['preordercampaign_id'] = $this->preordercampaign_id;
$preorders = PreorderModel::search($preorder_filter);
return $preorders;
}
public function sendToPreorder(Preorder $preorder, $email_to) {
public function sendToPreorder(Preorder $preorder, $email_to = false) {
$subject = $this->subject;
$body = $this->body_html; // TODO: Variable replacement
$from = $this->sender_email;
@@ -21,10 +27,29 @@ class Preordernotification extends mfBaseModel {
if($this->sender_replyto) {
$reply_to = $this->sender_replyto;
}
$to = $preorder->email;
if($email_to) {
$to = $email_to;
} else {
// check if email was sent to this preorder already
$log = PreordernotificationLogModel::getFirst([
'preordernotification_id' => $this->id,
'preorder_id' => $preorder->id
]);
if(!$log) {
// check if this was sent to the same emailaddress already
$log = PreordernotificationLogModel::getFirst([
'preordernotification_id' => $this->id,
'email' => $preorder->email
]);
}
if($log) {
return true;
}
}
if(!$to) return true;
@@ -61,6 +86,17 @@ class Preordernotification extends mfBaseModel {
}
$email->send();
$this->log->info(__CLASS__."::sendToPreorder(): Sending Preordernotification for Preorder id ".$preorder->id);
if($preorder && !$email_to) {
// save notification log
$log = PreordernotificationLogModel::create([
'preordernotification_id' => $this->id,
'preorder_id' => $preorder->id,
'email' => $preorder->email,
'sent' => date('U')
]);
$log->save();
}
}
return true;

View File

@@ -379,7 +379,11 @@ class PreordernotificationController extends mfBaseController {
}
$this->layout()->setFlash("Erfolgreich gepeichert.", "success");
$this->redirect("Preordernotification", "edit", ['id' => $new_id]);
if($r->return == "index") {
$this->redirect("Preordernotification");
} else {
$this->redirect("Preordernotification", "edit", ['id' => $new_id]);
}
}
}

View File

@@ -1,14 +1,19 @@
<?php
class PreordernotificationModel {
public $sender_email;
public $sender_name;
public $sender_replyto;
public $subject;
public $body_text;
public $body_html;
public $tosend_date;
public $sent_date;
public $send_start;
public $send_finish;
public $recipient_count;
public $preordercampaign_id;
public $preorder_filter;
public $send_lock;
public $note = null;
public $create_by = null;
@@ -145,78 +150,26 @@ class PreordernotificationModel {
}
}
if(array_key_exists("productgroup_id", $filter)) {
$productgroup_id = $filter['productgroup_id'];
if(is_numeric($productgroup_id)) {
$where .= " AND productgroup_id=$productgroup_id";
} elseif(is_array($productgroup_id) && count($productgroup_id)) {
$where .= " AND Preordernotification.productgroup_id IN (". implode(",", $productgroup_id).")";
if(array_key_exists("preordercampaign_id", $filter)) {
$preordercampaign_id = $filter['preordercampaign_id'];
if(is_numeric($preordercampaign_id)) {
$where .= " AND preordercampaign_id=$preordercampaign_id";
} elseif(is_array($preordercampaign_id) && count($preordercampaign_id)) {
$where .= " AND Preordernotification.preordercampaign_id IN (". implode(",", $preordercampaign_id).")";
}
}
if(array_key_exists("producttech_id", $filter)) {
$producttech_id = $filter['producttech_id'];
if(is_numeric($producttech_id)) {
$where .= " AND Preordernotification.producttech_id=$producttech_id";
} elseif(is_array($producttech_id) && count($producttech_id)) {
$where .= " AND Preordernotification.producttech_id IN (". implode(",", $producttech_id).")";
if(array_key_exists("send_finish", $filter)) {
$send_finish = $db->escape($filter['send_finish']);
if($send_finish === null) {
$where .= " AND Preordernotification.send_finish = NULL";
}
}
if(array_key_exists("sla_id", $filter)) {
$sla_id = $filter['sla_id'];
if(is_numeric($sla_id)) {
$where .= " AND sla_id=$sla_id";
} elseif(is_array($sla_id) && count($sla_id)) {
$where .= " AND Preordernotification.sla_id IN (". implode(",", $sla_id).")";
}
}
if(array_key_exists("name", $filter)) {
$name = $db->escape($filter['name']);
if($name) {
$where .= " AND Preordernotification.`name` like '$name'";
}
}
if(array_key_exists("name%", $filter)) {
$name = $db->escape($filter['name%']);
if($name) {
$where .= " AND Preordernotification.`name` like '%$name%'";
}
}
if(array_key_exists("external", $filter)) {
$external = $filter['external'];
if(is_numeric($external)) {
if($external) {
$where .= " AND Preordernotification.external=1";
} else {
$where .= " AND Preordernotification.external=0";
}
}
}
if(array_key_exists("customer_type", $filter)) {
$customer_type = $db->escape($filter['customer_type']);
if($customer_type) {
$where .= " AND Preordernotificationtech.`customer_type` = '$customer_type'";
}
}
if(array_key_exists("attributename", $filter)) {
$attributename = $db->escape($filter['attributename']);
if($attributename) {
$where .= " AND PreordernotificationtechAttribute.name = '$attributename'";
}
}
if(array_key_exists("attributevalue", $filter)) {
$attributevalue = $db->escape($filter['attributevalue']);
if($attributevalue) {
$where .= " AND PreordernotificationAttribute.value = '$attributevalue'";
if(array_key_exists("send_lock", $filter)) {
$send_lock = $db->escape($filter['send_lock']);
if($send_lock === null) {
$where .= " AND Preordernotification.send_lock = NULL";
}
}