Changes
This commit is contained in:
parent
9b2aa355b9
commit
0ceaafc0ec
@ -11,7 +11,10 @@ namespace BusinessLogic\Emails;
|
||||
|
||||
use BusinessLogic\Exceptions\EmailTemplateNotFoundException;
|
||||
use BusinessLogic\Exceptions\InvalidEmailTemplateException;
|
||||
use BusinessLogic\Statuses\DefaultStatusForAction;
|
||||
use BusinessLogic\Tickets\Ticket;
|
||||
use Core\Constants\Priority;
|
||||
use DataAccess\Categories\CategoryGateway;
|
||||
use DataAccess\Statuses\StatusGateway;
|
||||
|
||||
class EmailTemplateParser {
|
||||
@ -21,8 +24,14 @@ class EmailTemplateParser {
|
||||
*/
|
||||
private $statusGateway;
|
||||
|
||||
function __construct($statusGateway) {
|
||||
/**
|
||||
* @var $categoryGateway CategoryGateway
|
||||
*/
|
||||
private $categoryGateway;
|
||||
|
||||
function __construct($statusGateway, $categoryGateway) {
|
||||
$this->statusGateway = $statusGateway;
|
||||
$this->categoryGateway = $categoryGateway;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -30,13 +39,13 @@ class EmailTemplateParser {
|
||||
* @param $language string
|
||||
* @param $ticket Ticket
|
||||
*/
|
||||
function getFormattedEmailForLanguage($templateName, $language, $ticket) {
|
||||
function getFormattedEmailForLanguage($templateName, $language, $ticket, $heskSettings) {
|
||||
global $hesklang;
|
||||
|
||||
$template = self::getFromFileSystem($templateName, $language);
|
||||
$subject = ValidEmailTemplates::getValidEmailTemplates()[$templateName];
|
||||
|
||||
$subject = self::parseSubject($subject, $ticket);
|
||||
$subject = $this->parseSubject($subject, $ticket, $language, $heskSettings);
|
||||
}
|
||||
|
||||
private function getFromFileSystem($template, $language)
|
||||
@ -56,11 +65,49 @@ class EmailTemplateParser {
|
||||
}
|
||||
}
|
||||
|
||||
private static function parseSubject($subjectTemplate, $ticket) {
|
||||
/**
|
||||
* @param $subjectTemplate string
|
||||
* @param $ticket Ticket
|
||||
* @param $language string
|
||||
* @param $heskSettings array
|
||||
* @return string
|
||||
*/
|
||||
private function parseSubject($subjectTemplate, $ticket, $language, $heskSettings) {
|
||||
global $hesklang;
|
||||
|
||||
if ($ticket === null) {
|
||||
return $subjectTemplate;
|
||||
}
|
||||
|
||||
//--
|
||||
// Status name and category name
|
||||
$defaultStatus = $this->statusGateway->getStatusForDefaultAction(DefaultStatusForAction::NEW_TICKET, $heskSettings);
|
||||
$statusName = $defaultStatus->localizedNames[$language]->text;
|
||||
$category = $this->categoryGateway->getAllCategories($heskSettings)[$ticket->categoryId];
|
||||
|
||||
$priority = '';
|
||||
switch ($ticket->priorityId) {
|
||||
case Priority::CRITICAL:
|
||||
$priority = $hesklang['critical'];
|
||||
break;
|
||||
case Priority::HIGH:
|
||||
$priority = $hesklang['high'];
|
||||
break;
|
||||
case Priority::MEDIUM:
|
||||
$priority = $hesklang['medium'];
|
||||
break;
|
||||
case Priority::LOW:
|
||||
$priority = $hesklang['low'];
|
||||
break;
|
||||
default:
|
||||
$priority = 'PRIORITY NOT FOUND';
|
||||
break;
|
||||
}
|
||||
|
||||
// Special tags
|
||||
$msg = str_replace('%%SUBJECT%%', $ticket->subject, $subjectTemplate);
|
||||
$msg = str_replace('%%TRACK_ID%%', $ticket->trackingId, $msg);
|
||||
$msg = str_replace('%%CATEGORY%%', $category->id, $msg);
|
||||
$msg = str_replace('%%PRIORITY%%', $priority, $msg);
|
||||
$msg = str_replace('%%STATUS%%', $statusName, $msg);
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@ class Status {
|
||||
|
||||
$localizedLanguages = array();
|
||||
while ($languageRow = hesk_dbFetchAssoc($languageRs)) {
|
||||
$localizedLanguages[] = new StatusLanguage($languageRow['language'], $languageRow['text']);
|
||||
$localizedLanguages[$languageRow['language']] = new StatusLanguage($languageRow['language'], $languageRow['text']);
|
||||
}
|
||||
$status->localizedNames = $localizedLanguages;
|
||||
$status->sort = $row['sort'];
|
||||
|
Loading…
x
Reference in New Issue
Block a user