summaryrefslogtreecommitdiff
path: root/app/frontend/mail/MailModule.php
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-11-03 23:29:15 +0100
committeremkael <emkael@tlen.pl>2016-11-03 23:31:39 +0100
commitfc36e60cc8f2b5a5919a6262571868365a209d17 (patch)
treed037fb8ef2ecad64307427d89a81be70d528d579 /app/frontend/mail/MailModule.php
parentbef5754e4676a8a578550b6af24d050a946405eb (diff)
* mail queueing, depending on the template
Diffstat (limited to 'app/frontend/mail/MailModule.php')
-rw-r--r--app/frontend/mail/MailModule.php38
1 files changed, 35 insertions, 3 deletions
diff --git a/app/frontend/mail/MailModule.php b/app/frontend/mail/MailModule.php
index 464f1d0..4d2faeb 100644
--- a/app/frontend/mail/MailModule.php
+++ b/app/frontend/mail/MailModule.php
@@ -4,17 +4,29 @@ Prado::using('System.I18N.Globalization');
Prado::using('Application.mail.Mailer');
Prado::using('Application.mail.MailTemplate');
Prado::using('Application.mail.MailTemplateTranslator');
+Prado::using('Application.model.MailQueue');
class MailModule extends TModule {
private $_configPath;
private $_config;
+ private $_queuedTemplates = [];
+
private $_templatePath;
private static $_templateExtension = 'html';
private $_templateCacheSubpath = 'mail';
private static $_templateTranslationCatalogue = 'messages';
+ public function init($xml) {
+ parent::init($xml);
+ if ($queueTemplates = $xml->getElementByTagName('mail-queue')) {
+ foreach ($queueTemplates->getElementsByTagName('template') as $template) {
+ $this->_queuedTemplates[] = $template->Attributes['id'];
+ }
+ }
+ }
+
public function setConfigPath(string $configPath) {
$this->_configPath = TPropertyValue::ensureString($configPath);
$this->_config = json_decode(
@@ -24,6 +36,10 @@ class MailModule extends TModule {
);
}
+ public function getConfig() {
+ return $this->_config;
+ }
+
public function setTemplatePath(string $templatePath) {
$this->_templatePath = Prado::getPathOfNamespace(
TPropertyValue::ensureString($templatePath)
@@ -92,14 +108,19 @@ class MailModule extends TModule {
return self::$_translator;
}
- public function getTemplate(string $template, string $language='') {
- $template = new MailTemplate($template . '.' . $this->TemplateExtension);
+ public function getTemplate(string $templateID, string $language='') {
+ $template = new MailTemplate($templateID . '.' . $this->TemplateExtension);
+
$template->setOutputMode(PHPTAL::HTML5);
$template->setTemplateRepository($this->_templatePath);
$template->setPhpCodeDestination($this->CachePath);
+
+ $template->toggleImmediate(!in_array($templateID, $this->_queuedTemplates));
+
$translator = self::_getTranslator();
$translator->setLanguage($language);
$template->setTranslator($translator);
+
return $template;
}
@@ -112,10 +133,21 @@ class MailModule extends TModule {
);
}
$mailer = new Mailer();
- $mailer->configure($this->_config);
+ $mailer->configure($this);
return $mailer;
}
+ public function queueMail(string $subject, string $body, string $rcptMail, string $rcptName) {
+ $queue = new MailQueue();
+ $queue->Subject = $subject;
+ $queue->HtmlBody = $body;
+ $queue->TextBody = strip_tags($body);
+ $queue->RecipientName = $rcptName;
+ $queue->RecipientMail = $rcptMail;
+ $queue->CreateTime = date('Y-m-d H:i:s');
+ return $queue->save();
+ }
+
}
?>