2017-01-26 22:00:45 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BusinessLogic\Tickets;
|
|
|
|
|
2017-01-28 22:35:42 -05:00
|
|
|
use BusinessLogic\Exceptions\ValidationException;
|
2017-02-12 01:38:12 -05:00
|
|
|
use DataAccess\Tickets\TicketGateway;
|
2017-01-26 22:00:45 -05:00
|
|
|
|
|
|
|
class TicketCreator {
|
2017-02-06 22:13:16 -05:00
|
|
|
/**
|
2017-02-12 01:38:12 -05:00
|
|
|
* @var $newTicketValidator NewTicketValidator
|
2017-02-06 22:13:16 -05:00
|
|
|
*/
|
2017-02-12 01:38:12 -05:00
|
|
|
private $newTicketValidator;
|
|
|
|
|
2017-02-06 22:13:16 -05:00
|
|
|
/**
|
2017-02-12 01:38:12 -05:00
|
|
|
* @var $trackingIdGenerator TrackingIdGenerator
|
2017-02-06 22:13:16 -05:00
|
|
|
*/
|
2017-02-12 01:38:12 -05:00
|
|
|
private $trackingIdGenerator;
|
|
|
|
|
2017-02-10 22:09:46 -05:00
|
|
|
/**
|
2017-02-12 01:38:12 -05:00
|
|
|
* @var $ticketGateway TicketGateway
|
2017-02-10 22:09:46 -05:00
|
|
|
*/
|
2017-02-12 01:38:12 -05:00
|
|
|
private $ticketGateway;
|
2017-02-05 22:12:18 -05:00
|
|
|
|
2017-02-12 01:38:12 -05:00
|
|
|
function __construct($newTicketValidator, $trackingIdGenerator, $ticketGateway) {
|
|
|
|
$this->newTicketValidator = $newTicketValidator;
|
|
|
|
$this->trackingIdGenerator = $trackingIdGenerator;
|
|
|
|
$this->ticketGateway = $ticketGateway;
|
2017-02-05 22:12:18 -05:00
|
|
|
}
|
|
|
|
|
2017-01-26 22:00:45 -05:00
|
|
|
/**
|
2017-02-11 22:07:10 -05:00
|
|
|
* Ticket attachments are <b>NOT</b> handled here!
|
|
|
|
*
|
2017-01-26 22:00:45 -05:00
|
|
|
* @param $ticketRequest CreateTicketByCustomerModel
|
|
|
|
* @param $heskSettings array HESK settings
|
|
|
|
* @param $modsForHeskSettings array Mods for HESK settings
|
2017-02-12 01:38:12 -05:00
|
|
|
* @return Ticket The newly created ticket
|
2017-01-26 22:00:45 -05:00
|
|
|
* @throws ValidationException When a required field in $ticket_request is missing
|
2017-02-11 22:07:10 -05:00
|
|
|
*
|
2017-01-26 22:00:45 -05:00
|
|
|
*/
|
2017-02-06 22:13:16 -05:00
|
|
|
function createTicketByCustomer($ticketRequest, $heskSettings, $modsForHeskSettings, $userContext) {
|
2017-02-12 01:38:12 -05:00
|
|
|
$validationModel = $this->newTicketValidator->validateNewTicketForCustomer($ticketRequest, $heskSettings, $userContext);
|
2017-01-26 22:00:45 -05:00
|
|
|
|
|
|
|
if (count($validationModel->errorKeys) > 0) {
|
|
|
|
// Validation failed
|
2017-02-05 22:12:18 -05:00
|
|
|
$validationModel->valid = false;
|
2017-01-26 22:00:45 -05:00
|
|
|
throw new ValidationException($validationModel);
|
|
|
|
}
|
|
|
|
|
2017-02-02 20:21:25 -05:00
|
|
|
// Create the ticket
|
2017-02-12 01:38:12 -05:00
|
|
|
$ticket = new Ticket();
|
|
|
|
$ticket->trackingId = $this->trackingIdGenerator->generateTrackingId($heskSettings);
|
2017-02-11 22:07:10 -05:00
|
|
|
|
|
|
|
//-- TODO suggested kb articles
|
|
|
|
|
2017-02-12 01:38:12 -05:00
|
|
|
//-- TODO owner/autoassign logic
|
2017-02-11 22:07:10 -05:00
|
|
|
|
|
|
|
//-- TODO latitude/longitude
|
|
|
|
|
|
|
|
//-- TODO HTML flag
|
|
|
|
|
2017-02-12 01:38:12 -05:00
|
|
|
$this->ticketGateway->createTicket($ticket, $heskSettings);
|
2017-01-26 22:00:45 -05:00
|
|
|
|
2017-02-12 01:38:12 -05:00
|
|
|
return $ticket;
|
2017-01-26 22:00:45 -05:00
|
|
|
}
|
|
|
|
}
|