<?php
namespace App\Form;
use App\Entity\Country;
use App\Entity\Referee;
use App\Repository\CountryRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Validator\Constraints\IsTrue;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\BirthdayType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
class RegistrationFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('gender', ChoiceType::class, [
'choices' => [
'Mme' => 0,
'Mr.' => 1,
],
'row_attr' => ['class' => 'mb-3 col-lg-2 col-sm-5'],
'label' => 'Gender',
'label_attr' => ['class' => 'radio-inline'],
'multiple' => false,
'expanded' => true,
])
->add('firstname', TextType::class, [
'row_attr' => ['class' => 'mb-3 col-lg-5 col-sm-6'],
'label' => 'Fist Name (Second name)',
])
->add('lastname', TextType::class, [
'row_attr' => ['class' => 'mb-3 col-lg-5 col-sm-5'],
'label' => 'Last Name',
])
->add('email', TextType::class, [
'row_attr' => ['class' => 'mb-3 col-lg-6 col-sm-12'],
'label' => 'Email',
])
->add('birthday', BirthdayType::class, [
'row_attr' => ['class' => 'mb-3 col-lg-6 col-sm-12'],
'label' => 'Birthday',
'required' => false,
])
->add('phone1', TelType::class, [
'row_attr' => ['class' => 'mb-3 col-lg-6 col-sm-12'],
'label' => 'Phone Number',
])
->add('phone2', TelType::class, [
'row_attr' => ['class' => 'mb-3 col-lg-6 col-sm-12'],
'label' => 'Phone Number 2',
'required' => false,
])
->add('kyorugiNumber', TextType::class, [
'row_attr' => ['class' => 'mb-3 col-lg-4 col-sm-8'],
'label' => 'KYORUGI IR Number',
'required' => false,
])
->add('kyorugiClass', ChoiceType::class, [
'row_attr' => ['class' => 'mb-3 col-lg-2 col-sm-4'],
'label' => 'KYORUGI RANK',
'choices' => [
'P' => 'P',
'3' => 3,
'2' => 2,
'1' => 1,
'S' => 'S',
],
'required' => false,
])
->add('poomsaeNumber', TextType::class, [
'row_attr' => ['class' => 'mb-3 col-lg-4 col-sm-8'],
'label' => 'POOMSAE IR Number',
'required' => false,
])
->add('poomsaeClass', ChoiceType::class, [
'row_attr' => ['class' => 'mb-3 col-lg-2 col-sm-4'],
'label' => 'POOMSAE RANK',
'choices' => [
'P' => 'P',
'3' => 3,
'2' => 2,
'1' => 1,
'S' => 'S',
],
'required' => false,
])
->add('avatar', FileType::class, [
'data_class' => null,
'row_attr' => ['class' => 'mb-3 col-lg-4 col-sm-12', 'format' => 'img', 'dir' => 'profiles'],
'label' => 'Photo',
'required' => false,
])
->add('kyorugiIRCard', FileType::class, [
'data_class' => null,
'row_attr' => ['class' => 'mb-3 col-lg-4 col-sm-12', 'format' => 'img', 'dir' => 'badges'],
'label' => 'Kyorugi IR Card',
'required' => false,
])
->add('poomsaeIRCard', FileType::class, [
'data_class' => null,
'row_attr' => ['class' => 'mb-3 col-lg-4 col-sm-12', 'format' => 'img', 'dir' => 'badges'],
'label' => 'Poomsae IR Card',
'required' => false,
])
->add('country', EntityType::class, [
'row_attr' => ['class' => 'mb-3 col-lg-6 col-sm-12'],
'label' => 'Country',
'class' => Country::class,
'choice_label' => 'name',
])
->add('country', EntityType::class, [
'class' => Country::class,
'query_builder' => function (CountryRepository $er) {
$qb = $er->createQueryBuilder('country')
->innerJoin('country.continent', 'continent')
->orderBy('country.name', 'ASC');
return $qb;
},
'group_by' => function (Country $country) {
return $country->getContinent()->getName();
},
'row_attr' => ['class' => 'mb-3 col-lg-6 col-sm-12'],
'label' => 'Country',
'choice_label' => 'name',
])
->add('secondcountry', EntityType::class, [
'class' => Country::class,
'query_builder' => function (CountryRepository $er) {
$qb = $er->createQueryBuilder('country')
->innerJoin('country.continent', 'continent')
->orderBy('country.name', 'ASC');
return $qb;
},
'group_by' => function (Country $country) {
return $country->getContinent()->getName();
},
'row_attr' => ['class' => 'mb-3 col-lg-6 col-sm-12'],
'label' => 'Second Country',
'choice_label' => 'name',
])
// ->add('agreeTerms', CheckboxType::class, [
// 'mapped' => false,
// 'constraints' => [
// new IsTrue([
// 'message' => 'You should agree to our terms.',
// ]),
// ],
// ])
->add('plainPassword', PasswordType::class, [
// instead of being set onto the object directly,
// this is read and encoded in the controller
'mapped' => false,
'attr' => ['autocomplete' => 'new-password'],
'constraints' => [
new NotBlank([
'message' => 'Please enter a password',
]),
new Length([
'min' => 6,
'minMessage' => 'Your password should be at least {{ limit }} characters',
// max length allowed by Symfony for security reasons
'max' => 4096,
]),
],
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Referee::class,
]);
}
}