Skip to content

Commit

Permalink
feat: Add field validation to prevent empty exercises from being set …
Browse files Browse the repository at this point in the history
…as answers
  • Loading branch information
Guillaume1868 committed Oct 9, 2024
1 parent 26856ef commit bcb52cd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/controllers/exercise_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
6 changes: 4 additions & 2 deletions src/views/manage_an_exercise.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
<tr>
<td><?= $exercise->getTitle() ?></td>
<td>
<a title="Be ready for answers" rel="nofollow" data-method="put"
href="/exercises/<?= $exercise->getId() ?>?exercise%5Bstatus%5D=answering"><i class="fa fa-comment"></i></a>
<?php if ($exercise->getFieldsCount() > 0) {?>
<a title="Be ready for answers" rel="nofollow" data-method="put"
href="/exercises/<?= $exercise->getId() ?>?exercise%5Bstatus%5D=answering"><i class="fa fa-comment"></i></a>
<?php }?>
<a title="Manage fields" href="/exercises/<?= $exercise->getId() ?>/fields"><i class="fa fa-edit"></i></a>
<a data-confirm="Are you sure?" title="Destroy" rel="nofollow" data-method="delete"
href="/exercises/<?= $exercise->getId() ?>"><i class="fa fa-trash"></i></a>
Expand Down

0 comments on commit bcb52cd

Please sign in to comment.