You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
3.9 KiB
PHP
109 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace BusinessLogic\Tickets;
|
|
|
|
use BusinessLogic\Exceptions\ValidationException;
|
|
use BusinessLogic\Statuses\DefaultStatusForAction;
|
|
use DataAccess\Statuses\StatusGateway;
|
|
use DataAccess\Tickets\TicketGateway;
|
|
|
|
class TicketCreator {
|
|
/**
|
|
* @var $newTicketValidator NewTicketValidator
|
|
*/
|
|
private $newTicketValidator;
|
|
|
|
/**
|
|
* @var $trackingIdGenerator TrackingIdGenerator
|
|
*/
|
|
private $trackingIdGenerator;
|
|
|
|
/**
|
|
* @var $autoassigner Autoassigner
|
|
*/
|
|
private $autoassigner;
|
|
|
|
/**
|
|
* @var $statusGateway StatusGateway
|
|
*/
|
|
private $statusGateway;
|
|
|
|
/**
|
|
* @var $ticketGateway TicketGateway
|
|
*/
|
|
private $ticketGateway;
|
|
|
|
function __construct($newTicketValidator, $trackingIdGenerator, $autoassigner, $statusGateway, $ticketGateway) {
|
|
$this->newTicketValidator = $newTicketValidator;
|
|
$this->trackingIdGenerator = $trackingIdGenerator;
|
|
$this->autoassigner = $autoassigner;
|
|
$this->statusGateway = $statusGateway;
|
|
$this->ticketGateway = $ticketGateway;
|
|
}
|
|
|
|
/**
|
|
* Ticket attachments are <b>NOT</b> handled here!
|
|
*
|
|
* @param $ticketRequest CreateTicketByCustomerModel
|
|
* @param $heskSettings array HESK settings
|
|
* @param $modsForHeskSettings array Mods for HESK settings
|
|
* @return Ticket The newly created ticket
|
|
* @throws ValidationException When a required field in $ticket_request is missing
|
|
*
|
|
*/
|
|
function createTicketByCustomer($ticketRequest, $heskSettings, $modsForHeskSettings, $userContext) {
|
|
$validationModel = $this->newTicketValidator->validateNewTicketForCustomer($ticketRequest, $heskSettings, $userContext);
|
|
|
|
if (count($validationModel->errorKeys) > 0) {
|
|
// Validation failed
|
|
$validationModel->valid = false;
|
|
throw new ValidationException($validationModel);
|
|
}
|
|
|
|
// Create the ticket
|
|
$ticket = new Ticket();
|
|
$ticket->trackingId = $this->trackingIdGenerator->generateTrackingId($heskSettings);
|
|
|
|
if ($heskSettings['autoassign']) {
|
|
$ticket->ownerId = $this->autoassigner->getNextUserForTicket($ticketRequest->category, $heskSettings);
|
|
}
|
|
|
|
// Transform one-to-one properties
|
|
$ticket->name = $ticketRequest->name;
|
|
$ticket->email = $ticketRequest->email;
|
|
$ticket->priorityId = $ticketRequest->priority;
|
|
$ticket->categoryId = $ticketRequest->category;
|
|
$ticket->subject = $ticketRequest->subject;
|
|
$ticket->message = $ticketRequest->message;
|
|
$ticket->usesHtml = $ticketRequest->html;
|
|
$ticket->customFields = $ticketRequest->customFields;
|
|
$ticket->location = $ticketRequest->location;
|
|
$ticket->suggestedArticles = $ticketRequest->suggestedKnowledgebaseArticleIds;
|
|
$ticket->userAgent = $ticketRequest->userAgent;
|
|
$ticket->screenResolution = $ticketRequest->screenResolution;
|
|
$ticket->ipAddress = $ticketRequest->ipAddress;
|
|
$ticket->language = $ticketRequest->language;
|
|
|
|
$status = $this->statusGateway->getStatusForDefaultAction(DefaultStatusForAction::NEW_TICKET, $heskSettings);
|
|
|
|
if ($status === null) {
|
|
throw new \Exception("Could not find the default status for a new ticket!");
|
|
}
|
|
$ticket->statusId = $status->id;
|
|
|
|
$ticketGatewayGeneratedFields = $this->ticketGateway->createTicket($ticket, $heskSettings);
|
|
|
|
$ticket->dateCreated = $ticketGatewayGeneratedFields->dateCreated;
|
|
$ticket->lastChanged = $ticketGatewayGeneratedFields->dateModified;
|
|
$ticket->archived = false;
|
|
$ticket->locked = false;
|
|
$ticket->id = $ticketGatewayGeneratedFields->id;
|
|
$ticket->openedBy = 0;
|
|
$ticket->numberOfReplies = 0;
|
|
$ticket->numberOfStaffReplies = 0;
|
|
$ticket->timeWorked = '00:00:00';
|
|
$ticket->lastReplier = 0;
|
|
|
|
return $ticket;
|
|
}
|
|
} |