Added ability to edit benchmarks
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user