Added ticket edit action
This commit is contained in:
@ -4,6 +4,7 @@ namespace BitGoblin\Goliath\Controllers;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Slim\Routing\RouteContext;
|
||||
use Slim\Views\Twig;
|
||||
use BitGoblin\Goliath\Models\Ticket;
|
||||
|
||||
@ -40,4 +41,32 @@ class TicketController extends Controller {
|
||||
->withStatus(302);
|
||||
}
|
||||
|
||||
public function getEdit(Request $request, Response $response, array $args): Response {
|
||||
$ticket = Ticket::where('id', $args['ticket_id'])->get();
|
||||
|
||||
$view = Twig::fromRequest($request);
|
||||
return $view->render($response, 'ticket/edit.twig', [
|
||||
'ticket' => $ticket[0],
|
||||
]);
|
||||
}
|
||||
|
||||
public function postEdit(Request $request, Response $response, array $args): Response {
|
||||
$ticket = Ticket::where('id', $args['ticket_id'])->first();
|
||||
|
||||
$params = (array)$request->getParsedBody();
|
||||
$ticket->title = $params['ticket_title'];
|
||||
$ticket->body = $params['ticket_body'];
|
||||
$ticket->severity = $params['ticket_severity'];
|
||||
$ticket->due_at = $params['ticket_due'];
|
||||
|
||||
$ticket->save();
|
||||
|
||||
// redirect the user back to the home page
|
||||
$routeContext = RouteContext::fromRequest($request);
|
||||
$routeParser = $routeContext->getRouteParser();
|
||||
return $response
|
||||
->withHeader('Location', $routeParser->urlFor('ticket.view', ['ticket_id' => $ticket->id]))
|
||||
->withStatus(302);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user