Ticket stuff slowly taking shape
This commit is contained in:
parent
a4af2e668f
commit
a2c98a5a26
@ -6,9 +6,11 @@ namespace Core;
|
||||
use BusinessLogic\Category\CategoryRetriever;
|
||||
use BusinessLogic\Security\BanRetriever;
|
||||
use BusinessLogic\Security\UserContextBuilder;
|
||||
use BusinessLogic\Tickets\TicketRetriever;
|
||||
use DataAccess\CategoryGateway;
|
||||
use DataAccess\Security\BanGateway;
|
||||
use DataAccess\Security\UserGateway;
|
||||
use DataAccess\Tickets\TicketGateway;
|
||||
|
||||
class ApplicationContext {
|
||||
public $get;
|
||||
@ -20,6 +22,10 @@ class ApplicationContext {
|
||||
$this->get['CategoryGateway'] = new CategoryGateway();
|
||||
$this->get['CategoryRetriever'] = new CategoryRetriever($this->get['CategoryGateway']);
|
||||
|
||||
// Tickets
|
||||
$this->get['TicketGateway'] = new TicketGateway();
|
||||
$this->get['TicketRetriever'] = new TicketRetriever($this->get['TicketGateway']);
|
||||
|
||||
// Bans
|
||||
$this->get['BanGateway'] = new BanGateway();
|
||||
$this->get['BanRetriever'] = new BanRetriever($this->get['BanGateway']);
|
||||
|
@ -34,6 +34,16 @@ require_once(__DIR__ . '/businesslogic/security/BanRetriever.php');
|
||||
require_once(__DIR__ . '/businesslogic/security/BannedEmail.php');
|
||||
require_once(__DIR__ . '/businesslogic/security/BannedIp.php');
|
||||
|
||||
// Tickets
|
||||
require_once(__DIR__ . '/dao/ticket/TicketGateway.php');
|
||||
require_once(__DIR__ . '/businesslogic/ticket/Attachment.php');
|
||||
require_once(__DIR__ . '/businesslogic/ticket/Ticket.php');
|
||||
require_once(__DIR__ . '/businesslogic/ticket/CreateTicketByCustomerModel.php');
|
||||
require_once(__DIR__ . '/businesslogic/ticket/TicketValidators.php');
|
||||
require_once(__DIR__ . '/businesslogic/ticket/TicketCreator.php');
|
||||
require_once(__DIR__ . '/businesslogic/ticket/TicketRetriever.php');
|
||||
require_once(__DIR__ . '/controllers/TicketController.php');
|
||||
|
||||
// Exceptions
|
||||
require_once(__DIR__ . '/businesslogic/exception/ApiFriendlyException.php');
|
||||
require_once(__DIR__ . '/businesslogic/exception/InvalidAuthenticationTokenException.php');
|
||||
|
27
api/businesslogic/ticket/Attachment.php
Normal file
27
api/businesslogic/ticket/Attachment.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: mkoch
|
||||
* Date: 1/31/2017
|
||||
* Time: 9:31 PM
|
||||
*/
|
||||
|
||||
namespace BusinessLogic\Tickets;
|
||||
|
||||
|
||||
class Attachment {
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $fileName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $savedName;
|
||||
}
|
@ -4,6 +4,86 @@ namespace BusinessLogic\Tickets;
|
||||
|
||||
|
||||
class Ticket {
|
||||
static function fromDatabaseRow($row, $linkedTicketsRs, $heskSettings) {
|
||||
$ticket = new Ticket();
|
||||
$ticket->id = $row['id'];
|
||||
$ticket->trackingId = $row['trackid'];
|
||||
$ticket->name = $row['name'];
|
||||
$ticket->email = $row['email'];
|
||||
$ticket->categoryId = $row['category'];
|
||||
$ticket->priorityId = $row['priority'];
|
||||
$ticket->subject = $row['subject'];
|
||||
$ticket->message = $row['message'];
|
||||
$ticket->dateCreated = $row['dt'];
|
||||
$ticket->lastChanged = $row['lastchange'];
|
||||
$ticket->firstReplyDate = $row['firstreply'];
|
||||
$ticket->closedDate = $row['closedat'];
|
||||
$ticket->suggestedArticles = explode(',', $row['articles']);
|
||||
$ticket->ipAddress = $row['ip'];
|
||||
$ticket->language = $row['language'];
|
||||
$ticket->statusId = $row['status'];
|
||||
$ticket->openedBy = $row['openedby'];
|
||||
$ticket->firstReplyByUserId = $row['firstreplyby'];
|
||||
$ticket->closedByUserId = $row['closedby'];
|
||||
$ticket->numberOfReplies = $row['replies'];
|
||||
$ticket->numberOfStaffReplies = $row['staffreplies'];
|
||||
$ticket->ownerId = $row['owner'];
|
||||
$ticket->timeWorked = $row['time_worked'];
|
||||
$ticket->lastReplyBy = $row['lastreplier'];
|
||||
$ticket->lastReplier = $row['replierid'];
|
||||
$ticket->archived = intval($row['archive']) === 1;
|
||||
$ticket->locked = intval($row['locked']) === 1;
|
||||
|
||||
if (trim($row['attachments']) !== '') {
|
||||
$attachments = explode(',', $row['attachments']);
|
||||
$attachmentArray = array();
|
||||
foreach ($attachments as $attachment) {
|
||||
$attachmentRow = explode('#', $attachment);
|
||||
$attachmentModel = new Attachment();
|
||||
|
||||
$attachmentModel->id = $attachmentRow[0];
|
||||
$attachmentModel->fileName = $attachmentRow[1];
|
||||
$attachmentModel->savedName = $attachmentRow[2];
|
||||
|
||||
$attachmentArray[] = $attachmentModel;
|
||||
}
|
||||
$ticket->attachments = $attachmentArray;
|
||||
}
|
||||
|
||||
if (trim($row['merged']) !== '') {
|
||||
$ticket->mergedTicketIds = explode(',', $row['merged']);
|
||||
}
|
||||
|
||||
$ticket->auditTrailHtml = $row['history'];
|
||||
|
||||
$ticket->customFields = array();
|
||||
foreach ($heskSettings['custom_fields'] as $key => $value) {
|
||||
if ($value['use'] == 1 && hesk_is_custom_field_in_category($key, intval($ticket->categoryId))) {
|
||||
$ticket->customFields[str_replace('custom', '', $key)] = $row[$key];
|
||||
}
|
||||
}
|
||||
|
||||
$ticket->linkedTicketIds = array();
|
||||
while ($linkedTicketsRow = hesk_dbFetchAssoc($linkedTicketsRs)) {
|
||||
$ticket->linkedTicketIds[] = $linkedTicketsRow['id'];
|
||||
}
|
||||
|
||||
$ticket->location = array();
|
||||
$ticket->location[0] = $row['latitude'];
|
||||
$ticket->location[1] = $row['longitude'];
|
||||
|
||||
$ticket->usesHtml = intval($row['html']) === 1;
|
||||
$ticket->userAgent = $row['user_agent'];
|
||||
$ticket->screenResolution = array();
|
||||
$ticket->screenResolution[0] = $row['screen_resolution_width'];
|
||||
$ticket->screenResolution[1] = $row['screen_resolution_height'];
|
||||
|
||||
$ticket->dueDate = $row['due_date'];
|
||||
$ticket->dueDateOverdueEmailSent = $row['overdue_email_sent'] !== null && intval($row['overdue_email_sent']) === 1;
|
||||
|
||||
return $ticket;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
@ -27,12 +107,12 @@ class Ticket {
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $category;
|
||||
public $categoryId;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $priority;
|
||||
public $priorityId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
@ -65,7 +145,7 @@ class Ticket {
|
||||
public $closedDate;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
* @var string[]|null
|
||||
*/
|
||||
public $suggestedArticles;
|
||||
|
||||
@ -85,9 +165,9 @@ class Ticket {
|
||||
public $statusId;
|
||||
|
||||
/**
|
||||
* @var int (convert to enum)
|
||||
* @var int
|
||||
*/
|
||||
public $openedByUserId;
|
||||
public $openedBy;
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
@ -120,7 +200,12 @@ class Ticket {
|
||||
public $timeWorked;
|
||||
|
||||
/**
|
||||
* @var int (convert to enum)
|
||||
* @var int
|
||||
*/
|
||||
public $lastReplyBy;
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
public $lastReplier;
|
||||
|
||||
@ -135,7 +220,7 @@ class Ticket {
|
||||
public $locked;
|
||||
|
||||
/**
|
||||
* @var array|null (TODO clarify this later)
|
||||
* @var Attachment[]|null
|
||||
*/
|
||||
public $attachments;
|
||||
|
||||
@ -150,7 +235,7 @@ class Ticket {
|
||||
public $auditTrailHtml;
|
||||
|
||||
/**
|
||||
* @var array (TODO clarify this later)
|
||||
* @var string[]
|
||||
*/
|
||||
public $customFields;
|
||||
|
||||
@ -160,7 +245,7 @@ class Ticket {
|
||||
public $linkedTicketIds;
|
||||
|
||||
/**
|
||||
* @var float[2]|null
|
||||
* @var float[]|null
|
||||
*/
|
||||
public $location;
|
||||
|
||||
@ -175,7 +260,7 @@ class Ticket {
|
||||
public $userAgent;
|
||||
|
||||
/**
|
||||
* @var int[2]|null
|
||||
* @var int[]|null
|
||||
*/
|
||||
public $screenResolution;
|
||||
|
||||
|
27
api/businesslogic/ticket/TicketRetriever.php
Normal file
27
api/businesslogic/ticket/TicketRetriever.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: mkoch
|
||||
* Date: 1/31/2017
|
||||
* Time: 10:13 PM
|
||||
*/
|
||||
|
||||
namespace BusinessLogic\Tickets;
|
||||
|
||||
|
||||
use DataAccess\Tickets\TicketGateway;
|
||||
|
||||
class TicketRetriever {
|
||||
/**
|
||||
* @var $ticketGateway TicketGateway
|
||||
*/
|
||||
private $ticketGateway;
|
||||
|
||||
function __construct($ticketGateway) {
|
||||
$this->ticketGateway = $ticketGateway;
|
||||
}
|
||||
|
||||
function getTicketById($id, $heskSettings, $userContext) {
|
||||
return $this->ticketGateway->getTicketById($id, $heskSettings);
|
||||
}
|
||||
}
|
17
api/controllers/TicketController.php
Normal file
17
api/controllers/TicketController.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Controllers\Tickets;
|
||||
|
||||
use BusinessLogic\Tickets\TicketRetriever;
|
||||
|
||||
|
||||
class TicketController {
|
||||
function get($id) {
|
||||
global $applicationContext, $hesk_settings, $userContext;
|
||||
|
||||
/* @var $ticketRetriever TicketRetriever */
|
||||
$ticketRetriever = $applicationContext->get['TicketRetriever'];
|
||||
|
||||
output($ticketRetriever->getTicketById($id, $hesk_settings, $userContext));
|
||||
}
|
||||
}
|
@ -3,11 +3,33 @@
|
||||
namespace DataAccess\Tickets;
|
||||
|
||||
|
||||
class TicketGateway {
|
||||
use BusinessLogic\Tickets\Ticket;
|
||||
use DataAccess\CommonDao;
|
||||
|
||||
class TicketGateway extends CommonDao {
|
||||
function getTicketById($id, $heskSettings) {
|
||||
$this->init();
|
||||
|
||||
$rs = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets` WHERE `id` = " . intval($id));
|
||||
$row = hesk_dbFetchAssoc($rs);
|
||||
$linkedTicketsRs = hesk_dbQuery("SELECT * FROM `hesk_tickets` WHERE `parent` = " . intval($id));
|
||||
|
||||
$ticket = Ticket::fromDatabaseRow($row, $linkedTicketsRs, $heskSettings);
|
||||
|
||||
$this->close();
|
||||
|
||||
return $ticket;
|
||||
}
|
||||
|
||||
function getTicketsByEmail($emailAddress, $heskSettings) {
|
||||
$rs = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets`
|
||||
WHERE `email` = '" . hesk_dbEscape($emailAddress) . "'");
|
||||
|
||||
$tickets = array();
|
||||
|
||||
while ($row = hesk_dbFetchAssoc($rs)) {
|
||||
$ticket = new Ticket();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -83,6 +83,8 @@ Link::all(array(
|
||||
// Categories
|
||||
'/v1/categories' => '\Controllers\Category\CategoryController::printAllCategories',
|
||||
'/v1/categories/{i}' => '\Controllers\Category\CategoryController',
|
||||
// Tickets
|
||||
'/v1/tickets/{i}' => '\Controllers\Tickets\TicketController',
|
||||
|
||||
// Any URL that doesn't match goes to the 404 handler
|
||||
'404' => 'handle404'
|
||||
|
Loading…
x
Reference in New Issue
Block a user