Categories can be created

master
Mike Koch 7 years ago
parent 8f52400aea
commit 7d2479d5b6

@ -3,6 +3,7 @@
// Responsible for loading in all necessary classes. AKA a poor man's DI solution.
use BusinessLogic\Attachments\AttachmentHandler;
use BusinessLogic\Attachments\AttachmentRetriever;
use BusinessLogic\Categories\CategoryHandler;
use BusinessLogic\Categories\CategoryRetriever;
use BusinessLogic\Emails\BasicEmailSender;
use BusinessLogic\Emails\EmailSenderHelper;
@ -73,6 +74,7 @@ class ApplicationContext {
// Categories
$this->get[CategoryGateway::class] = new CategoryGateway();
$this->get[CategoryRetriever::class] = new CategoryRetriever($this->get[CategoryGateway::class]);
$this->get[CategoryHandler::class] = new CategoryHandler($this->get[CategoryGateway::class]);
// Bans
$this->get[BanGateway::class] = new BanGateway();

@ -4,6 +4,7 @@ namespace DataAccess\Categories;
use BusinessLogic\Categories\Category;
use DataAccess\CommonDao;
use DataAccess\Logging\LoggingGateway;
use Exception;
class CategoryGateway extends CommonDao {
@ -57,10 +58,10 @@ class CategoryGateway extends CommonDao {
(`name`, `cat_order`, `autoassign`, `type`, `priority`, `manager`, `background_color`, `usage`,
`foreground_color`, `display_border_outline`, `mfh_description`)
VALUES ('" . hesk_dbEscape($category->name) . "', " . intval($newOrder['cat_order']) . ",
'" . $category->autoAssign ? 1 : 0 . "', '" . intval($category->type) . "',
'" . intval($category->priority) . "', " . $category->manager === null ? 'NULL' : intval($category->manager) . ",
'" . ($category->autoAssign ? 1 : 0) . "', '" . intval($category->type) . "',
'" . intval($category->priority) . "', " . ($category->manager === null ? 0 : intval($category->manager)) . ",
'" . 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_dbQuery($sql);

@ -1,5 +1,7 @@
<?php
require_once 'RequestMethod.php';
/**
* @class Main class of the Link router that helps you create and deploy routes
*/
@ -40,9 +42,11 @@ class Link
self::$routes = $routes;
$method = self::getRequestMethod();
$acceptedMethods = RequestMethod::ALL;
$path = '/';
$handler = null;
$matched = array();
$middleware = null;
if ( !empty ( $_SERVER['PATH_INFO'] ) ) {
$path = $_SERVER['PATH_INFO'];
} else if ( !empty ( $_SERVER['REQUEST_URI'] ) ) {
@ -52,6 +56,8 @@ class Link
if ( isset($routes[$path] ) ) {
if( is_array( $routes[$path] ) ) {
$handler = $routes[$path][0];
$middleware = $routes[$path][2];
$acceptedMethods = $routes[$path][3];
} else {
$handler = $routes[$path];
}
@ -88,15 +94,15 @@ class Link
unset( $matched[0] );
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( $newMatched ) {
self::callFunction( $handler, $newMatched, $method );
self::callFunction( $handler, $newMatched, $method, $acceptedMethods );
} else {
self::callFunction( $handler, $matched, $method );
self::callFunction( $handler, $matched, $method, $acceptedMethods );
}
} else {
self::callFunction( $handler, $matched, $method );
self::callFunction( $handler, $matched, $method, $acceptedMethods );
}
/* Call all the function that are to be executed after routing */
@ -160,17 +166,25 @@ class Link
}
}
/**
* Static function to handle both middlewares' call and main handler's call.
*
* @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
* @return array $newParams The parameters return in the case of middleware if you intend to
* the wildcards that were originally passed, this newParams will
* be next passed to main handler
*/
public static function callFunction( $handler , $matched, $method )
/**
* Static function to handle both middlewares' call and main handler's call.
*
* @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 $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
* the wildcards that were originally passed, this newParams will
* be next passed to main handler
*/
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 ( is_callable( $handler ) ) {
$newParams = call_user_func_array( $handler, $matched ) ;

@ -187,7 +187,8 @@ Link::before('globalBefore');
Link::all(array(
// 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),
// Tickets
'/v1/tickets' => action(\Controllers\Tickets\CustomerTicketController::class),

Loading…
Cancel
Save