126 lines
3.5 KiB
PHP
126 lines
3.5 KiB
PHP
<?php
|
|
|
|
class Preordernotification extends mfBaseModel {
|
|
private $campaign;
|
|
private $filter;
|
|
private $files;
|
|
|
|
private $creator;
|
|
private $editor;
|
|
|
|
public function getPreorders() {
|
|
|
|
}
|
|
|
|
public function sendToPreorder(Preorder $preorder, $email_to) {
|
|
$subject = $this->subject;
|
|
$body = $this->body_html; // TODO: Variable replacement
|
|
$from = $this->sender_email;
|
|
$from_name = $this->sender_name;
|
|
$reply_to = null;
|
|
if($this->sender_replyto) {
|
|
$reply_to = $this->sender_replyto;
|
|
}
|
|
$to = $preorder->email;
|
|
|
|
if($email_to) {
|
|
$to = $email_to;
|
|
}
|
|
|
|
if(!$to) return true;
|
|
|
|
// get attachments
|
|
$attachments = [];
|
|
foreach($this->getProperty("files") as $file) {
|
|
$att = [];
|
|
$att["path"] = MFUPLOAD_FILE_SAVE_PATH."/".$file->file->subfolder."/".$file->file->store_filename;
|
|
$att["filename"] = $file->filename;
|
|
$att["mimetype"] = $file->file->mimetype;
|
|
$attachments[] = $att;
|
|
}
|
|
|
|
//var_dump($attachments);exit;
|
|
|
|
if(!$subject || !$from || !$from_name || !$to) {
|
|
$this->log->warn("Preordernotification not sent. subject, from or to missing. Preorder id ".$preorder->id);
|
|
return false;
|
|
} else {
|
|
$email = new Emailnotification();
|
|
$email->setSubject($subject);
|
|
$email->setHtmlBody($body);
|
|
$email->setFrom($from, $from_name);
|
|
$email->setTo($to);
|
|
if($reply_to) {
|
|
$email->setHeader("Reply-To", $reply_to);
|
|
}
|
|
$email->setHeader("X-".ucfirst(MFAPPNAME)."-Pnid", $this->id);
|
|
if(count($attachments)) {
|
|
foreach($attachments as $file) {
|
|
$email->addAttachment($file["path"], null, $file["filename"], $file['mimetype']);
|
|
}
|
|
}
|
|
$email->send();
|
|
$this->log->info(__CLASS__."::sendToPreorder(): Sending Preordernotification for Preorder id ".$preorder->id);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function getProperty($name) {
|
|
if($this->$name == null) {
|
|
|
|
if($name == "campaign") {
|
|
$this->campaign = new Preordercampaign($this->preordercampaign_id);
|
|
return $this->campaign;
|
|
}
|
|
|
|
if($name == "filter") {
|
|
if($this->preorder_filter) {
|
|
$this->filter = json_decode($this->preorder_filter, true);
|
|
} else {
|
|
$this->filter = [];
|
|
}
|
|
return $this->filter;
|
|
}
|
|
|
|
if($name == "files") {
|
|
$this->files = PreordernotificationFileModel::search(["preordernotification_id" => $this->id]);
|
|
return $this->files;
|
|
}
|
|
|
|
if($name == "creator") {
|
|
$user = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
|
if($user) {
|
|
$this->creator = $user;
|
|
return $this->creator;
|
|
}
|
|
$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 = new User($this->edit_by);
|
|
return $this->editor;
|
|
}
|
|
|
|
$classname = ucfirst($name);
|
|
$idfield = $name."_id";
|
|
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
|
|
if(!$this->$name) {
|
|
$this->$name = new $classname($this->$idfield);
|
|
}
|
|
|
|
if($this->$name->id) {
|
|
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
|
|
return $this->$name;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
return $this->$name;
|
|
}
|
|
} |