Skip to content

Commit 1723256

Browse files
committed
Proof of concept of first try checking
1 parent 4ecb53e commit 1723256

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/FormType/PuzzleSolvingTimeFormType.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Ramsey\Uuid\Uuid;
88
use SpeedPuzzling\Web\FormData\PuzzleSolvingTimeFormData;
99
use SpeedPuzzling\Web\Query\GetManufacturers;
10+
use SpeedPuzzling\Web\Results\PlayerProfile;
11+
use SpeedPuzzling\Web\Services\CheckFirstTryAvailability;
1012
use SpeedPuzzling\Web\Services\RetrieveLoggedUserProfile;
1113
use Symfony\Component\Form\AbstractType;
1214
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
@@ -35,6 +37,7 @@ public function __construct(
3537
readonly private RetrieveLoggedUserProfile $retrieveLoggedUserProfile,
3638
readonly private TranslatorInterface $translator,
3739
readonly private UrlGeneratorInterface $urlGenerator,
40+
readonly private CheckFirstTryAvailability $checkFirstTryAvailability,
3841
) {
3942
}
4043

@@ -179,12 +182,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
179182
'required' => false,
180183
]);
181184

182-
$builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event): void {
185+
$builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use ($userProfile): void {
183186
$form = $event->getForm();
184187
$data = $event->getData();
185188
assert($data instanceof PuzzleSolvingTimeFormData);
186189

187-
$this->applyDynamicRules($form, $data);
190+
$this->applyDynamicRules($form, $data, $userProfile);
188191
});
189192
}
190193

@@ -201,6 +204,7 @@ public function configureOptions(OptionsResolver $resolver): void
201204
private function applyDynamicRules(
202205
FormInterface $form,
203206
PuzzleSolvingTimeFormData $data,
207+
PlayerProfile $playerProfile,
204208
): void {
205209
// TODO: Should check if the puzzle exists in database as well
206210
if (is_string($data->puzzle) && Uuid::isValid($data->puzzle) === false) {
@@ -212,5 +216,14 @@ private function applyDynamicRules(
212216
$form->get('puzzlePhoto')->addError(new FormError($this->translator->trans('forms.puzzle_photo_is_required')));
213217
}
214218
}
219+
220+
if (is_string($data->puzzle) && Uuid::isValid($data->puzzle) === true && $data->firstAttempt === true) {
221+
$firstTry = $this->checkFirstTryAvailability->forPlayer($playerProfile->playerId, $data->puzzle);
222+
223+
if ($firstTry === false) {
224+
$form->get('firstAttempt')->addError(new FormError($this->translator->trans('Píčo tvůj first attempt už byl tady: ...')));
225+
$form->addError(new FormError('ASdfda fasdf asdf asdf asdf as'));
226+
}
227+
}
215228
}
216229
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SpeedPuzzling\Web\Services;
6+
7+
readonly final class CheckFirstTryAvailability
8+
{
9+
public function forPlayer(string $playerId, string $puzzleId): bool
10+
{
11+
return false;
12+
}
13+
}

0 commit comments

Comments
 (0)