5 define (
"NEWSLETTER_STATUS_READY", 0);
6 define (
"NEWSLETTER_STATUS_SENT", 1);
15 const TABLE_NAME =
"Newsletter";
18 public $IdAccount = 0;
23 public $DateCreation =
"";
24 public $DateSent =
"";
26 public $LogMessage =
"";
31 public function __construct($src = null, $stripSlashes =
false) {
37 $this->_loadByRow($src, $stripSlashes);
38 }
else if (is_numeric($src) && intval($src) > 0) {
40 $this->_loadFilter(self::GetTableName(__CLASS__),
"Id = " . intval($src));
54 public static function Load ($idApp = 0, $limit = null, $offset = null, &$count = null, $returnArray =
false) {
57 $where = sprintf(
"IdApp = %d", $idApp);
59 return self::_load(self::GetTableName(__CLASS__), ($returnArray ?
"" : __CLASS__), $where, NULL, $limit, $offset, $count);
70 $query = sprintf(
"UPDATE %s SET Subject = '%s', Body = '%s', Status = %d, DateSent = %s, LogMessage = '%s' WHERE Id = %d",
71 self::GetTableName(__CLASS__),
72 $Database->Escape($this->Subject),
73 $Database->Escape($this->Body),
75 $Database->EscapeDate($this->DateSent),
76 $Database->Escape($this->LogMessage),
79 $this->DateCreation = date(
"Y-m-d H:i:s");
80 $query = sprintf(
"INSERT INTO %s (IdAccount, IdApp, Subject, Body, IsHtml, DateCreation, Status, LogMessage) VALUES (%d, %d, '%s', '%s', %d, %s, %d, '{}')",
81 self::GetTableName(__CLASS__),
84 $Database->Escape($this->Subject),
85 $Database->Escape($this->Body),
87 $Database->EscapeDate($this->DateCreation),
91 if ($Database->Query($query)) {
93 $this->Id = $Database->InsertedId();
106 if ($this->Id > 0 && $this->_Delete(self::GetTableName(__CLASS__), sprintf(
"Id = %d", $this->Id))) {
107 $this->_Delete(self::GetTableName(NewsletterLog::class), sprintf(
"IdNewsletter = %d", $this->Id));
117 self::TruncateClass(__CLASS__);
118 self::TruncateClass(NewsletterLog::class);
128 $this->DateSent = date(
"Y-m-d H:i:s");
133 $accounts = Account::LoadAny($this->IdApp);
134 foreach ($accounts as $account) {
135 if (empty($account->Email) || !$account->Enabled) {
139 $recordLog->IdNewsletter = $this->Id;
140 $recordLog->IdAccount = $account->Id;
142 $mail->prepare($this->Subject, $this->Body, $account->Email, NEWSLETTER_SENDER_ADDRESS, NEWSLETTER_SENDER_NAME);
145 $recordLog->Sent = TRUE;
148 $recordLog->Sent = FALSE;
149 $recordLog->Message = $mail->ErrorInfo;
154 $this->LogMessage = json_encode(array(
"sent" => $sent,
"skipped" => $skipped,
"errors" => $errors ));
__construct($src=null, $stripSlashes=false)
const NEWSLETTER_STATUS_READY
static Load($idApp=0, $limit=null, $offset=null, &$count=null, $returnArray=false)
const NEWSLETTER_STATUS_SENT