src/Form/Type/AnnuaireRepreneursRechercheType.php line 22

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * @author Mehrez Labidi
  5.  */
  6. namespace App\Form\Type;
  7. use App\Helper\TransProvider;
  8. use App\Helper\Utils;
  9. use App\Repository\SecteursActiviteRepository;
  10. use App\Services\ManagerEntity\PaysManagers;
  11. use Psr\Cache\InvalidArgumentException;
  12. use Symfony\Component\Form\AbstractType;
  13. use Symfony\Component\Form\Extension\Core\Type\{ChoiceType,TextType,HiddenType};
  14.  
  15. use Symfony\Component\Form\FormBuilderInterface;
  16. use Symfony\Component\OptionsResolver\OptionsResolver;
  17. class AnnuaireRepreneursRechercheType extends AbstractType
  18. {
  19.     /**
  20.      * @var TransProvider
  21.      */
  22.     private $transProvider;
  23.     /**
  24.      * @var PaysManagers
  25.      */
  26.     private $paysManagers;
  27.     /**
  28.      * @var SecteursActiviteRepository
  29.      */
  30.     private $secteursActiviteRepository;
  31.     /**
  32.      * @param TransProvider $transProvider
  33.      * @param PaysManagers $paysManagers
  34.      * @param SecteursActiviteRepository $secteursActiviteRepository
  35.      */
  36.     public function __construct(TransProvider $transProviderPaysManagers $paysManagersSecteursActiviteRepository $secteursActiviteRepository)
  37.     {
  38.         $this->transProvider $transProvider;
  39.         $this->paysManagers $paysManagers;
  40.         $this->secteursActiviteRepository $secteursActiviteRepository;
  41.     }
  42.     /**
  43.      * @param FormBuilderInterface $builder
  44.      * @param array $options
  45.      * @return void
  46.      * @throws InvalidArgumentException
  47.      */
  48.     public function buildForm(FormBuilderInterface $builder, array $options)
  49.     {
  50.         $builder
  51.             ->add('id_pays'ChoiceType::class,
  52.                 [
  53.                     "required" => false,
  54.                     "choices" => $this->listPays(),
  55.                     "data" => Utils::firstValInArray($this->listPays()),
  56.                     "attr" => [
  57.                         "v-model" => 'id_pays'
  58.                         "class" => "form-control"
  59.                     ],
  60.                 ]
  61.             )
  62.             ->add('id_region'ChoiceType::class,
  63.                 [
  64.                     "choices" => [],
  65.                     "attr" => [
  66.                         "v-html" => "regionHtml"
  67.                         "class" => "form-control"
  68.                     ]
  69.                 ]
  70.             )
  71.             ->add('id_departement'ChoiceType::class,
  72.                 [
  73.                     "choices" => [],
  74.                     "attr" => [
  75.                         "v-html" => "departementHtml",
  76.                         "class" => "form-control"
  77.                     ]
  78.                 ]
  79.             )
  80.             ->add('id_secteur_activite_recherche_1'ChoiceType::class,
  81.                 [
  82.                     "required" => false,
  83.                     "choices" => $this->listSecteurLevel1(),
  84.                     "data" => Utils::firstValInArray($this->listSecteurLevel1()),
  85.                     "attr" => [
  86.                         "v-model" => 'id_secteur_activite_recherche_1'
  87.                         "class" => "form-control"
  88.                     ],
  89.                 ]
  90.             )
  91.             ->add('id_secteur_activite_recherche_2'ChoiceType::class,
  92.                 [
  93.                     "choices" => [],
  94.                     "attr" => [
  95.                         "v-html" => "secteur_activite_recherche_2_Html",
  96.                         "class" => "form-control"
  97.                     ]
  98.                 ]
  99.             )
  100.             ->add('id_secteur_activite_recherche_3'ChoiceType::class,
  101.                 [
  102.                     "choices" => [],
  103.                     "attr" => [
  104.                         "v-html" => "secteur_activite_recherche_3_Html",
  105.                         "class" => "form-control"
  106.                     ]
  107.                 ]
  108.             )
  109.             ->add('type_reprise'ChoiceType::class,
  110.                 [
  111.                     "choices" => $this->transChoice(Utils::reverseArrayKeyValueValueKey(FormChoices::typeReprise())),
  112.                      "attr" => [
  113.                         "class" => "form-control"
  114.                      ]
  115.                 ]
  116.             )
  117.             ->add('apport_min'ChoiceType::class,
  118.                 [
  119.                     "choices" => FormChoices::montantApportChoix(),
  120.                       "attr" => [
  121.                         "class" => "form-control"
  122.                      ],
  123.                     "data" => Utils::firstValInArray(FormChoices::montantApportChoix())
  124.                 ]
  125.             )
  126.             ->add('apport_max'ChoiceType::class,
  127.                 [
  128.                     "choices" => FormChoices::montantApportChoix(),
  129.                       "attr" => [
  130.                         "class" => "form-control"
  131.                      ],
  132.                     "data" => Utils::lastValInArray(FormChoices::montantApportChoix())
  133.                 ]
  134.             )
  135.             ->add('reference_mots_cles'TextType::class,
  136.                 [
  137.                     "required" => false,
  138.                     'attr' => array(
  139.                         'placeholder' => $this->transChoice('activite, competences, numero repreneur'),
  140.                           "class" => "form-control"
  141.                     )
  142.                 ]
  143.             )
  144.             ->add('mots_cle_exact'HiddenType::class, [
  145.                 "attr" => [
  146.                     "v-model" => 'mots_cle_exact'
  147.                 ]
  148.             ]);
  149.     }
  150.     /**
  151.      * @return string[]
  152.      */
  153.     private function listPays()
  154.     {
  155.         $list = [$this->transChoice("IndiffĂ©rent") => ""];
  156.         $data $this->paysManagers->getListPaysCVsRepreneurs(true);
  157.         foreach ($data as $pays) {
  158.             $list[$pays["nom_pays"]] = $pays["id_localisation"];
  159.         }
  160.         return $list;
  161.     }
  162.     /**
  163.      * @param $var
  164.      * @return mixed|string
  165.      */
  166.     private function transChoice($var)
  167.     {
  168.         if (is_string($var)) {
  169.             $var $this->transProvider
  170.                 ->translate($var"""M");
  171.         }
  172.         if (is_array($var)) {
  173.             foreach ($var as $key => $item) {
  174.                 unset($var[$key]);
  175.                 $key $this->transProvider
  176.                     ->translate($key"""M");
  177.                 $var[$key] = $item;
  178.             }
  179.         }
  180.         return $var;
  181.     }
  182.     /**
  183.      * @return string[]
  184.      * @throws InvalidArgumentException
  185.      */
  186.     private function listSecteurLevel1()
  187.     {
  188.         $list = [$this->transChoice("IndiffĂ©rent") => ""];
  189.         $data $this->secteursActiviteRepository->getNomSecteurActivitieLevel1();
  190.         foreach ($data as $secteur) {
  191.             $list[$secteur["nomSecteurActivite"]] = $secteur["idSecteurActivite"];
  192.         }
  193.         return $list;
  194.     }
  195.     /**
  196.      * @param OptionsResolver $resolver
  197.      * @return void
  198.      */
  199.     public function configureOptions(OptionsResolver $resolver)
  200.     {
  201.         $resolver->setDefaults([
  202.             'validation_groups' => false,
  203.             'data_class' => null
  204.             'csrf_protection' => false,
  205.             'allow_extra_fields' => true,
  206.         ]);
  207.     }
  208.     /**
  209.      * @return string
  210.      */
  211.     public function getBlockPrefix()
  212.     { // pour unifier avec les inputs definis dans html
  213.         return '';
  214.     }
  215. }