Working more on create ticket endpoint
This commit is contained in:
parent
843528252b
commit
1cb4209be2
@ -4,7 +4,12 @@
|
||||
use BusinessLogic\Categories\CategoryRetriever;
|
||||
use BusinessLogic\Security\BanRetriever;
|
||||
use BusinessLogic\Security\UserContextBuilder;
|
||||
use BusinessLogic\Tickets\Autoassigner;
|
||||
use BusinessLogic\Tickets\TicketRetriever;
|
||||
use BusinessLogic\Tickets\TicketCreator;
|
||||
use BusinessLogic\Tickets\NewTicketValidator;
|
||||
use BusinessLogic\Tickets\TicketValidators;
|
||||
use BusinessLogic\Tickets\TrackingIdGenerator;
|
||||
use DataAccess\Categories\CategoryGateway;
|
||||
use DataAccess\Security\BanGateway;
|
||||
use DataAccess\Security\UserGateway;
|
||||
@ -17,20 +22,30 @@ class ApplicationContext {
|
||||
function __construct() {
|
||||
$this->get = array();
|
||||
|
||||
// Categories
|
||||
$this->get['CategoryGateway'] = new CategoryGateway();
|
||||
$this->get['CategoryRetriever'] = new CategoryRetriever($this->get['CategoryGateway']);
|
||||
// User Context
|
||||
$this->get[UserGateway::class] = new UserGateway();
|
||||
$this->get[UserContextBuilder::class] = new UserContextBuilder($this->get[UserGateway::class]);
|
||||
|
||||
// Tickets
|
||||
$this->get['TicketGateway'] = new TicketGateway();
|
||||
$this->get['TicketRetriever'] = new TicketRetriever($this->get['TicketGateway']);
|
||||
// Categories
|
||||
$this->get[CategoryGateway::class] = new CategoryGateway();
|
||||
$this->get[CategoryRetriever::class] = new CategoryRetriever($this->get[CategoryGateway::class]);
|
||||
|
||||
// Bans
|
||||
$this->get['BanGateway'] = new BanGateway();
|
||||
$this->get['BanRetriever'] = new BanRetriever($this->get['BanGateway']);
|
||||
$this->get[BanGateway::class] = new BanGateway();
|
||||
$this->get[BanRetriever::class] = new BanRetriever($this->get[BanGateway::class]);
|
||||
|
||||
// User Context
|
||||
$this->get['UserGateway'] = new UserGateway();
|
||||
$this->get['UserContextBuilder'] = new UserContextBuilder($this->get['UserGateway']);
|
||||
// Tickets
|
||||
$this->get[TicketGateway::class] = new TicketGateway();
|
||||
$this->get[TicketRetriever::class] = new TicketRetriever($this->get[TicketGateway::class]);
|
||||
$this->get[TicketValidators::class] = new TicketValidators($this->get[TicketGateway::class]);
|
||||
$this->get[TrackingIdGenerator::class] = new TrackingIdGenerator($this->get[TicketGateway::class]);
|
||||
$this->get[Autoassigner::class] = new Autoassigner();
|
||||
$this->get[NewTicketValidator::class] = new NewTicketValidator($this->get[CategoryRetriever::class],
|
||||
$this->get[BanRetriever::class],
|
||||
$this->get[TicketValidators::class]);
|
||||
$this->get[TicketCreator::class] = new TicketCreator($this->get[NewTicketValidator::class],
|
||||
$this->get[TrackingIdGenerator::class],
|
||||
$this->get[Autoassigner::class],
|
||||
$this->get[TicketGateway::class]);
|
||||
}
|
||||
}
|
@ -20,4 +20,10 @@ class Helpers {
|
||||
static function hashToken($token) {
|
||||
return hash('sha512', $token);
|
||||
}
|
||||
|
||||
static function safeArrayGet($array, $key) {
|
||||
return $array !== null && array_key_exists($key, $array)
|
||||
? $array[$key]
|
||||
: null;
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@ class CustomFieldValidator {
|
||||
return false;
|
||||
}
|
||||
|
||||
return count($customField['category']) === 0 ||
|
||||
in_array($categoryId, $customField['category']);
|
||||
return count($customField['Categories']) === 0 ||
|
||||
in_array($categoryId, $customField['Categories']);
|
||||
}
|
||||
}
|
@ -1,10 +1,4 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Mike
|
||||
* Date: 2/12/2017
|
||||
* Time: 1:01 AM
|
||||
*/
|
||||
|
||||
namespace BusinessLogic\Tickets;
|
||||
|
||||
@ -82,6 +76,12 @@ class NewTicketValidator {
|
||||
|
||||
foreach ($heskSettings['custom_fields'] as $key => $value) {
|
||||
$customFieldNumber = intval(str_replace('custom', '', $key));
|
||||
|
||||
//TODO test this
|
||||
if (!array_key_exists($customFieldNumber, $ticketRequest->customFields)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($value['use'] == 1 && CustomFieldValidator::isCustomFieldInCategory($customFieldNumber, intval($ticketRequest->category), false, $heskSettings)) {
|
||||
$custom_field_value = $ticketRequest->customFields[$customFieldNumber];
|
||||
if (empty($custom_field_value)) {
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Controllers\Category;
|
||||
|
||||
use BusinessLogic\Category\CategoryRetriever;
|
||||
use BusinessLogic\Categories\CategoryRetriever;
|
||||
|
||||
class CategoryController {
|
||||
function get($id) {
|
||||
@ -18,7 +18,7 @@ class CategoryController {
|
||||
global $hesk_settings, $applicationContext, $userContext;
|
||||
|
||||
/* @var $categoryRetriever CategoryRetriever */
|
||||
$categoryRetriever = $applicationContext->get['CategoryRetriever'];
|
||||
$categoryRetriever = $applicationContext->get[CategoryRetriever::class];
|
||||
|
||||
return $categoryRetriever->getAllCategories($hesk_settings, $userContext);
|
||||
}
|
||||
|
22
api/Controllers/JsonRetriever.php
Normal file
22
api/Controllers/JsonRetriever.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: mkoch
|
||||
* Date: 2/13/2017
|
||||
* Time: 9:21 PM
|
||||
*/
|
||||
|
||||
namespace Controllers;
|
||||
|
||||
|
||||
class JsonRetriever {
|
||||
/**
|
||||
* Support POST, PUT, and PATCH request (and possibly more)
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
static function getJsonData() {
|
||||
$json = file_get_contents('php://input');
|
||||
return json_decode($json);
|
||||
}
|
||||
}
|
@ -2,8 +2,11 @@
|
||||
|
||||
namespace Controllers\Tickets;
|
||||
|
||||
use BusinessLogic\Helpers;
|
||||
use BusinessLogic\Tickets\CreateTicketByCustomerModel;
|
||||
use BusinessLogic\Tickets\TicketCreator;
|
||||
use BusinessLogic\Tickets\TicketRetriever;
|
||||
use Controllers\JsonRetriever;
|
||||
|
||||
|
||||
class TicketController {
|
||||
@ -11,7 +14,7 @@ class TicketController {
|
||||
global $applicationContext, $hesk_settings, $userContext;
|
||||
|
||||
/* @var $ticketRetriever TicketRetriever */
|
||||
$ticketRetriever = $applicationContext->get['TicketRetriever'];
|
||||
$ticketRetriever = $applicationContext->get[TicketRetriever::class];
|
||||
|
||||
output($ticketRetriever->getTicketById($id, $hesk_settings, $userContext));
|
||||
}
|
||||
@ -22,8 +25,38 @@ class TicketController {
|
||||
/* @var $ticketCreator TicketCreator */
|
||||
$ticketCreator = $applicationContext->get[TicketCreator::class];
|
||||
|
||||
//-- TODO Parse POST data
|
||||
$jsonRequest = JsonRetriever::getJsonData();
|
||||
|
||||
$ticketCreator->createTicketByCustomer(null, $hesk_settings, $modsForHeskSettings, $userContext);
|
||||
$ticketCreator->createTicketByCustomer($this->buildTicketRequestFromJson($jsonRequest), $hesk_settings, $modsForHeskSettings, $userContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $json array
|
||||
* @return CreateTicketByCustomerModel
|
||||
*/
|
||||
private function buildTicketRequestFromJson($json) {
|
||||
$ticketRequest = new CreateTicketByCustomerModel();
|
||||
$ticketRequest->name = Helpers::safeArrayGet($json, 'name');
|
||||
$ticketRequest->email = Helpers::safeArrayGet($json, 'email');
|
||||
$ticketRequest->category = Helpers::safeArrayGet($json, 'category');
|
||||
$ticketRequest->priority = Helpers::safeArrayGet($json, 'priority');
|
||||
$ticketRequest->subject = Helpers::safeArrayGet($json, 'subject');
|
||||
$ticketRequest->message = Helpers::safeArrayGet($json, 'message');
|
||||
$ticketRequest->html = Helpers::safeArrayGet($json, 'html');
|
||||
$ticketRequest->location = Helpers::safeArrayGet($json, 'location');
|
||||
$ticketRequest->suggestedKnowledgebaseArticleIds = Helpers::safeArrayGet($json, 'suggestedArticles');
|
||||
$ticketRequest->userAgent = Helpers::safeArrayGet($json, 'userAgent');
|
||||
$ticketRequest->screenResolution = Helpers::safeArrayGet($json, 'screenResolution');
|
||||
$ticketRequest->customFields = array();
|
||||
|
||||
$jsonCustomFields = Helpers::safeArrayGet($json, 'customFields');
|
||||
|
||||
if ($jsonCustomFields !== null && !empty($jsonCustomFields)) {
|
||||
foreach ($jsonCustomFields as $key => $value) {
|
||||
$ticketRequest->customFields[intval($key)] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $ticketRequest;
|
||||
}
|
||||
}
|
@ -19,8 +19,8 @@ class BanGateway extends CommonDao {
|
||||
|
||||
$rs = hesk_dbQuery("SELECT `bans`.`id` AS `id`, `bans`.`email` AS `email`,
|
||||
`users`.`id` AS `banned_by`, `bans`.`dt` AS `dt`
|
||||
FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "_banned_emails` AS `bans`
|
||||
LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "_users` AS `users`
|
||||
FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "banned_emails` AS `bans`
|
||||
LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "users` AS `users`
|
||||
ON `bans`.`banned_by` = `users`.`id`
|
||||
AND `users`.`active` = '1'");
|
||||
|
||||
@ -51,8 +51,8 @@ class BanGateway extends CommonDao {
|
||||
$rs = hesk_dbQuery("SELECT `bans`.`id` AS `id`, `bans`.`ip_from` AS `ip_from`,
|
||||
`bans`.`ip_to` AS `ip_to`, `bans`.`ip_display` AS `ip_display`,
|
||||
`users`.`id` AS `banned_by`, `bans`.`dt` AS `dt`
|
||||
FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "_banned_ips` AS `bans`
|
||||
LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "_users` AS `users`
|
||||
FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "banned_ips` AS `bans`
|
||||
LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "users` AS `users`
|
||||
ON `bans`.`banned_by` = `users`.`id`
|
||||
AND `users`.`active` = '1'");
|
||||
|
||||
|
@ -177,14 +177,7 @@ class Link
|
||||
|
||||
if( isset( $instanceOfHandler ) ) {
|
||||
if( method_exists( $instanceOfHandler, $method ) ) {
|
||||
try {
|
||||
$newParams = call_user_func_array( array( $instanceOfHandler, $method ), $matched );
|
||||
} catch ( Exception $exception ){
|
||||
$string = str_replace("\n", ' ', var_export($exception, TRUE));
|
||||
error_log($string); //Log to error file only if display errors has been declared
|
||||
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
if( isset( $newParams ) && $newParams ) {
|
||||
|
@ -18,4 +18,4 @@ require_once(__DIR__ . '/../inc/custom_fields.inc.php');
|
||||
|
||||
// Load the ApplicationContext
|
||||
$applicationContext = new \ApplicationContext();
|
||||
$modsForHeskSettings = mfh_getSettings();
|
||||
//$modsForHeskSettings = mfh_getSettings();
|
@ -28,7 +28,7 @@ function buildUserContext($xAuthToken) {
|
||||
global $applicationContext, $userContext, $hesk_settings;
|
||||
|
||||
/* @var $userContextBuilder \BusinessLogic\Security\UserContextBuilder */
|
||||
$userContextBuilder = $applicationContext->get['UserContextBuilder'];
|
||||
$userContextBuilder = $applicationContext->get[\BusinessLogic\Security\UserContextBuilder::class];
|
||||
|
||||
$userContext = $userContextBuilder->buildUserContext($xAuthToken, $hesk_settings);
|
||||
}
|
||||
@ -52,7 +52,7 @@ function exceptionHandler($exception) {
|
||||
$castedException = $exception;
|
||||
print_error("Fought an uncaught exception", sprintf("%s\n\n%s", $castedException->failingQuery, $exception->getTraceAsString()));
|
||||
} else {
|
||||
print_error("Fought an uncaught exception", sprintf("%s\n\n%s", $exception->getMessage(), $exception->getTraceAsString()));
|
||||
print_error("Fought an uncaught exception of type " . get_class($exception), sprintf("%s\n\n%s", $exception->getMessage(), $exception->getTraceAsString()));
|
||||
}
|
||||
|
||||
}
|
||||
@ -85,6 +85,7 @@ Link::all(array(
|
||||
'/v1/categories/{i}' => '\Controllers\Category\CategoryController',
|
||||
// Tickets
|
||||
'/v1/tickets/{i}' => '\Controllers\Tickets\TicketController',
|
||||
'/v1/tickets' => '\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