Improve POST ticket
This commit is contained in:
parent
0a2d94e05b
commit
ef9cbf98b0
@ -3,6 +3,7 @@
|
|||||||
namespace BusinessLogic\Emails;
|
namespace BusinessLogic\Emails;
|
||||||
|
|
||||||
|
|
||||||
|
use BusinessLogic\Exceptions\ApiFriendlyException;
|
||||||
use BusinessLogic\Exceptions\EmailTemplateNotFoundException;
|
use BusinessLogic\Exceptions\EmailTemplateNotFoundException;
|
||||||
use BusinessLogic\Exceptions\InvalidEmailTemplateException;
|
use BusinessLogic\Exceptions\InvalidEmailTemplateException;
|
||||||
use BusinessLogic\Statuses\DefaultStatusForAction;
|
use BusinessLogic\Statuses\DefaultStatusForAction;
|
||||||
@ -63,9 +64,21 @@ class EmailTemplateParser {
|
|||||||
$htmlTemplate = self::getFromFileSystem($emailTemplate->fileName, $languageCode, true);
|
$htmlTemplate = self::getFromFileSystem($emailTemplate->fileName, $languageCode, true);
|
||||||
$subject = $hesklang[$emailTemplate->languageKey];
|
$subject = $hesklang[$emailTemplate->languageKey];
|
||||||
|
|
||||||
$subject = $this->parseSubject($subject, $ticket, $languageCode, $heskSettings);
|
$fullLanguageName = null;
|
||||||
$message = $this->parseMessage($template, $ticket, $languageCode, $emailTemplate->forStaff, $heskSettings, $modsForHeskSettings, false);
|
foreach ($heskSettings['languages'] as $key => $value) {
|
||||||
$htmlMessage = $this->parseMessage($htmlTemplate, $ticket, $languageCode, $emailTemplate->forStaff, $heskSettings, $modsForHeskSettings, true);
|
if ($value['folder'] === $languageCode) {
|
||||||
|
$fullLanguageName = $key;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($fullLanguageName === null) {
|
||||||
|
throw new \Exception("Language code {$languageCode} did not return any valid HESK languages!");
|
||||||
|
}
|
||||||
|
|
||||||
|
$subject = $this->parseSubject($subject, $ticket, $fullLanguageName, $heskSettings);
|
||||||
|
$message = $this->parseMessage($template, $ticket, $fullLanguageName, $emailTemplate->forStaff, $heskSettings, $modsForHeskSettings, false);
|
||||||
|
$htmlMessage = $this->parseMessage($htmlTemplate, $ticket, $fullLanguageName, $emailTemplate->forStaff, $heskSettings, $modsForHeskSettings, true);
|
||||||
|
|
||||||
return new ParsedEmailProperties($subject, $message, $htmlMessage);
|
return new ParsedEmailProperties($subject, $message, $htmlMessage);
|
||||||
}
|
}
|
||||||
@ -113,7 +126,7 @@ class EmailTemplateParser {
|
|||||||
|
|
||||||
// Status name and category name
|
// Status name and category name
|
||||||
$defaultStatus = $this->statusGateway->getStatusForDefaultAction(DefaultStatusForAction::NEW_TICKET, $heskSettings);
|
$defaultStatus = $this->statusGateway->getStatusForDefaultAction(DefaultStatusForAction::NEW_TICKET, $heskSettings);
|
||||||
$statusName = $defaultStatus->localizedNames[$language]->text;
|
$statusName = $defaultStatus->localizedNames[$language];
|
||||||
$category = $this->categoryGateway->getAllCategories($heskSettings)[$ticket->categoryId];
|
$category = $this->categoryGateway->getAllCategories($heskSettings)[$ticket->categoryId];
|
||||||
|
|
||||||
switch ($ticket->priorityId) {
|
switch ($ticket->priorityId) {
|
||||||
@ -175,7 +188,7 @@ class EmailTemplateParser {
|
|||||||
|
|
||||||
// Status name and category name
|
// Status name and category name
|
||||||
$defaultStatus = $this->statusGateway->getStatusForDefaultAction(DefaultStatusForAction::NEW_TICKET, $heskSettings);
|
$defaultStatus = $this->statusGateway->getStatusForDefaultAction(DefaultStatusForAction::NEW_TICKET, $heskSettings);
|
||||||
$statusName = hesk_msgToPlain($defaultStatus->localizedNames[$language]->text);
|
$statusName = hesk_msgToPlain($defaultStatus->localizedNames[$language]);
|
||||||
$category = hesk_msgToPlain($this->categoryGateway->getAllCategories($heskSettings)[$ticket->categoryId]->name);
|
$category = hesk_msgToPlain($this->categoryGateway->getAllCategories($heskSettings)[$ticket->categoryId]->name);
|
||||||
$owner = hesk_msgToPlain($this->userGateway->getUserById($ticket->ownerId, $heskSettings)->name);
|
$owner = hesk_msgToPlain($this->userGateway->getUserById($ticket->ownerId, $heskSettings)->name);
|
||||||
|
|
||||||
@ -217,7 +230,7 @@ class EmailTemplateParser {
|
|||||||
for ($i=1; $i<=50; $i++) {
|
for ($i=1; $i<=50; $i++) {
|
||||||
$k = 'custom'.$i;
|
$k = 'custom'.$i;
|
||||||
|
|
||||||
if (isset($heskSettings['custom_fields'][$k])) {
|
if (isset($heskSettings['custom_fields'][$k]) && isset($ticket->customFields[$i])) {
|
||||||
$v = $heskSettings['custom_fields'][$k];
|
$v = $heskSettings['custom_fields'][$k];
|
||||||
|
|
||||||
switch ($v['type']) {
|
switch ($v['type']) {
|
||||||
|
@ -66,7 +66,7 @@ class Status {
|
|||||||
public $sort;
|
public $sort;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var $name StatusLanguage[]
|
* @var $name string[]
|
||||||
*/
|
*/
|
||||||
public $localizedNames;
|
public $localizedNames;
|
||||||
}
|
}
|
@ -24,7 +24,13 @@ class Ticket {
|
|||||||
$ticket->closedDate = $row['closedat'];
|
$ticket->closedDate = $row['closedat'];
|
||||||
|
|
||||||
if (trim($row['articles']) !== '') {
|
if (trim($row['articles']) !== '') {
|
||||||
$ticket->suggestedArticles = explode(',', $row['articles']);
|
$suggestedArticles = explode(',', $row['articles']);
|
||||||
|
|
||||||
|
$articlesAsInts = array();
|
||||||
|
foreach ($suggestedArticles as $article) {
|
||||||
|
$articlesAsInts[] = intval($article);
|
||||||
|
}
|
||||||
|
$ticket->suggestedArticles = $articlesAsInts;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ticket->ipAddress = $row['ip'];
|
$ticket->ipAddress = $row['ip'];
|
||||||
@ -202,7 +208,7 @@ class Ticket {
|
|||||||
public $closedDate;
|
public $closedDate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string[]
|
* @var int[]
|
||||||
*/
|
*/
|
||||||
public $suggestedArticles = array();
|
public $suggestedArticles = array();
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ class TicketCreator {
|
|||||||
|
|
||||||
if ($ticketRequest->sendEmailToCustomer && $emailVerified) {
|
if ($ticketRequest->sendEmailToCustomer && $emailVerified) {
|
||||||
$this->emailSenderHelper->sendEmailForTicket(EmailTemplateRetriever::NEW_TICKET, $ticketRequest->language, $addressees, $ticket, $heskSettings, $modsForHeskSettings);
|
$this->emailSenderHelper->sendEmailForTicket(EmailTemplateRetriever::NEW_TICKET, $ticketRequest->language, $addressees, $ticket, $heskSettings, $modsForHeskSettings);
|
||||||
} else if ($modsForHeskSettings[''] && !$emailVerified) {
|
} else if ($modsForHeskSettings['customer_email_verification_required'] && !$emailVerified) {
|
||||||
$this->emailSenderHelper->sendEmailForTicket(EmailTemplateRetriever::VERIFY_EMAIL, $ticketRequest->language, $addressees, $ticket, $heskSettings, $modsForHeskSettings);
|
$this->emailSenderHelper->sendEmailForTicket(EmailTemplateRetriever::VERIFY_EMAIL, $ticketRequest->language, $addressees, $ticket, $heskSettings, $modsForHeskSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ class TicketRetriever {
|
|||||||
function getTicketById($id, $heskSettings, $userContext) {
|
function getTicketById($id, $heskSettings, $userContext) {
|
||||||
$ticket = $this->ticketGateway->getTicketById($id, $heskSettings);
|
$ticket = $this->ticketGateway->getTicketById($id, $heskSettings);
|
||||||
|
|
||||||
if ($ticket !== null) {
|
if ($ticket === null) {
|
||||||
throw new ApiFriendlyException("Ticket {$id} not found!", "Ticket Not Found", 404);
|
throw new ApiFriendlyException("Ticket {$id} not found!", "Ticket Not Found", 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,9 +36,9 @@ class TrackingIdGenerator {
|
|||||||
$trackingId = $this->formatTrackingId($trackingId);
|
$trackingId = $this->formatTrackingId($trackingId);
|
||||||
|
|
||||||
/* Check for duplicate IDs */
|
/* Check for duplicate IDs */
|
||||||
$ticket = $this->ticketGateway->getTicketByTrackingId($trackingId, $heskSettings);
|
$goodId = !$this->ticketGateway->doesTicketExist($trackingId, $heskSettings);
|
||||||
|
|
||||||
if ($ticket === null) {
|
if ($goodId) {
|
||||||
return $trackingId;
|
return $trackingId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,9 +57,9 @@ class TrackingIdGenerator {
|
|||||||
/* Format the ID to the correct shape and check wording */
|
/* Format the ID to the correct shape and check wording */
|
||||||
$trackingId = $this->formatTrackingId($trackingId);
|
$trackingId = $this->formatTrackingId($trackingId);
|
||||||
|
|
||||||
$ticket = $this->ticketGateway->getTicketByTrackingId($trackingId, $heskSettings);
|
$goodId = !$this->ticketGateway->doesTicketExist($trackingId, $heskSettings);
|
||||||
|
|
||||||
if ($ticket === null) {
|
if ($goodId) {
|
||||||
return $trackingId;
|
return $trackingId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ class CustomerTicketController {
|
|||||||
$ticketRequest->screenResolution = Helpers::safeArrayGet($json, 'screenResolution');
|
$ticketRequest->screenResolution = Helpers::safeArrayGet($json, 'screenResolution');
|
||||||
$ticketRequest->ipAddress = Helpers::safeArrayGet($json, 'ip');
|
$ticketRequest->ipAddress = Helpers::safeArrayGet($json, 'ip');
|
||||||
$ticketRequest->language = Helpers::safeArrayGet($json, 'language');
|
$ticketRequest->language = Helpers::safeArrayGet($json, 'language');
|
||||||
$ticketRequest->sendEmailToCustomer = Helpers::safeArrayGet($json, 'sendEmailToCustomer');
|
$ticketRequest->sendEmailToCustomer = true;
|
||||||
$ticketRequest->customFields = array();
|
$ticketRequest->customFields = array();
|
||||||
|
|
||||||
$jsonCustomFields = Helpers::safeArrayGet($json, 'customFields');
|
$jsonCustomFields = Helpers::safeArrayGet($json, 'customFields');
|
||||||
|
@ -66,6 +66,24 @@ class TicketGateway extends CommonDao {
|
|||||||
return $tickets;
|
return $tickets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $trackingId string
|
||||||
|
* @param $heskSettings array
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function doesTicketExist($trackingId, $heskSettings) {
|
||||||
|
$this->init();
|
||||||
|
|
||||||
|
$rs = hesk_dbQuery("SELECT 1 FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets`
|
||||||
|
WHERE `trackid` = '" . hesk_dbEscape($trackingId) . "'");
|
||||||
|
|
||||||
|
$ticketExists = hesk_dbNumRows($rs) > 0;
|
||||||
|
|
||||||
|
$this->close();
|
||||||
|
|
||||||
|
return $ticketExists;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $trackingId string
|
* @param $trackingId string
|
||||||
* @param $heskSettings array
|
* @param $heskSettings array
|
||||||
|
@ -150,7 +150,6 @@ Link::all(array(
|
|||||||
'/v1/categories' => \Controllers\Categories\CategoryController::class . '::printAllCategories',
|
'/v1/categories' => \Controllers\Categories\CategoryController::class . '::printAllCategories',
|
||||||
'/v1/categories/{i}' => \Controllers\Categories\CategoryController::class,
|
'/v1/categories/{i}' => \Controllers\Categories\CategoryController::class,
|
||||||
// Tickets
|
// Tickets
|
||||||
'/v1/tickets/{i}' => \Controllers\Tickets\CustomerTicketController::class,
|
|
||||||
'/v1/tickets' => \Controllers\Tickets\CustomerTicketController::class,
|
'/v1/tickets' => \Controllers\Tickets\CustomerTicketController::class,
|
||||||
// Tickets - Staff
|
// Tickets - Staff
|
||||||
'/v1/staff/tickets/{i}' => \Controllers\Tickets\StaffTicketController::class,
|
'/v1/staff/tickets/{i}' => \Controllers\Tickets\StaffTicketController::class,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user