2016-07-15 00:06:47 +02:00
|
|
|
<?php
|
2016-07-26 23:30:51 +02:00
|
|
|
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';
|
2016-08-16 01:15:09 +02:00
|
|
|
const PASSWORD_FORGOT = 'PASSWORD_FORGOT';
|
2017-01-16 20:07:53 +01:00
|
|
|
const USER_SYSTEM_DISABLED = 'USER_SYSTEM_DISABLED';
|
|
|
|
const USER_SYSTEM_ENABLED = 'USER_SYSTEM_ENABLED';
|
2017-03-17 00:00:21 +01:00
|
|
|
const TICKET_CREATED = 'TICKET_CREATED';
|
|
|
|
const TICKET_RESPONDED = 'TICKET_RESPONDED';
|
|
|
|
const TICKET_CLOSED = 'TICKET_CLOSED';
|
|
|
|
|
2016-07-15 00:06:47 +02:00
|
|
|
public static function getTemplate($type) {
|
2016-07-27 18:58:19 +02:00
|
|
|
$globalLanguage = Setting::getSetting('language')->value;
|
2016-07-26 23:30:51 +02:00
|
|
|
|
|
|
|
$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-26 23:30:51 +02:00
|
|
|
));
|
2016-07-15 00:06:47 +02:00
|
|
|
|
2016-07-27 18:58:19 +02:00
|
|
|
return ($bean) ? new MailTemplate($bean) : new NullDataStore();
|
2016-07-15 00:06:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function getProps() {
|
|
|
|
return [
|
|
|
|
'type',
|
|
|
|
'subject',
|
2016-07-27 05:44:07 +02:00
|
|
|
'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;
|
|
|
|
}
|
2017-01-03 23:36:26 +01:00
|
|
|
public function toArray() {
|
|
|
|
return [
|
|
|
|
'type' => $this->type,
|
|
|
|
'subject' => $this->subject,
|
|
|
|
'language' => $this->language,
|
|
|
|
'body' => $this->body,
|
|
|
|
];
|
|
|
|
}
|
2016-07-15 00:06:47 +02:00
|
|
|
}
|