opensupports/server/models/MailTemplate.php

49 lines
1.4 KiB
PHP
Raw Normal View History

2016-07-15 00:06:47 +02:00
<?php
use RedBeanPHP\Facade as RedBean;
2016-07-15 00:06:47 +02:00
class MailTemplate extends DataStore {
const TABLE = 'mailtemplate';
const USER_SIGNUP = 'USER_SIGNUP';
const USER_PASSWORD = 'USER_PASSWORD';
const PASSWORD_FORGOT = 'PASSWORD_FORGOT';
const PASSWORD_RECOVERED = 'PASSWORD_RECOVERED';
2016-07-15 00:06:47 +02:00
public static function getTemplate($type) {
$globalLanguage = Setting::getSetting('language')->value;
$bean = RedBean::findOne(MailTemplate::TABLE, 'type = :type AND language = :language', array(
':type' => $type,
2016-07-27 06:04:29 +02:00
':language' => $globalLanguage
));
2016-07-15 00:06:47 +02:00
return ($bean) ? new MailTemplate($bean) : new NullDataStore();
2016-07-15 00:06:47 +02:00
}
public static function getProps() {
return [
'type',
'subject',
'language',
2016-07-15 00:06:47 +02:00
'body'
];
}
public function compile($config) {
return [
'body' => $this->compileString($this->body, $config),
'subject' => $this->compileString($this->subject, $config),
'to' => $config['to']
];
}
public function compileString($string, $config) {
$compiledString = $string;
foreach ($config as $configName => $configValue) {
$compiledString = str_replace("{{{$configName}}}", $configValue, $compiledString);
}
return $compiledString;
}
}