From bcb52cd2e3b7e2ea8aa566ea08386c5d1dc9668e Mon Sep 17 00:00:00 2001 From: Guillaume Aubert Date: Wed, 9 Oct 2024 12:14:01 +0200 Subject: [PATCH] feat: Add field validation to prevent empty exercises from being set as answers --- src/controllers/exercise_controller.php | 2 +- src/views/manage_an_exercise.php | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/controllers/exercise_controller.php b/src/controllers/exercise_controller.php index a555a8c..6163acf 100644 --- a/src/controllers/exercise_controller.php +++ b/src/controllers/exercise_controller.php @@ -16,7 +16,7 @@ function createExercise() function setExerciseAsAnswering(int $id) { $exercise = new Exercises($id); - if ($exercise->getStatus() === Status::Building) { + if ($exercise->getStatus() === Status::Building && $exercise->getFieldsCount() > 0) { $exercise->setExerciseAs(Status::Answering); } header('Location: /exercises'); diff --git a/src/views/manage_an_exercise.php b/src/views/manage_an_exercise.php index f050ac6..6281e4d 100644 --- a/src/views/manage_an_exercise.php +++ b/src/views/manage_an_exercise.php @@ -28,8 +28,10 @@ getTitle() ?> - + getFieldsCount() > 0) {?> + +