2016-07-15 00:06:47 +02:00
|
|
|
<?php
|
2016-07-26 23:30:51 +02:00
|
|
|
use RedBeanPHP\Facade as RedBean;
|
|
|
|
|
2017-04-21 05:34:20 +02:00
|
|
|
/**
|
|
|
|
* @api {OBJECT} MailTemplate MailTemplate
|
2018-09-20 22:19:47 +02:00
|
|
|
* @apiVersion 4.3.0
|
2017-04-21 05:34:20 +02:00
|
|
|
* @apiGroup Data Structures
|
|
|
|
* @apiParam {String} type The type of the mail template.
|
|
|
|
* @apiParam {String} subject The subject of the mail template.
|
|
|
|
* @apiParam {string} language The language of the mail template.
|
|
|
|
* @apiParam {String} body The body of the mail template.
|
|
|
|
*/
|
|
|
|
|
2016-07-15 00:06:47 +02:00
|
|
|
class MailTemplate extends DataStore {
|
|
|
|
const TABLE = 'mailtemplate';
|
2018-05-09 00:55:58 +02:00
|
|
|
|
2016-07-15 00:06:47 +02:00
|
|
|
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';
|
2017-06-10 08:27:22 +02:00
|
|
|
const TICKET_CREATED_STAFF = 'TICKET_CREATED_STAFF';
|
2017-03-17 00:00:21 +01:00
|
|
|
|
2018-11-14 16:28:01 +01:00
|
|
|
public static function getFilePaths() {
|
|
|
|
return [
|
|
|
|
'USER_SIGNUP' => 'data/mail-templates/user-signup.html',
|
|
|
|
'USER_PASSWORD' => 'data/mail-templates/user-edit-password.html',
|
|
|
|
'USER_EMAIL' => 'data/mail-templates/user-edit-email.html',
|
|
|
|
'PASSWORD_FORGOT' => 'data/mail-templates/user-password-forgot.html',
|
|
|
|
'USER_SYSTEM_DISABLED' => 'data/mail-templates/user-system-disabled.html',
|
|
|
|
'USER_SYSTEM_ENABLED' => 'data/mail-templates/user-system-enabled.html',
|
|
|
|
'TICKET_CREATED' => 'data/mail-templates/ticket-created.html',
|
|
|
|
'TICKET_RESPONDED' => 'data/mail-templates/ticket-responded.html',
|
|
|
|
'TICKET_CLOSED' => 'data/mail-templates/ticket-closed.html',
|
|
|
|
'TICKET_CREATED_STAFF' => 'data/mail-templates/ticket-created-staff.html',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getMailTemplate($template) {
|
2016-07-27 18:58:19 +02:00
|
|
|
$globalLanguage = Setting::getSetting('language')->value;
|
2018-05-09 00:55:58 +02:00
|
|
|
|
2018-11-14 16:28:01 +01:00
|
|
|
$bean = RedBean::findOne(MailTemplate::TABLE, 'template = :template AND language = :language', array(
|
|
|
|
':template' => $template,
|
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
|
|
|
}
|
2018-05-09 00:55:58 +02:00
|
|
|
|
2016-07-15 00:06:47 +02:00
|
|
|
public static function getProps() {
|
|
|
|
return [
|
2018-11-14 16:28:01 +01:00
|
|
|
'template',
|
2016-07-15 00:06:47 +02:00
|
|
|
'subject',
|
2016-07-27 05:44:07 +02:00
|
|
|
'language',
|
2018-11-14 16:28:01 +01:00
|
|
|
'text1',
|
|
|
|
'text2',
|
|
|
|
'text3',
|
2016-07-15 00:06:47 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2018-11-14 16:28:01 +01:00
|
|
|
public function getSubject($config) {
|
|
|
|
return $this->compileString($this->subject, $config);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBody($config) {
|
|
|
|
$templateFilePaths = MailTemplate::getFilePaths();
|
|
|
|
$texts = [
|
|
|
|
$this->text1, $this->text2, $this->text3, $this->text4,
|
|
|
|
];
|
|
|
|
|
|
|
|
$matches = [];
|
|
|
|
foreach($texts as $key => $val) {
|
|
|
|
$matches[] = '{{' . $this->template . '_MATCH_' . ($key + 1) . '}}';
|
|
|
|
}
|
|
|
|
|
|
|
|
$body = str_replace($matches, $texts, file_get_contents($templateFilePaths[$this->template]));
|
|
|
|
|
|
|
|
return $this->compileString($body, $config);
|
2016-07-15 00:06:47 +02:00
|
|
|
}
|
2018-05-09 00:55:58 +02:00
|
|
|
|
2016-07-15 00:06:47 +02:00
|
|
|
public function compileString($string, $config) {
|
|
|
|
$compiledString = $string;
|
|
|
|
|
|
|
|
foreach ($config as $configName => $configValue) {
|
|
|
|
$compiledString = str_replace("{{{$configName}}}", $configValue, $compiledString);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $compiledString;
|
|
|
|
}
|
2018-11-14 16:28:01 +01:00
|
|
|
|
2017-01-03 23:36:26 +01:00
|
|
|
public function toArray() {
|
|
|
|
return [
|
2018-11-14 16:28:01 +01:00
|
|
|
'template' => $this->template,
|
2017-01-03 23:36:26 +01:00
|
|
|
'subject' => $this->subject,
|
|
|
|
'language' => $this->language,
|
2018-11-14 16:28:01 +01:00
|
|
|
'text1' => $this->text1,
|
|
|
|
'text2' => $this->text2,
|
|
|
|
'text3' => $this->text3,
|
2017-01-03 23:36:26 +01:00
|
|
|
];
|
|
|
|
}
|
2018-05-09 00:55:58 +02:00
|
|
|
}
|