Commit 591e039d authored by Clouard Regis's avatar Clouard Regis
Browse files

Refactored Form

parent 3f0fe848
<?php
namespace App\Form;
use App\Entity\EventCourse;
use App\Entity\User;
use phpDocumentor\Reflection\Types\Integer;
......@@ -15,13 +13,12 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\TimeType;
use Symfony\Component\OptionsResolver\OptionsResolver;
// TODO
class EventCourseType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$courses = [];
foreach ($options['user']->getCourses() as $course){
foreach ($options['user']->getCourses() as $course) {
$courses[$course->getName()] = $course;
}
$builder
......@@ -47,11 +44,15 @@ class EventCourseType extends AbstractType
)
->add('missingPunchPenalty', TextType::class, ['label' => "form.eventCourse.missingPunchPenalty",])
->add('overTimePenalty', TextType::class, ['label' => "form.eventCourse.overTimePenalty",])
->add('time', TimeType::class, [
'input' => 'timestamp',
'widget' => 'choice',
'label' => "form.eventCourse.maxTime",
]);
->add(
'time',
TimeType::class,
[
'input' => 'timestamp',
'widget' => 'choice',
'label' => "form.eventCourse.maxTime",
]
);
}
public function configureOptions(OptionsResolver $resolver)
......
<?php
namespace App\Form;
use App\Entity\Event;
......@@ -10,7 +9,6 @@ use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
// TODO
class EventType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
......@@ -30,6 +28,7 @@ class EventType extends AbstractType
]
);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
......
......@@ -10,7 +10,6 @@ use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
// TODO
class GpxImportType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
......
......@@ -10,7 +10,6 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
// TODO
class ManuallySetPenaltyOfParticipantMakeEventCourseType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
......@@ -18,22 +17,26 @@ class ManuallySetPenaltyOfParticipantMakeEventCourseType extends AbstractType
$event = $options['event'];
$participants = [];
$participants["-"] = null;
foreach ($options['event']->getParticipants() as $participant) {
foreach ($event->getParticipants() as $participant) {
$participants[$participant->getNickName()] = $participant;
}
$eventCourses = [];
$eventCourses["-"] = null;
foreach ($options['event']->getEventCourses() as $eventCourse) {
foreach ($event->getEventCourses() as $eventCourse) {
$eventCourses[$eventCourse->getCourse()->getName()] = $eventCourse;
}
$builder
->add('participant', ChoiceType::class,
->add(
'participant',
ChoiceType::class,
[
'label' => "form.ManuallySetPenalty.participant",
'choices' => $participants,
]
)
->add('eventCourse', ChoiceType::class,
->add(
'eventCourse',
ChoiceType::class,
[
'label' => "form.ManuallySetPenalty.eventCourse",
'choices' => $eventCourses,
......
......@@ -3,8 +3,6 @@
namespace App\Form;
use App\Model\ModifyEventCourse;
use App\Entity\User;
use phpDocumentor\Reflection\Types\Integer;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
......@@ -12,13 +10,13 @@ use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\TimeType;
use Symfony\Component\OptionsResolver\OptionsResolver;
// TODO
class ModifyEventCourseType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('id', HiddenType::class,)
->add('id', HiddenType::class)
->add(
'format',
ChoiceType::class,
......@@ -32,11 +30,15 @@ class ModifyEventCourseType extends AbstractType
)
->add('missingPunchPenalty', TextType::class, ['label' => "form.eventCourse.missingPunchPenalty",])
->add('overTimePenalty', TextType::class, ['label' => "form.eventCourse.overTimePenalty",])
->add('time', TimeType::class, [
'input' => 'timestamp',
'widget' => 'choice',
'label' => "form.eventCourse.maxTime",
]);
->add(
'time',
TimeType::class,
[
'input' => 'timestamp',
'widget' => 'choice',
'label' => "form.eventCourse.maxTime",
]
);
}
public function configureOptions(OptionsResolver $resolver)
......
......@@ -11,7 +11,6 @@ use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
// TODO
class ModifyParticipantMakeEventCourseType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
......@@ -24,27 +23,26 @@ class ModifyParticipantMakeEventCourseType extends AbstractType
if (array_key_exists($track->getName(), $duplicates)) {
if ($duplicates[$track->getName()] === 1) {
$timeOfTheTrack = $tracksSimple[$track->getName()]->getTotalTimeInHMS();
$tracks[$track->getName() . " [1] (" . $timeOfTheTrack . ")"] = $tracks[$track->getName() . " (" . $timeOfTheTrack . ")"];
unset($tracks[$track->getName() . " (" . $timeOfTheTrack . ")"]);
$tracks[$track->getName()." [1] (".$timeOfTheTrack.")"] = $tracks[$track->getName()." (".$timeOfTheTrack.")"];
unset($tracks[$track->getName()." (".$timeOfTheTrack.")"]);
}
$duplicates[$track->getName()] += 1;
$tracks[$track->getName() . " [" . $duplicates[$track->getName()] . "] (" . $track->getTotalTimeInHMS() . ")"] = $track;
$tracks[$track->getName()." [".$duplicates[$track->getName()]."] (".$track->getTotalTimeInHMS().")"] = $track;
} else {
$tracks[$track->getName() . " (" . $track->getTotalTimeInHMS() . ")"] = $track;
$tracks[$track->getName()." (".$track->getTotalTimeInHMS().")"] = $track;
$tracksSimple[$track->getName()] = $track;
$duplicates[$track->getName()] = 1;
}
}
$builder
->add(
'track',
ChoiceType::class,
[
'label' => "form.modifyParticipantMakeEventCourse.track",
'choices' => $tracks,
]
)
$builder->add(
'track',
ChoiceType::class,
[
'label' => "form.modifyParticipantMakeEventCourse.track",
'choices' => $tracks,
]
)
->add('participantId', HiddenType::class, ['data' => $options['participant']])
->add('eventCourseId', HiddenType::class, ['data' => $options['eventCourse']]);
}
......
......@@ -8,14 +8,13 @@ use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
// TODO
class ParticipantType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('nickname', TextType::class, ['label' => "form.participant.name",]);
$builder->add('nickname', TextType::class, ['label' => "form.participant.name",]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
......
......@@ -11,7 +11,6 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
// TODO
class PlannerType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment