src/Form/UserFormType.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\User;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\FormBuilderInterface;
  6. use Vich\UploaderBundle\Form\Type\VichImageType;
  7. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  8. use Symfony\Component\OptionsResolver\OptionsResolver;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Symfony\Component\Form\Extension\Core\Type\DateType;
  11. use Symfony\Component\Form\Extension\Core\Type\TextType;
  12. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  13. use Symfony\Component\Form\Extension\Core\Type\CountryType;
  14. use Symfony\Component\Security\Core\Security;
  15. class UserFormType extends AbstractType
  16. {
  17.     private $security;
  18.     public function __construct(Security $security)
  19.     {
  20.         $this->security $security;
  21.     }
  22.     public function buildForm(FormBuilderInterface $builder, array $options): void
  23.     {
  24.         $user $this->security->getUser();
  25.         $builder
  26.             ->add('phoneNumber')
  27.            
  28.             ->add('fullName'TextType::class, [
  29.                 'label' => 'Nom complet',
  30.                 'required' => true,
  31.                 'constraints' => new Assert\NotBlank(),
  32.                 'trim' => true])
  33.            
  34.             ->add('birthday'DateType::class, [
  35.                 'label' => 'Date de naissance',
  36.                 
  37.                 'html5' => true,
  38.                 'widget' => 'single_text',
  39.                 'constraints' => new Assert\Date(),
  40.                 'required' => true,
  41.                 'constraints' => new Assert\NotBlank(),
  42.                 'trim' => true])
  43.             ->add('gender'ChoiceType::class, array(
  44.                 'constraints' => new Assert\NotBlank(),
  45.                 'choices' => array(
  46.                     'FEMME' => 1,
  47.                     'HOMME' => 0,
  48.                 ), 'label' => 'Sexe'))
  49.             ->add('birthplace')
  50.             ->add('phoneNumber'TextType::class, [
  51.                 'label' => 'Téléphone',
  52.                 'required' => false,
  53.                 'trim' => true])
  54.             ->add('nationality'CountryType::class, [
  55.                 'label' => 'Nationalité',
  56.                 'required' => true,
  57.                 'constraints' => new Assert\NotBlank(),
  58.                 'trim' => true])
  59.             ->add('location'TextType::class, [
  60.                 'label' => 'Résidence',
  61.                 'required' => true,
  62.                 'constraints' => new Assert\NotBlank(),
  63.                 'trim' => true])
  64.             ->add('academicLevel'ChoiceType::class, array(
  65.                 'constraints' => new Assert\NotBlank(),
  66.                 'choices' => array(
  67.                     'BAC' => 'BACCALAUREAT',
  68.                     'LICENCE' => 'LICENCE',
  69.                     'MASTER' => 'MASTER',
  70.                     'IET' => 'IET',
  71.                     'DOCTORAT' => 'DOCTORAT',
  72.                 ), 'label' => 'Niveau  académique'))
  73.             ->add('numCni'TextType::class, [
  74.                 'label' => 'Numéro de CNI',
  75.                 'required' => true,
  76.                 'constraints' => new Assert\NotBlank(),
  77.                 'trim' => true])
  78.            
  79.             ->add('region'ChoiceType::class, array(
  80.                 'constraints' => new Assert\NotBlank(),
  81.                 'choices' => array(
  82.                     'Adamaoua' => 'Adamaoua',
  83.                     'Centre' => 'Centre',
  84.                     'Est' => 'Est',
  85.                     'Extrême-Nord' => 'Extrême-Nord',
  86.                     'Littoral' => 'Littoral',
  87.                     'Nord' => 'Nord',
  88.                     'Nord-Ouest' => 'Nord-Ouest',
  89.                     'Ouest' => 'Ouest',
  90.                     'Sud' => 'Sud',
  91.                     'Sud-Ouest' => 'Sud-Ouest',
  92.                 ), 'label' => 'Region d\'origine'))
  93.                 ->add('department'TextType::class, [
  94.                     'label' => 'Departement d\'origine',
  95.                     'required' => true,
  96.                     'constraints' => new Assert\NotBlank(),
  97.                     'trim' => true])
  98.             
  99.             ->add('domain')
  100.             ->add('securityQuestion'ChoiceType::class, array(
  101.                 'constraints' => new Assert\NotBlank(),
  102.                 'choices' => array(
  103.                     'Numero de CNI?' => 'cin_number',
  104.                      'Quelle est la ville de naissance de maman?'=> 'mother_birthplace',
  105.                    'Le metier dont tu reves d\'exercer depuis ton enfance?'=> 'favorite_job' ,
  106.                     'Quel est ton quartier de residence?' =>'residence' ,
  107.                 ), 'label' => 'Question de securite'))
  108.                 ->add('securityAnswer'TextType::class, [
  109.                     'label' => 'Réponse à la question de sécurité',
  110.                     'required' => true,
  111.                 ]);
  112.                 if ($this->security->isGranted('ROLE_ADMIN')) {
  113.                     $builder
  114.                     ->add('email')
  115.                     ->add('status'ChoiceType::class, array(
  116.                         'constraints' => new Assert\NotBlank(),
  117.                         'choices' => array(
  118.                             'ADMINISTRATEUR' => 'ADMIN',
  119.                             'ELEVE' => 'ELEVE',
  120.                             'ENSEIGNANT' => 'PROF',
  121.                             'FINANCE' => 'FINANCE',
  122.                             'PREFET d\'ETUDES' => 'PREFET',
  123.                             'PRINCIPAL' => 'PRINCIPAL',
  124.                         ), 'label' => 'Fonction'));
  125.                 }
  126.                    
  127.     
  128.           
  129.         ;
  130.     }
  131.     public function configureOptions(OptionsResolver $resolver): void
  132.     {
  133.         
  134.         $resolver->setDefaults([
  135.             'data_class' => User::class,
  136.         ]);
  137.     }
  138. }