Starting to work on reply API endpoint
This commit is contained in:
parent
d97fe5a81c
commit
669edf832c
@ -34,4 +34,47 @@ class Helpers extends \BaseClass {
|
|||||||
static function heskHtmlSpecialCharsDecode($in) {
|
static function heskHtmlSpecialCharsDecode($in) {
|
||||||
return str_replace(array('&', '<', '>', '"'), array('&', '<', '>', '"'), $in);
|
return str_replace(array('&', '<', '>', '"'), array('&', '<', '>', '"'), $in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function heskMakeUrl($text, $class = '', $shortenLinks = true) {
|
||||||
|
if (!defined('MAGIC_URL_EMAIL')) {
|
||||||
|
define('MAGIC_URL_EMAIL', 1);
|
||||||
|
define('MAGIC_URL_FULL', 2);
|
||||||
|
define('MAGIC_URL_LOCAL', 3);
|
||||||
|
define('MAGIC_URL_WWW', 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
$class = ($class) ? ' class="' . $class . '"' : '';
|
||||||
|
|
||||||
|
// matches a xxxx://aaaaa.bbb.cccc. ...
|
||||||
|
$text = preg_replace_callback(
|
||||||
|
'#(^|[\n\t (>.])(' . "[a-z][a-z\d+]*:/{2}(?:(?:[^\p{C}\p{Z}\p{S}\p{P}\p{Nl}\p{No}\p{Me}\x{1100}-\x{115F}\x{A960}-\x{A97C}\x{1160}-\x{11A7}\x{D7B0}-\x{D7C6}\x{20D0}-\x{20FF}\x{1D100}-\x{1D1FF}\x{1D200}-\x{1D24F}\x{0640}\x{07FA}\x{302E}\x{302F}\x{3031}-\x{3035}\x{303B}]*[\x{00B7}\x{0375}\x{05F3}\x{05F4}\x{30FB}\x{002D}\x{06FD}\x{06FE}\x{0F0B}\x{3007}\x{00DF}\x{03C2}\x{200C}\x{200D}\pL0-9\-._~!$&'(*+,;=:@|]+|%[\dA-F]{2})+|[0-9.]+|\[[a-z0-9.]+:[a-z0-9.]+:[a-z0-9.:]+\])(?::\d*)?(?:/(?:[^\p{C}\p{Z}\p{S}\p{P}\p{Nl}\p{No}\p{Me}\x{1100}-\x{115F}\x{A960}-\x{A97C}\x{1160}-\x{11A7}\x{D7B0}-\x{D7C6}\x{20D0}-\x{20FF}\x{1D100}-\x{1D1FF}\x{1D200}-\x{1D24F}\x{0640}\x{07FA}\x{302E}\x{302F}\x{3031}-\x{3035}\x{303B}]*[\x{00B7}\x{0375}\x{05F3}\x{05F4}\x{30FB}\x{002D}\x{06FD}\x{06FE}\x{0F0B}\x{3007}\x{00DF}\x{03C2}\x{200C}\x{200D}\pL0-9\-._~!$&'(*+,;=:@|]+|%[\dA-F]{2})*)*(?:\?(?:[^\p{C}\p{Z}\p{S}\p{P}\p{Nl}\p{No}\p{Me}\x{1100}-\x{115F}\x{A960}-\x{A97C}\x{1160}-\x{11A7}\x{D7B0}-\x{D7C6}\x{20D0}-\x{20FF}\x{1D100}-\x{1D1FF}\x{1D200}-\x{1D24F}\x{0640}\x{07FA}\x{302E}\x{302F}\x{3031}-\x{3035}\x{303B}]*[\x{00B7}\x{0375}\x{05F3}\x{05F4}\x{30FB}\x{002D}\x{06FD}\x{06FE}\x{0F0B}\x{3007}\x{00DF}\x{03C2}\x{200C}\x{200D}\pL0-9\-._~!$&'(*+,;=:@/?|]+|%[\dA-F]{2})*)?(?:\#(?:[^\p{C}\p{Z}\p{S}\p{P}\p{Nl}\p{No}\p{Me}\x{1100}-\x{115F}\x{A960}-\x{A97C}\x{1160}-\x{11A7}\x{D7B0}-\x{D7C6}\x{20D0}-\x{20FF}\x{1D100}-\x{1D1FF}\x{1D200}-\x{1D24F}\x{0640}\x{07FA}\x{302E}\x{302F}\x{3031}-\x{3035}\x{303B}]*[\x{00B7}\x{0375}\x{05F3}\x{05F4}\x{30FB}\x{002D}\x{06FD}\x{06FE}\x{0F0B}\x{3007}\x{00DF}\x{03C2}\x{200C}\x{200D}\pL0-9\-._~!$&'(*+,;=:@/?|]+|%[\dA-F]{2})*)?" . ')#iu',
|
||||||
|
create_function(
|
||||||
|
"\$matches",
|
||||||
|
"return make_clickable_callback(MAGIC_URL_FULL, \$matches[1], \$matches[2], '', '$class', '$shortenLinks');"
|
||||||
|
),
|
||||||
|
$text
|
||||||
|
);
|
||||||
|
|
||||||
|
// matches a "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing
|
||||||
|
$text = preg_replace_callback(
|
||||||
|
'#(^|[\n\t (>])(' . "www\.(?:[^\p{C}\p{Z}\p{S}\p{P}\p{Nl}\p{No}\p{Me}\x{1100}-\x{115F}\x{A960}-\x{A97C}\x{1160}-\x{11A7}\x{D7B0}-\x{D7C6}\x{20D0}-\x{20FF}\x{1D100}-\x{1D1FF}\x{1D200}-\x{1D24F}\x{0640}\x{07FA}\x{302E}\x{302F}\x{3031}-\x{3035}\x{303B}]*[\x{00B7}\x{0375}\x{05F3}\x{05F4}\x{30FB}\x{002D}\x{06FD}\x{06FE}\x{0F0B}\x{3007}\x{00DF}\x{03C2}\x{200C}\x{200D}\pL0-9\-._~!$&'(*+,;=:@|]+|%[\dA-F]{2})+(?::\d*)?(?:/(?:[^\p{C}\p{Z}\p{S}\p{P}\p{Nl}\p{No}\p{Me}\x{1100}-\x{115F}\x{A960}-\x{A97C}\x{1160}-\x{11A7}\x{D7B0}-\x{D7C6}\x{20D0}-\x{20FF}\x{1D100}-\x{1D1FF}\x{1D200}-\x{1D24F}\x{0640}\x{07FA}\x{302E}\x{302F}\x{3031}-\x{3035}\x{303B}]*[\x{00B7}\x{0375}\x{05F3}\x{05F4}\x{30FB}\x{002D}\x{06FD}\x{06FE}\x{0F0B}\x{3007}\x{00DF}\x{03C2}\x{200C}\x{200D}\pL0-9\-._~!$&'(*+,;=:@|]+|%[\dA-F]{2})*)*(?:\?(?:[^\p{C}\p{Z}\p{S}\p{P}\p{Nl}\p{No}\p{Me}\x{1100}-\x{115F}\x{A960}-\x{A97C}\x{1160}-\x{11A7}\x{D7B0}-\x{D7C6}\x{20D0}-\x{20FF}\x{1D100}-\x{1D1FF}\x{1D200}-\x{1D24F}\x{0640}\x{07FA}\x{302E}\x{302F}\x{3031}-\x{3035}\x{303B}]*[\x{00B7}\x{0375}\x{05F3}\x{05F4}\x{30FB}\x{002D}\x{06FD}\x{06FE}\x{0F0B}\x{3007}\x{00DF}\x{03C2}\x{200C}\x{200D}\pL0-9\-._~!$&'(*+,;=:@/?|]+|%[\dA-F]{2})*)?(?:\#(?:[^\p{C}\p{Z}\p{S}\p{P}\p{Nl}\p{No}\p{Me}\x{1100}-\x{115F}\x{A960}-\x{A97C}\x{1160}-\x{11A7}\x{D7B0}-\x{D7C6}\x{20D0}-\x{20FF}\x{1D100}-\x{1D1FF}\x{1D200}-\x{1D24F}\x{0640}\x{07FA}\x{302E}\x{302F}\x{3031}-\x{3035}\x{303B}]*[\x{00B7}\x{0375}\x{05F3}\x{05F4}\x{30FB}\x{002D}\x{06FD}\x{06FE}\x{0F0B}\x{3007}\x{00DF}\x{03C2}\x{200C}\x{200D}\pL0-9\-._~!$&'(*+,;=:@/?|]+|%[\dA-F]{2})*)?" . ')#iu',
|
||||||
|
create_function(
|
||||||
|
"\$matches",
|
||||||
|
"return make_clickable_callback(MAGIC_URL_WWW, \$matches[1], \$matches[2], '', '$class', '$shortenLinks');"
|
||||||
|
),
|
||||||
|
$text
|
||||||
|
);
|
||||||
|
|
||||||
|
// matches an email address
|
||||||
|
$text = preg_replace_callback(
|
||||||
|
'/(^|[\n\t (>])(' . '((?:[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*(?:[\w\!\#$\%\'\*\+\-\/\=\?\^\`{\|\}\~]|&)+)@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,63})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)' . ')/iu',
|
||||||
|
create_function(
|
||||||
|
"\$matches",
|
||||||
|
"return make_clickable_callback(MAGIC_URL_EMAIL, \$matches[1], \$matches[2], '', '$class', '$shortenLinks');"
|
||||||
|
),
|
||||||
|
$text
|
||||||
|
);
|
||||||
|
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
}
|
}
|
12
api/BusinessLogic/Tickets/CreateReplyRequest.php
Normal file
12
api/BusinessLogic/Tickets/CreateReplyRequest.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BusinessLogic\Tickets;
|
||||||
|
|
||||||
|
|
||||||
|
class CreateReplyRequest {
|
||||||
|
public $trackingId;
|
||||||
|
public $emailAddress;
|
||||||
|
public $replyMessage;
|
||||||
|
public $hasHtml;
|
||||||
|
public $ipAddress;
|
||||||
|
}
|
60
api/BusinessLogic/Tickets/ReplyCreator.php
Normal file
60
api/BusinessLogic/Tickets/ReplyCreator.php
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BusinessLogic\Tickets;
|
||||||
|
|
||||||
|
|
||||||
|
use BusinessLogic\Emails\EmailSenderHelper;
|
||||||
|
use BusinessLogic\Exceptions\ApiFriendlyException;
|
||||||
|
use BusinessLogic\Helpers;
|
||||||
|
use BusinessLogic\Security\UserContext;
|
||||||
|
use BusinessLogic\ValidationModel;
|
||||||
|
use DataAccess\AuditTrail\AuditTrailGateway;
|
||||||
|
use DataAccess\Security\UserGateway;
|
||||||
|
use DataAccess\Statuses\StatusGateway;
|
||||||
|
use DataAccess\Tickets\TicketGateway;
|
||||||
|
|
||||||
|
class ReplyCreator {
|
||||||
|
private $statusGateway;
|
||||||
|
private $ticketGateway;
|
||||||
|
private $emailSenderHelper;
|
||||||
|
private $userGateway;
|
||||||
|
private $auditTrailGateway;
|
||||||
|
|
||||||
|
public function __construct(StatusGateway $statusGateway,
|
||||||
|
TicketGateway $ticketGateway,
|
||||||
|
EmailSenderHelper $emailSenderHelper,
|
||||||
|
UserGateway $userGateway,
|
||||||
|
AuditTrailGateway $auditTrailGateway) {
|
||||||
|
$this->statusGateway = $statusGateway;
|
||||||
|
$this->ticketGateway = $ticketGateway;
|
||||||
|
$this->emailSenderHelper = $emailSenderHelper;
|
||||||
|
$this->userGateway = $userGateway;
|
||||||
|
$this->auditTrailGateway = $auditTrailGateway;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $replyRequest CreateReplyRequest
|
||||||
|
* @param $heskSettings array
|
||||||
|
* @param $modsForHeskSettings array
|
||||||
|
* @param $userContext UserContext
|
||||||
|
* @throws ApiFriendlyException
|
||||||
|
*/
|
||||||
|
function createReplyByCustomer($replyRequest, $heskSettings, $modsForHeskSettings, $userContext) {
|
||||||
|
$ticket = $this->ticketGateway->getTicketByTrackingId($replyRequest->trackingId, $heskSettings);
|
||||||
|
|
||||||
|
if ($ticket === null) {
|
||||||
|
throw new ApiFriendlyException("Ticket with tracking ID {$replyRequest->trackingId} not found.",
|
||||||
|
"Ticket not found", 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$validationModel = new ValidationModel();
|
||||||
|
if (!strlen($replyRequest->replyMessage)) {
|
||||||
|
$validationModel->errorKeys[] = 'MESSAGE_REQUIRED';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($modsForHeskSettings['rich_text_for_tickets_for_customers']) {
|
||||||
|
$replyRequest->replyMessage = Helpers::heskMakeUrl($replyRequest->replyMessage);
|
||||||
|
$replyRequest->replyMessage = nl2br($replyRequest->replyMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user