Files
fdn2/app/private/lib/dao/models/MailModel.php
2022-08-29 23:20:16 +02:00

82 lines
1.7 KiB
PHP

<?php
/*
Author: Riccardo Di Dato
Creation Date: 25/gen/2016
*/
class MailModel extends Model implements FDN_MailInterface{
const STATUS_PENDING = 0;
const STATUS_SENT = 1;
const STATUS_PAUSED = 2;
const PRIORITY_HIGH = 100;
const PRIORITY_NORMAL = 50;
const PRIORITY_LOW = 10;
public function __construct($saveableObject = null){
parent::__construct($saveableObject);
$requiredProps = array("from","subject","body","recipient");
if (!$this->hasProperty("status")){
$this->status = self::STATUS_PENDING;
}
if (!$this->hasProperty("priority")){
$this->priority = self::PRIORITY_NORMAL;
}
foreach ($requiredProps as $prop){
if (!$this->hasProperty($prop)){
throw new CoreException("Missing parameter '$prop' while calling MailModel::__construct()");
}
}
}
public function __set($attr,$value){
if (strcmp("status", $attr)==0 || strcmp("priority", $attr)==0){
$value = intval($value);
}
return parent::__set($attr, $value);
}
public function getMailObject(){
$email = new PHPMailer();
$email->CharSet = "UTF-8";
$email->isMail();
$email->From = $this->from;
if ($this->hasProperty("fromName")){
$email->FromName = $this->fromName;
}
$email->Subject = $this->subject;
$email->IsHTML(true);
$email->Body = $this->body;
if ($this->hasProperty("altBody")){
$email->AltBody = $this->altBody;
}
else {
$email->AltBody = strip_tags($this->body);
}
$email->AddAddress($this->recipient);
if ($this->hasProperty("attachment")){
$email->AddAttachment( $this->attachment , basename($this->attachment) );
}
return $email;
}
public static function getCollectionName(){
return "mail";
}
}
?>