Little progress, but still something
parent
b53e9aafd7
commit
9b2aa355b9
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: mkoch
|
||||
* Date: 2/22/2017
|
||||
* Time: 9:11 PM
|
||||
*/
|
||||
|
||||
namespace BusinessLogic\Emails;
|
||||
|
||||
|
||||
use BusinessLogic\Exceptions\EmailTemplateNotFoundException;
|
||||
use BusinessLogic\Exceptions\InvalidEmailTemplateException;
|
||||
use BusinessLogic\Tickets\Ticket;
|
||||
use DataAccess\Statuses\StatusGateway;
|
||||
|
||||
class EmailTemplateParser {
|
||||
|
||||
/**
|
||||
* @var $statusGateway StatusGateway
|
||||
*/
|
||||
private $statusGateway;
|
||||
|
||||
function __construct($statusGateway) {
|
||||
$this->statusGateway = $statusGateway;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $templateName string
|
||||
* @param $language string
|
||||
* @param $ticket Ticket
|
||||
*/
|
||||
function getFormattedEmailForLanguage($templateName, $language, $ticket) {
|
||||
global $hesklang;
|
||||
|
||||
$template = self::getFromFileSystem($templateName, $language);
|
||||
$subject = ValidEmailTemplates::getValidEmailTemplates()[$templateName];
|
||||
|
||||
$subject = self::parseSubject($subject, $ticket);
|
||||
}
|
||||
|
||||
private function getFromFileSystem($template, $language)
|
||||
{
|
||||
if (!isset(ValidEmailTemplates::getValidEmailTemplates()[$template])) {
|
||||
throw new InvalidEmailTemplateException($template);
|
||||
}
|
||||
|
||||
/* Get email template */
|
||||
$file = 'language/' . $language . '/emails/' . $template . '.txt';
|
||||
$absoluteFilePath = __DIR__ . '/../../../' . $file;
|
||||
|
||||
if (file_exists($absoluteFilePath)) {
|
||||
return file_get_contents($absoluteFilePath);
|
||||
} else {
|
||||
throw new EmailTemplateNotFoundException($template, $language);
|
||||
}
|
||||
}
|
||||
|
||||
private static function parseSubject($subjectTemplate, $ticket) {
|
||||
if ($ticket === null) {
|
||||
return $subjectTemplate;
|
||||
}
|
||||
|
||||
//--
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: mkoch
|
||||
* Date: 2/22/2017
|
||||
* Time: 9:11 PM
|
||||
*/
|
||||
|
||||
namespace BusinessLogic\Emails;
|
||||
|
||||
|
||||
use BusinessLogic\Exceptions\EmailTemplateNotFoundException;
|
||||
|
||||
class EmailTemplateRetriever {
|
||||
|
||||
function getTemplateForLanguage($templateName, $language) {
|
||||
|
||||
}
|
||||
|
||||
private function getFromFileSystem($template, $language)
|
||||
{
|
||||
global $hesk_settings, $hesklang;
|
||||
|
||||
// Demo mode
|
||||
if (defined('HESK_DEMO')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
/* Get list of valid emails */
|
||||
$valid_emails = hesk_validEmails();
|
||||
|
||||
/* Verify this is a valid email include */
|
||||
|
||||
if (!isset(ValidEmailTemplates::getValidEmailTemplates()[$template])) {
|
||||
hesk_error($hesklang['inve']);
|
||||
}
|
||||
|
||||
/* Get email template */
|
||||
$file = 'language/' . $language . '/emails/' . $template . '.txt';
|
||||
$absoluteFilePath = __DIR__ . '/../../../' . $file;
|
||||
|
||||
if (file_exists($absoluteFilePath)) {
|
||||
return file_get_contents($absoluteFilePath);
|
||||
} else {
|
||||
throw new EmailTemplateNotFoundException($template, $language);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: mkoch
|
||||
* Date: 2/23/2017
|
||||
* Time: 8:13 PM
|
||||
*/
|
||||
|
||||
namespace BusinessLogic\Exceptions;
|
||||
|
||||
|
||||
class InvalidEmailTemplateException extends ApiFriendlyException {
|
||||
function __construct($template) {
|
||||
parent::__construct(sprintf("The email template '%s' is invalid", $template), 'Invalid Email Template', 400);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue