Categories can be created
This commit is contained in:
parent
8f52400aea
commit
7d2479d5b6
@ -3,6 +3,7 @@
|
|||||||
// Responsible for loading in all necessary classes. AKA a poor man's DI solution.
|
// Responsible for loading in all necessary classes. AKA a poor man's DI solution.
|
||||||
use BusinessLogic\Attachments\AttachmentHandler;
|
use BusinessLogic\Attachments\AttachmentHandler;
|
||||||
use BusinessLogic\Attachments\AttachmentRetriever;
|
use BusinessLogic\Attachments\AttachmentRetriever;
|
||||||
|
use BusinessLogic\Categories\CategoryHandler;
|
||||||
use BusinessLogic\Categories\CategoryRetriever;
|
use BusinessLogic\Categories\CategoryRetriever;
|
||||||
use BusinessLogic\Emails\BasicEmailSender;
|
use BusinessLogic\Emails\BasicEmailSender;
|
||||||
use BusinessLogic\Emails\EmailSenderHelper;
|
use BusinessLogic\Emails\EmailSenderHelper;
|
||||||
@ -73,6 +74,7 @@ class ApplicationContext {
|
|||||||
// Categories
|
// Categories
|
||||||
$this->get[CategoryGateway::class] = new CategoryGateway();
|
$this->get[CategoryGateway::class] = new CategoryGateway();
|
||||||
$this->get[CategoryRetriever::class] = new CategoryRetriever($this->get[CategoryGateway::class]);
|
$this->get[CategoryRetriever::class] = new CategoryRetriever($this->get[CategoryGateway::class]);
|
||||||
|
$this->get[CategoryHandler::class] = new CategoryHandler($this->get[CategoryGateway::class]);
|
||||||
|
|
||||||
// Bans
|
// Bans
|
||||||
$this->get[BanGateway::class] = new BanGateway();
|
$this->get[BanGateway::class] = new BanGateway();
|
||||||
|
@ -4,6 +4,7 @@ namespace DataAccess\Categories;
|
|||||||
|
|
||||||
use BusinessLogic\Categories\Category;
|
use BusinessLogic\Categories\Category;
|
||||||
use DataAccess\CommonDao;
|
use DataAccess\CommonDao;
|
||||||
|
use DataAccess\Logging\LoggingGateway;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
class CategoryGateway extends CommonDao {
|
class CategoryGateway extends CommonDao {
|
||||||
@ -57,10 +58,10 @@ class CategoryGateway extends CommonDao {
|
|||||||
(`name`, `cat_order`, `autoassign`, `type`, `priority`, `manager`, `background_color`, `usage`,
|
(`name`, `cat_order`, `autoassign`, `type`, `priority`, `manager`, `background_color`, `usage`,
|
||||||
`foreground_color`, `display_border_outline`, `mfh_description`)
|
`foreground_color`, `display_border_outline`, `mfh_description`)
|
||||||
VALUES ('" . hesk_dbEscape($category->name) . "', " . intval($newOrder['cat_order']) . ",
|
VALUES ('" . hesk_dbEscape($category->name) . "', " . intval($newOrder['cat_order']) . ",
|
||||||
'" . $category->autoAssign ? 1 : 0 . "', '" . intval($category->type) . "',
|
'" . ($category->autoAssign ? 1 : 0) . "', '" . intval($category->type) . "',
|
||||||
'" . intval($category->priority) . "', " . $category->manager === null ? 'NULL' : intval($category->manager) . ",
|
'" . intval($category->priority) . "', " . ($category->manager === null ? 0 : intval($category->manager)) . ",
|
||||||
'" . hesk_dbEscape($category->backgroundColor) . "', " . intval($category->usage) . ",
|
'" . hesk_dbEscape($category->backgroundColor) . "', " . intval($category->usage) . ",
|
||||||
'" . hesk_dbEscape($category->foregroundColor) . "', '" . $category->displayBorder ? 1 : 0 . "',
|
'" . hesk_dbEscape($category->foregroundColor) . "', '" . ($category->displayBorder ? 1 : 0) . "',
|
||||||
'" . hesk_dbEscape($category->description) . "')";
|
'" . hesk_dbEscape($category->description) . "')";
|
||||||
|
|
||||||
hesk_dbQuery($sql);
|
hesk_dbQuery($sql);
|
||||||
|
24
api/Link.php
24
api/Link.php
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require_once 'RequestMethod.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class Main class of the Link router that helps you create and deploy routes
|
* @class Main class of the Link router that helps you create and deploy routes
|
||||||
*/
|
*/
|
||||||
@ -40,9 +42,11 @@ class Link
|
|||||||
|
|
||||||
self::$routes = $routes;
|
self::$routes = $routes;
|
||||||
$method = self::getRequestMethod();
|
$method = self::getRequestMethod();
|
||||||
|
$acceptedMethods = RequestMethod::ALL;
|
||||||
$path = '/';
|
$path = '/';
|
||||||
$handler = null;
|
$handler = null;
|
||||||
$matched = array();
|
$matched = array();
|
||||||
|
$middleware = null;
|
||||||
if ( !empty ( $_SERVER['PATH_INFO'] ) ) {
|
if ( !empty ( $_SERVER['PATH_INFO'] ) ) {
|
||||||
$path = $_SERVER['PATH_INFO'];
|
$path = $_SERVER['PATH_INFO'];
|
||||||
} else if ( !empty ( $_SERVER['REQUEST_URI'] ) ) {
|
} else if ( !empty ( $_SERVER['REQUEST_URI'] ) ) {
|
||||||
@ -52,6 +56,8 @@ class Link
|
|||||||
if ( isset($routes[$path] ) ) {
|
if ( isset($routes[$path] ) ) {
|
||||||
if( is_array( $routes[$path] ) ) {
|
if( is_array( $routes[$path] ) ) {
|
||||||
$handler = $routes[$path][0];
|
$handler = $routes[$path][0];
|
||||||
|
$middleware = $routes[$path][2];
|
||||||
|
$acceptedMethods = $routes[$path][3];
|
||||||
} else {
|
} else {
|
||||||
$handler = $routes[$path];
|
$handler = $routes[$path];
|
||||||
}
|
}
|
||||||
@ -88,15 +94,15 @@ class Link
|
|||||||
unset( $matched[0] );
|
unset( $matched[0] );
|
||||||
|
|
||||||
if( isset($middleware) ){
|
if( isset($middleware) ){
|
||||||
$newMatched = self::callFunction( $middleware, $matched, $method );
|
$newMatched = self::callFunction( $middleware, $matched, $method, $acceptedMethods );
|
||||||
/* If new wildcard param are there pass them to main handler */
|
/* If new wildcard param are there pass them to main handler */
|
||||||
if( $newMatched ) {
|
if( $newMatched ) {
|
||||||
self::callFunction( $handler, $newMatched, $method );
|
self::callFunction( $handler, $newMatched, $method, $acceptedMethods );
|
||||||
} else {
|
} else {
|
||||||
self::callFunction( $handler, $matched, $method );
|
self::callFunction( $handler, $matched, $method, $acceptedMethods );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self::callFunction( $handler, $matched, $method );
|
self::callFunction( $handler, $matched, $method, $acceptedMethods );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Call all the function that are to be executed after routing */
|
/* Call all the function that are to be executed after routing */
|
||||||
@ -165,12 +171,20 @@ class Link
|
|||||||
*
|
*
|
||||||
* @param array|string $handler Handler that will handle the routes call or middleware
|
* @param array|string $handler Handler that will handle the routes call or middleware
|
||||||
* @param array $matched The parameters that we get from the route wildcard
|
* @param array $matched The parameters that we get from the route wildcard
|
||||||
|
* @param $method string request method
|
||||||
|
* @param $acceptedMethods array Accepted request methods for the request
|
||||||
* @return array $newParams The parameters return in the case of middleware if you intend to
|
* @return array $newParams The parameters return in the case of middleware if you intend to
|
||||||
* the wildcards that were originally passed, this newParams will
|
* the wildcards that were originally passed, this newParams will
|
||||||
* be next passed to main handler
|
* be next passed to main handler
|
||||||
*/
|
*/
|
||||||
public static function callFunction( $handler , $matched, $method )
|
public static function callFunction( $handler , $matched, $method, $acceptedMethods )
|
||||||
{
|
{
|
||||||
|
if (!in_array($method, $acceptedMethods)) {
|
||||||
|
print_r('Request method ' . $method . ' not allowed');
|
||||||
|
header($_SERVER['SERVER_PROTOCOL'] . ' 405 Method Not Allowed', true, 405);
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
if ( $handler ) {
|
if ( $handler ) {
|
||||||
if ( is_callable( $handler ) ) {
|
if ( is_callable( $handler ) ) {
|
||||||
$newParams = call_user_func_array( $handler, $matched ) ;
|
$newParams = call_user_func_array( $handler, $matched ) ;
|
||||||
|
@ -187,7 +187,8 @@ Link::before('globalBefore');
|
|||||||
|
|
||||||
Link::all(array(
|
Link::all(array(
|
||||||
// Categories
|
// Categories
|
||||||
'/v1/categories' => action(\Controllers\Categories\CategoryController::class . '::printAllCategories', [RequestMethod::GET]),
|
'/v1/categories/all' => action(\Controllers\Categories\CategoryController::class . '::printAllCategories', [RequestMethod::GET]),
|
||||||
|
'/v1/categories' => action(\Controllers\Categories\CategoryController::class, [RequestMethod::POST]),
|
||||||
'/v1/categories/{i}' => action(\Controllers\Categories\CategoryController::class),
|
'/v1/categories/{i}' => action(\Controllers\Categories\CategoryController::class),
|
||||||
// Tickets
|
// Tickets
|
||||||
'/v1/tickets' => action(\Controllers\Tickets\CustomerTicketController::class),
|
'/v1/tickets' => action(\Controllers\Tickets\CustomerTicketController::class),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user