summaryrefslogtreecommitdiff
path: root/app/frontend/mail/MailModule.php
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-10-31 21:57:54 +0100
committeremkael <emkael@tlen.pl>2016-10-31 21:59:22 +0100
commitf1c5b6c282e34a9e6b5c140371acd623c7b50d60 (patch)
treec4b27a44b9878c900c038bccae7cab102835a669 /app/frontend/mail/MailModule.php
parentd216b3147bc3f37cf2337acab5767c6a4f74aa2e (diff)
* mail templating module
Diffstat (limited to 'app/frontend/mail/MailModule.php')
-rw-r--r--app/frontend/mail/MailModule.php95
1 files changed, 95 insertions, 0 deletions
diff --git a/app/frontend/mail/MailModule.php b/app/frontend/mail/MailModule.php
new file mode 100644
index 0000000..5f7749b
--- /dev/null
+++ b/app/frontend/mail/MailModule.php
@@ -0,0 +1,95 @@
+<?php
+
+Prado::using('System.I18N.Globalization');
+Prado::using('Application.mail.MailTemplate');
+Prado::using('Application.mail.MailTemplateTranslator');
+
+class MailModule extends TModule {
+
+ private $_templatePath;
+ private static $_templateExtension = 'html';
+ private $_templateCacheSubpath = 'mail';
+ private static $_templateTranslationCatalogue = 'messages';
+
+ public function setTemplatePath($templatePath) {
+ $this->_templatePath = Prado::getPathOfNamespace(
+ TPropertyValue::ensureString($templatePath)
+ );
+ }
+
+ public function getTemplatePath() {
+ if (!file_exists($this->_templatePath)
+ || !is_dir($this->_templatePath)) {
+ throw new TConfigurationException(
+ Prado::localize(
+ 'Invalid mail template path'
+ )
+ );
+ }
+ return $this->_templatePath;
+ }
+
+ public function setCachePath($cachePath) {
+ $this->templateCacheSubpath = TPropertyValue::ensureString($cachePath);
+ }
+
+ public function getCachePath() {
+ $cachePath = $this->getApplication()->getRuntimePath()
+ . DIRECTORY_SEPARATOR
+ . $this->_templateCacheSubpath;
+ if (!file_exists($cachePath)) {
+ mkdir($cachePath);
+ } else {
+ if (!is_dir($cachePath)
+ || !is_writable($cachePath)) {
+ throw new TConfigurationException(
+ Prado::localize(
+ 'Template cache path must be a writable directory'
+ )
+ );
+ }
+ }
+ return $cachePath;
+ }
+
+ public function setTemplateExtension($ext) {
+ self::$_templateExtension = TPropertyValue::ensureString($ext);
+ }
+
+ public function getTemplateExtension() {
+ return self::$_templateExtension;
+ }
+
+ public function setTranslationCatalogue($ext) {
+ self::$_templateTranslationCatalogue = TPropertyValue::ensureString($ext);
+ }
+
+ public function getTranslationCatalogue() {
+ return self::$_templateTranslationCatalogue;
+ }
+
+ private static $_translator;
+
+ private static function _getTranslator() {
+ if (!isset(self::$_translator)) {
+ self::$_translator = new MailTemplateTranslator(
+ self::$_templateTranslationCatalogue
+ );
+ }
+ return self::$_translator;
+ }
+
+ public function getTemplate($template, $language=NULL) {
+ $template = new MailTemplate($template . '.' . $this->TemplateExtension);
+ $template->setOutputMode(PHPTAL::HTML5);
+ $template->setTemplateRepository($this->_templatePath);
+ $template->setPhpCodeDestination($this->CachePath);
+ $translator = self::_getTranslator();
+ $translator->setLanguage($language);
+ $template->setTranslator($translator);
+ return $template;
+ }
+
+}
+
+?>