<?php
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use App\Repository\paysRepository;
use App\Repository\ResidenceRepository;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3;
use App\Entity\pays;
class ContactType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('recaptcha', Recaptcha3Type::class, [
'constraints' => new Recaptcha3(['message' => 'There were problems with your captcha. Please try again or contact with support and provide following code(s): {{ errorCodes }}']),
'action_name' => 'contact',
])
->add('nom', TextType::class, array(
'label' => false,
'attr' => array('class' => 'form-control')
)
)
->add('prenom', TextType::class, array(
'label' => false,
'attr' => array('class' => 'form-control')
)
)
->add('email', EmailType::class, array(
'label' => false,
'attr' => array('class' => 'form-control')
)
)
->add('societe', TextType::class, array(
'label' => false,
'required' => false,
'attr' => array('class' => 'form-control')
)
)
->add('pays', EntityType::class, array(
'label' => false,
'attr' => array('class' => 'form-control'),
'class' => pays::class,
'query_builder' => function (paysRepository $er) {
return $er->createQueryBuilder('p')
->where('p.etat = 1');
},
'choice_label' => 'nom',
'preferred_choices' => $options['default_country']
))
->add('telephone', TextType::class, array(
'label' => false,
'required' => false,
'attr' => array('class' => 'form-control'))
)
->add('message', TextareaType::class, array('label' => false, 'attr' => array('class' => 'form-control width-100')))
;
if($options['slug'] == null) {
$builder->add('objet', TextType::class, array(
'label' => false,
'attr' => array('class' => 'form-control')
));
} else {
switch($options['slug']) {
case "ce-collectivites" :
case "groupe-seminaire":
$choices = array("contact.objet.choix.demande_devis" => "Demande de devis", "contact.objet.choix.besoin_infos" => "Informations");
break;
case "sejour-longue-duree":
$choices = array("contact.objet.choix.prise_contact" => "Prise de contact", "contact.objet.choix.demande_tarifs" => "Demande de tarif");
break;
}
$builder->add('objet', ChoiceType::class, array(
"label" => false,
'attr' => array('class' => 'form-control'),
"choices" => $choices,
'multiple' => false,
'expanded' => false,
'translation_domain' => 'form',
'choice_translation_domain' => true
));
if($options['slug'] == "groupe-seminaire") {
$choices = array("contact.occasion.choix.seminaire" => "Séminaire", "contact.occasion.choix.incentive" => "Incentive", "contact.occasion.choix.congres" => "Congrès", "contact.occasion.choix.mariage" => "Mariage", "contact.occasion.choix.anniversaire" => "Anniversaire", "contact.occasion.choix.bapteme" => "Baptème", "contact.occasion.choix.autre" => "Autre");
$builder
/*
->add('residence', EntityType::class, array(
'label' => false,
'attr' => array('class' => 'form-control'),
'class' => 'App:residence',
'query_builder' => function (ResidenceRepository $er) {
return $er->createQueryBuilder('p')->where('p.iscontact = 1');
},
'choice_label' => 'nom'
))
*/
->add('occasion', ChoiceType::class, array(
"label" => false,
'attr' => array('class' => 'form-control'),
"choices" => $choices,
'multiple' => false,
'expanded' => false,
'translation_domain' => 'form',
'choice_translation_domain' => 'form'
))
->add('nbparticipants', IntegerType::class, [
'required' => false,
'attr' => array('class' => 'form-control'),
])
->add('datearrivee', DateType::class, array(
"label" => false,
'html5' => false,
'widget' => 'single_text',
'format' => 'dd/MM/yyyy',
'html5' => false,
'required' => false,
'attr' => array('class' => 'datepicker form-control')
))
->add('nbnuits', IntegerType::class, [
'required' => false,
'attr' => array('class' => 'form-control'),
]);
} else {
/*
$builder
->add('residence', EntityType::class, array(
'label' => false,
'attr' => array('class' => 'form-control'),
'class' => 'App:residence',
'query_builder' => function (ResidenceRepository $er) {
return $er->createQueryBuilder('p');
},
'choice_label' => 'nom'
));
*/
}
}
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => null,
'slug' => null,
'default_country' => null
));
}
}