diff --git a/src/Controllers/BenchmarkController.php b/src/Controllers/BenchmarkController.php index 634c009..9ca5e97 100644 --- a/src/Controllers/BenchmarkController.php +++ b/src/Controllers/BenchmarkController.php @@ -60,4 +60,32 @@ class BenchmarkController extends Controller { ->withStatus(302); } + public function getEdit(Request $request, Response $response, array $args): Response { + $benchmark = Benchmark::where('id', $args['benchmark_id'])->first(); + + $view = Twig::fromRequest($request); + return $view->render($response, 'benchmark/edit.twig', [ + 'benchmark' => $benchmark, + ]); + } + + public function postEdit(Request $request, Response $response, array $args): Response { + $benchmark = Benchmark::where('id', $args['benchmark_id'])->first(); + + $params = (array)$request->getParsedBody(); + + $benchmark->name = $params['benchmark_name']; + $benchmark->description = $params['benchmark_description']; + $benchmark->scoring = $params['benchmark_scoring']; + + $benchmark->save(); + + // redirect the user back to the home page + $routeContext = RouteContext::fromRequest($request); + $routeParser = $routeContext->getRouteParser(); + return $response + ->withHeader('Location', $routeParser->urlFor('benchmark.view', ['benchmark_id' => $benchmark->id])) + ->withStatus(302); + } + } diff --git a/src/routes.php b/src/routes.php index 8571b73..557219d 100644 --- a/src/routes.php +++ b/src/routes.php @@ -9,7 +9,13 @@ $app->group('/benchmark', function(RouteCollectorProxy $group) { $group->get('/list', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:getList')->setName('benchmark.list'); $group->get('/add', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:getAdd')->setName('benchmark.add'); $group->post('/add', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:postAdd'); - $group->get('/{benchmark_id}', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:getView')->setName('benchmark.view'); + + $group->group('/{benchmark_id}', function(RouteCollectorProxy $benchmark) { + $benchmark->get('', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:getView')->setName('benchmark.view'); + + $benchmark->get('/edit', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:getEdit')->setName('benchmark.edit'); + $benchmark->post('/edit', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:postEdit'); + }); }); $app->group('/component', function(RouteCollectorProxy $group) { diff --git a/views/benchmark/edit.twig b/views/benchmark/edit.twig new file mode 100644 index 0000000..c224079 --- /dev/null +++ b/views/benchmark/edit.twig @@ -0,0 +1,46 @@ +{% extends 'layout.twig' %} + +{% block title %}Editing Benchmark: {{ benchmark.name }}{% endblock %} + +{% block content %} + +
+
+

Editing Benchmark: {{ benchmark.name }}

+
+
+ +
+
+
+
+
+ + +
+ +
+ +
+
+ +
+
+ + +
+
+ + +
+
+
+ +{% endblock %} diff --git a/views/benchmark/view.twig b/views/benchmark/view.twig index b006cd1..5cc6267 100644 --- a/views/benchmark/view.twig +++ b/views/benchmark/view.twig @@ -6,6 +6,7 @@

{{ benchmark.name }}

+

Edit

{{ benchmark.description }}