src/Controller/Content/Formulaire/FormulaireCrudController.php line 147

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Content\Formulaire;
  3. use App\Entity\Formulaire;
  4. use App\Entity\FormulaireChamp;
  5. use App\Entity\FormulaireChampLiee;
  6. use App\Entity\FormulaireEtape;
  7. use App\Entity\FormulaireInput;
  8. use App\Entity\Projet;
  9. use Doctrine\ORM\QueryBuilder;
  10. use Doctrine\Persistence\ManagerRegistry;
  11. use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
  12. use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
  13. use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
  14. use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
  15. use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
  16. use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
  17. use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
  18. use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
  19. use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
  20. use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
  21. use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
  22. use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
  23. use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
  24. use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
  25. use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
  26. use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
  27. use Flasher\SweetAlert\Prime\SweetAlertFactory;
  28. class FormulaireCrudController extends AbstractCrudController
  29. {
  30.     private ManagerRegistry $manager;
  31.     private SweetAlertFactory $flasher;
  32.     private AdminContextProvider $adminContextProvider;
  33.     private AdminUrlGenerator $adminUrlGenerator;
  34.     public function __construct(
  35.         ManagerRegistry $manager,
  36.         AdminContextProvider $adminContextProvider,
  37.         AdminUrlGenerator $adminUrlGenerator,
  38.         SweetAlertFactory $flasher
  39.     ) {
  40.         $this->manager $manager;
  41.         $this->adminContextProvider $adminContextProvider;
  42.         $this->adminUrlGenerator $adminUrlGenerator;
  43.         $this->flasher $flasher;
  44.     }
  45.     public static function getEntityFqcn(): string
  46.     {
  47.         return Formulaire::class;
  48.     }
  49.     public function configureFields(string $pageName): iterable
  50.     {
  51.         return [
  52.             FormField::addPanel(''),
  53.             IdField::new('id')->setSortable(false)->onlyOnIndex(),
  54.             TextField::new('nom')->stripTags()->setSortable(false)->setColumns('col-sm-12 col-lg-6 col-xxl-6'),
  55.             TextField::new('titre')->stripTags()->setSortable(false)->setColumns('col-sm-12 col-lg-6 col-xxl-6'),
  56.             TextareaField::new('descriptionDebut')->setSortable(false)->hideOnIndex()->setColumns('col-sm-12 col-lg-6 col-xxl-6'),
  57.             TextareaField::new('descriptionFin')->setSortable(false)->hideOnIndex()->setColumns('col-sm-12 col-lg-6 col-xxl-6'),
  58.             /* 
  59.             AssociationField::new('pages')->setSortable(false)
  60.                 ->setQueryBuilder(function (QueryBuilder $queryBuilder) {
  61.                     $projet = $this->manager->getRepository(Projet::class)->findOneBy(
  62.                         ['id' => $this->getUser()->getProjet()->getId()]
  63.                     );
  64.                     $queryBuilder
  65.                         ->andWhere('entity.projet = :val')
  66.                         ->setParameter('val', $projet);
  67.                 })->hideOnIndex()->setColumns('col-sm-6 col-lg-6 col-xxl-6'),
  68.             AssociationField::new('articles')->setSortable(false)
  69.                 ->setQueryBuilder(function (QueryBuilder $queryBuilder) {
  70.                     $projet = $this->manager->getRepository(Projet::class)->findOneBy(
  71.                         ['id' => $this->getUser()->getProjet()->getId()]
  72.                     );
  73.                     $queryBuilder
  74.                         ->join('entity.type', 'type')
  75.                         ->andWhere('type.projet = :val')
  76.                         ->setParameter('val', $projet);
  77.                 })->hideOnIndex()->setColumns('col-sm-6 col-lg-6 col-xxl-6'),
  78.                 */
  79.             AssociationField::new('projet')->setCssClass('d-none')->setSortable(false)
  80.                 ->setColumns('col-sm-6 col-lg-4 col-xxl-4')
  81.                 ->setQueryBuilder(function (QueryBuilder $queryBuilder) {
  82.                     $queryBuilder->andWhere('entity.id = :val')->setParameter('val'$this->getUser()->getProjet()->getId());
  83.                 })
  84.                 ->hideOnIndex()
  85.                 ->hideOnDetail()
  86.                 ->hideWhenUpdating(),
  87.             FormField::addPanel('Étapes')->onlyWhenUpdating(),
  88.         ];
  89.     }
  90.     public function createIndexQueryBuilder(SearchDto $searchDtoEntityDto $entityDtoFieldCollection $fieldsFilterCollection $filters): QueryBuilder
  91.     {
  92.         $queryBuilder parent::createIndexQueryBuilder($searchDto$entityDto$fields$filters);
  93.         $projet $this->manager->getRepository(Projet::class)->findOneBy(
  94.             ['id' => $this->getUser()->getProjet()->getId()]
  95.         );
  96.         if (=== count($searchDto->getSort())) {
  97.             $queryBuilder
  98.                 ->andWhere('entity.projet = :val')->setParameter('val'$projet);
  99.         }
  100.         return $queryBuilder;
  101.     }
  102.     public function configureCrud(Crud $crud): Crud
  103.     {
  104.         return $crud
  105.             // the labels used to refer to this entity in titles, buttons, etc.
  106.             ->overrideTemplate('crud/index''content/formulaire/index.html.twig')
  107.             ->overrideTemplate('crud/edit''content/formulaire/crud/edit.html.twig')
  108.             ->showEntityActionsInlined()
  109.             ->renderContentMaximized()
  110.             ->setPaginatorPageSize(30);
  111.     }
  112.     public function configureActions(Actions $actions): Actions
  113.     {
  114.         $preview Action::new('Aperçu')
  115.             ->linkToRoute('app_formulaire_preview', function (Formulaire $form): array {
  116.                 return [
  117.                     'formid' => $form->getId(),
  118.                     'projectid' => $this->getUser()->getProjet()->getId(),
  119.                     //'method' => $order->getUser()->getPreferredSendingMethod(),
  120.                 ];
  121.             })
  122.             ->addCssClass('btn crud-action-preview px-2 py-1 ')
  123.             ->setIcon('fa fa-binoculars')
  124.             ->setHtmlAttributes(['target' => '_blank']);
  125.         $previewedit Action::new('Aperçu')
  126.             ->linkToRoute('app_formulaire_preview', function (Formulaire $form): array {
  127.                 return [
  128.                     'formid' => $form->getId(),
  129.                     'projectid' => $this->getUser()->getProjet()->getId(),
  130.                     //'method' => $order->getUser()->getPreferredSendingMethod(),
  131.                 ];
  132.             })
  133.             ->addCssClass('btn btn-info px-2 py-1 ')
  134.             ->setIcon('fa fa-binoculars')
  135.             ->setHtmlAttributes(['target' => '_blank']);
  136.         $crudEtape Action::new('Etapes')
  137.             ->linkToCrudAction('toFormulaireEtape')
  138.             ->addCssClass('btn crud-action-content px-2 py-1 ')
  139.             ->setIcon('fa fa-list-ol');
  140.         $crudChamps Action::new('Champs')
  141.             ->linkToCrudAction('toFormulaireChamps')
  142.             ->addCssClass('btn btn-light px-2 py-1 ')
  143.             ->setIcon('fa fa-clipboard-list')
  144.             ->createAsGlobalAction();
  145.         return $actions
  146.             // ->add(Crud::PAGE_INDEX, $crudEtape)
  147.             // ->add(Crud::PAGE_INDEX, $crudChamps)
  148.             ->add(Crud::PAGE_INDEX$preview)
  149.             ->add(Crud::PAGE_EDIT$previewedit)
  150.             ->add(Crud::PAGE_NEWAction::SAVE_AND_CONTINUE)
  151.             ->update(Crud::PAGE_NEWAction::SAVE_AND_CONTINUE, function (Action $action) {
  152.                 return $action->setLabel('Créer et ajouter étape')->addCssClass('btn btn-info px-2 py-1 ');
  153.             })
  154.             /* ->update(Crud::PAGE_INDEX, Action::DETAIL, function (Action $action) {
  155.                 return $action->setIcon('fa fa-info')->addCssClass('btn crud-action-details px-2 py-1 ');
  156.             }) */
  157.             ->update(Crud::PAGE_INDEXAction::EDIT, function (Action $action) {
  158.                 return $action->setIcon('fa fa-pen')->addCssClass('btn crud-action-edit px-2 py-1 ');
  159.             })
  160.             ->update(Crud::PAGE_INDEXAction::DELETE, function (Action $action) {
  161.                 return $action->setIcon('fa fa-trash')->addCssClass('btn px-2 py-1');
  162.             });
  163.     }
  164.     public function toFormulaireEtape(AdminContext $context)
  165.     {
  166.         $url $this->adminUrlGenerator
  167.             ->setController(FormulaireEtapeCrudController::class)
  168.             ->setAction(Action::INDEX)
  169.             ->set('parentform'$context->getEntity()->getInstance()->getId())
  170.             ->unset('entityId')
  171.             ->generateUrl();
  172.         return $this->redirect($url);
  173.     }
  174.     public function toFormulaireChamps(AdminContext $context)
  175.     {
  176.         $url $this->adminUrlGenerator
  177.             ->setController(FormulaireChampCrudController::class)
  178.             ->setAction(Action::INDEX)
  179.             ->unset('entityId')
  180.             ->generateUrl();
  181.         return $this->redirect($url);
  182.     }
  183.     public function ajouterEtape(AdminContext $context)
  184.     {
  185.         $entityManager $this->manager->getManager();
  186.         $idForm $context->getEntity()->getInstance()->getId();
  187.         $titre $context->getRequest()->get('titre');
  188.         $ordre $context->getRequest()->get('ordre');
  189.         $description $context->getRequest()->get('description');
  190.         $secure $context->getRequest()->get('secure');
  191.         $actif $context->getRequest()->get('actifetape');
  192.         $save $context->getRequest()->get('save');
  193.         $formulaire $this->manager->getRepository(Formulaire::class)->findOneBy(['id' => $idForm]);
  194.         $formEtape = new FormulaireEtape();
  195.         //$contenu = new PageContenu();
  196.         if ($titre != '') {
  197.             $formEtape->setTitre($titre);
  198.         }
  199.         if ($ordre != '' && $ordre != 0) {
  200.             $formEtape->setOrdre($ordre);
  201.         }
  202.         if ($description != '') {
  203.             $formEtape->setDescription($description);
  204.         }
  205.         if ($secure != '' && $secure != 'Rien') {
  206.             $formEtape->setSecure($secure);
  207.             if ($formEtape->getSecure() == 'Email') {
  208.                 // TODO add champliee Email
  209.                 $formChamp $this->manager->getRepository(FormulaireChamp::class)->findOneBy(['nom' => 'contact_email_secure']);
  210.                 if ($formChamp != null) {
  211.                     $champLiee = new FormulaireChampLiee();
  212.                     $champLiee->setFormulaireChamp($formChamp);
  213.                     $champLiee->setFormulaireEtape($formEtape);
  214.                     $champLiee->setObligatoire(true);
  215.                     $entityManager->persist($champLiee);
  216.                 }
  217.             } else if ($formEtape->getSecure() == 'SMS') {
  218.                 // TODO add champliee SMS
  219.                 $formChamp $this->manager->getRepository(FormulaireChamp::class)->findOneBy(['nom' => 'contact_tel_secure']);
  220.                 if ($formChamp != null) {
  221.                     $champLiee = new FormulaireChampLiee();
  222.                     $champLiee->setObligatoire(true);
  223.                     $champLiee->setFormulaireChamp($formChamp);
  224.                     $champLiee->setFormulaireEtape($formEtape);
  225.                     $champLiee->setObligatoire(true);
  226.                     $entityManager->persist($champLiee);
  227.                 }
  228.             }
  229.         }
  230.         if ($actif != '') {
  231.             $formEtape->setActif($actif);
  232.         } else {
  233.             $formEtape->setActif(false);
  234.         }
  235.         if ($save != '') {
  236.             $formEtape->setSave($save);
  237.         }
  238.         $formEtape->setFormulaire($formulaire);
  239.         $formEtape->setIdImport(date('Y-m-d-H-i-s') . '-formulaire-etape-' $formEtape->getId() . "-" $formEtape->getFormulaire()->getId() . "-" $formEtape->getFormulaire()->getProjet()->getId());
  240.         $formEtape->setIdImportFormulaire($formEtape->getFormulaire()->getIdImport());
  241.         $entityManager->persist($formEtape);
  242.         $entityManager->flush();
  243.         $url $this->adminUrlGenerator
  244.             ->setController(FormulaireCrudController::class)
  245.             ->setAction(Action::EDIT)
  246.             // ->set('tabactive', 'contenu')
  247.             ->generateUrl();
  248.         return $this->redirect($url);
  249.     }
  250.     public function editEtape(AdminContext $context)
  251.     {
  252.         $entityManager $this->manager->getManager();
  253.         $idFormEtape $context->getRequest()->get('etapeId');
  254.         $titre $context->getRequest()->get('titre');
  255.         $ordre $context->getRequest()->get('ordre');
  256.         $description $context->getRequest()->get('description');
  257.         $secure $context->getRequest()->get('secure' $idFormEtape);
  258.         $actif $context->getRequest()->get('actifetape' $idFormEtape);
  259.         $save $context->getRequest()->get('save' $idFormEtape);
  260.         $formEtape $this->manager->getRepository(FormulaireEtape::class)->findOneBy(['id' => $idFormEtape]);
  261.         //$contenu = new PageContenu();
  262.         if ($titre != '') {
  263.             $formEtape->setTitre($titre);
  264.         }
  265.         if ($ordre != '' && $ordre != 0) {
  266.             $formEtape->setOrdre($ordre);
  267.         } else {
  268.             $formEtape->setOrdre(null);
  269.         }
  270.         if ($description != '') {
  271.             $formEtape->setDescription($description);
  272.         } else {
  273.             $formEtape->setDescription(null);
  274.         }
  275.         if ($secure != $formEtape->getSecure()) {
  276.             $formChampEmail $this->manager->getRepository(FormulaireChamp::class)->findOneBy(['nom' => 'contact_email_secure']);
  277.             if ($formChampEmail != null) {
  278.                 $champLieeEmail $this->manager->getRepository(FormulaireChampLiee::class)->findOneBy(['formulaireChamp' => $formChampEmail'formulaireEtape' => $formEtape]);
  279.                 if ($champLieeEmail != null) {
  280.                     $entityManager->remove($champLieeEmail);
  281.                 }
  282.             }
  283.             $formChampTel $this->manager->getRepository(FormulaireChamp::class)->findOneBy(['nom' => 'contact_tel_secure']);
  284.             if ($formChampTel != null) {
  285.                 $champLieeTel $this->manager->getRepository(FormulaireChampLiee::class)->findOneBy(['formulaireChamp' => $formChampTel'formulaireEtape' => $formEtape]);
  286.                 if ($champLieeTel != null) {
  287.                     $entityManager->remove($champLieeTel);
  288.                 }
  289.             }
  290.             if ($secure != '' && $secure != 'Rien') {
  291.                 $formEtape->setSecure($secure);
  292.                 if ($formEtape->getSecure() == 'Email') {
  293.                     // TODO add champliee Email
  294.                     $formChamp $this->manager->getRepository(FormulaireChamp::class)->findOneBy(['nom' => 'contact_email_secure']);
  295.                     if ($formChamp == null) {
  296.                         $formChamp = new FormulaireChamp();
  297.                         $formChamp->setNom('contact_email_secure');
  298.                         $formChamp->setQuestion('Saisissez votre adresse e-mail pour recevoir le code confidentiel');
  299.                         $formChamp->setActif(true);
  300.                         $formInput $this->manager->getRepository(FormulaireInput::class)->findOneBy(['type' => 'email']);
  301.                         if ($formInput == null) {
  302.                             $formInput = new FormulaireInput();
  303.                             $formInput->setType('email');
  304.                             $formInput->setActif(true);
  305.                             $formInput->setProjet($formEtape->getFormulaire()->getProjet());
  306.                             $entityManager->persist($formInput);
  307.                         }
  308.                         $formChamp->setFormulaireInput($formInput);
  309.                         $entityManager->persist($formChamp);
  310.                     }
  311.                     $champLiee $this->manager->getRepository(FormulaireChampLiee::class)->findOneBy(['formulaireChamp' => $formChamp'formulaireEtape' => $formEtape]);
  312.                     if ($champLiee == null) {
  313.                         $champLiee = new FormulaireChampLiee();
  314.                         $champLiee->setFormulaireChamp($formChamp);
  315.                         $champLiee->setFormulaireEtape($formEtape);
  316.                     }
  317.                     $champLiee->setObligatoire(true);
  318.                     $entityManager->persist($champLiee);
  319.                 } else if ($formEtape->getSecure() == 'SMS') {
  320.                     // TODO add champliee SMS
  321.                     $formChamp $this->manager->getRepository(FormulaireChamp::class)->findOneBy(['nom' => 'contact_tel_secure']);
  322.                     if ($formChamp == null) {
  323.                         $formChamp = new FormulaireChamp();
  324.                         $formChamp->setNom('contact_tel_secure');
  325.                         $formChamp->setQuestion('Saisissez votre numéro du téléphone pour recevoir le code confidentiel    ');
  326.                         $formChamp->setActif(true);
  327.                         $formInput $this->manager->getRepository(FormulaireInput::class)->findOneBy(['type' => 'tel']);
  328.                         if ($formInput == null) {
  329.                             $formInput = new FormulaireInput();
  330.                             $formInput->setType('tel');
  331.                             $formInput->setActif(true);
  332.                             $formInput->setProjet($formEtape->getFormulaire()->getProjet());
  333.                             $entityManager->persist($formInput);
  334.                         }
  335.                         $formChamp->setFormulaireInput($formInput);
  336.                         $entityManager->persist($formChamp);
  337.                     }
  338.                     $champLiee $this->manager->getRepository(FormulaireChampLiee::class)->findOneBy(['formulaireChamp' => $formChamp'formulaireEtape' => $formEtape]);
  339.                     if ($champLiee == null) {
  340.                         $champLiee = new FormulaireChampLiee();
  341.                         $champLiee->setFormulaireChamp($formChamp);
  342.                         $champLiee->setFormulaireEtape($formEtape);
  343.                     }
  344.                     $champLiee->setObligatoire(true);
  345.                     $entityManager->persist($champLiee);
  346.                 }
  347.             } else {
  348.                 $formEtape->setSecure(null);
  349.             }
  350.             /* else {
  351.                 $formChampEmail = $this->manager->getRepository(FormulaireChamp::class)->findOneBy(['nom' => 'contact_email_secure']);
  352.                 if ($formChampEmail != null) {
  353.                     $champLieeEmail = $this->manager->getRepository(FormulaireChampLiee::class)->findOneBy(['formulaireChamp' => $formChampEmail, 'formulaireEtape' => $formEtape]);
  354.                     if ($champLieeEmail != null) {
  355.                         $entityManager->remove($champLieeEmail);
  356.                     }
  357.                 }
  358.                 $formChampTel = $this->manager->getRepository(FormulaireChamp::class)->findOneBy(['nom' => 'contact_tel_secure']);
  359.                 if ($formChampTel != null) {
  360.                     $champLieeTel = $this->manager->getRepository(FormulaireChampLiee::class)->findOneBy(['formulaireChamp' => $formChampTel, 'formulaireEtape' => $formEtape]);
  361.                     if ($champLieeTel != null) {
  362.                         $entityManager->remove($champLieeTel);
  363.                     }
  364.                 }
  365.             } */
  366.         }
  367.         if ($actif != '') {
  368.             $formEtape->setActif($actif);
  369.         } else {
  370.             $formEtape->setActif(false);
  371.         }
  372.         if ($save != '') {
  373.             $formEtape->setSave($save);
  374.         } else {
  375.             $formEtape->setSave(false);
  376.         }
  377.         if ($formEtape->getIdImport() == null || $formEtape->getIdImport() == '') {
  378.             $formEtape->setIdImport(date('Y-m-d-H-i-s') . '-formulaire-etape-' $formEtape->getId() . "-" $formEtape->getFormulaire()->getId() . "-" $formEtape->getFormulaire()->getProjet()->getId());
  379.         }
  380.         $formEtape->setIdImportFormulaire($formEtape->getFormulaire()->getIdImport());
  381.         $entityManager->flush();
  382.         $url $this->adminUrlGenerator
  383.             ->setController(FormulaireCrudController::class)
  384.             ->setAction(Action::EDIT)
  385.             // ->set('tabactive', 'contenu')
  386.             ->generateUrl();
  387.         return $this->redirect($url);
  388.     }
  389.     public function ajouterChampLiee(AdminContext $context)
  390.     {
  391.         $etapeId $context->getRequest()->get('etapeChampId');
  392.         $champId $context->getRequest()->get('champ');
  393.         $ordre $context->getRequest()->get('ordre');
  394.         $obligatoire $context->getRequest()->get('obligatoire');
  395.         $etape $this->manager->getRepository(FormulaireEtape::class)->findOneBy(['id' => $etapeId]);
  396.         $champ $this->manager->getRepository(FormulaireChamp::class)->findOneBy(['id' => $champId]);
  397.         $champLiee = new FormulaireChampLiee();
  398.         //$contenu = new PageContenu();
  399.         if ($ordre != '') {
  400.             $champLiee->setOrdre($ordre);
  401.         }
  402.         if ($obligatoire != '') {
  403.             if ($obligatoire == 'on') {
  404.                 $obligatoire true;
  405.             }
  406.             $champLiee->setObligatoire($obligatoire);
  407.         } else {
  408.             $obligatoire false;
  409.             $champLiee->setObligatoire($obligatoire);
  410.         }
  411.         $champLiee->setFormulaireEtape($etape);
  412.         $champLiee->setFormulaireChamp($champ);
  413.         if ($champ->getNom() == 'contact_email_secure') {
  414.             $champLiee->getFormulaireEtape()->setSecure('Email');
  415.             $champLiee->setObligatoire(true);
  416.         } else if ($champ->getNom() == 'contact_tel_secure') {
  417.             $champLiee->getFormulaireEtape()->setSecure('SMS');
  418.             $champLiee->setObligatoire(true);
  419.         } else {
  420.             $champLiee->getFormulaireEtape()->setSecure(null);
  421.         }
  422.         $champLiee->setIdImport(date('Y-m-d-H-i-s') . '-formulaire-champ-liee-' $champLiee->getId() . "-" $champLiee->getFormulaireEtape()->getId() . "-" $champLiee->getFormulaireEtape()->getFormulaire()->getId() . "-" $champLiee->getFormulaireEtape()->getFormulaire()->getProjet()->getId());
  423.         $champLiee->setIdImportChamp($champLiee->getFormulaireChamp()->getIdImport());
  424.         $champLiee->setIdImportEtape($champLiee->getFormulaireEtape()->getIdImport());
  425.         $entityManager $this->manager->getManager();
  426.         $entityManager->persist($champLiee);
  427.         $entityManager->flush();
  428.         $url $this->adminUrlGenerator
  429.             ->setController(FormulaireCrudController::class)
  430.             ->setAction(Action::EDIT)
  431.             // ->set('tabactive', 'contenu')
  432.             ->generateUrl();
  433.         return $this->redirect($url);
  434.     }
  435.     public function editChampLiee(AdminContext $context)
  436.     {
  437.         $champLieeId $context->getRequest()->get('champLieeId');
  438.         $champId $context->getRequest()->get('champ');
  439.         $ordre $context->getRequest()->get('ordre');
  440.         $obligatoire $context->getRequest()->get('obligatoire');
  441.         $champLiee $this->manager->getRepository(FormulaireChampLiee::class)->findOneBy(['id' => $champLieeId]);
  442.         $champ $this->manager->getRepository(FormulaireChamp::class)->findOneBy(['id' => $champId]);
  443.         //$champLiee = new FormulaireChampLiee();
  444.         //$contenu = new PageContenu();
  445.         if ($ordre != '') {
  446.             $champLiee->setOrdre($ordre);
  447.         } else {
  448.             $champLiee->setOrdre(null);
  449.         }
  450.         if ($obligatoire != '') {
  451.             if ($obligatoire == 'on') {
  452.                 $obligatoire true;
  453.             }
  454.             $champLiee->setObligatoire($obligatoire);
  455.         } else {
  456.             $obligatoire false;
  457.             $champLiee->setObligatoire($obligatoire);
  458.         }
  459.         if ($champLiee->getFormulaireChamp()->getNom() == 'contact_email_secure' || $champLiee->getFormulaireChamp()->getNom() == 'contact_tel_secure') {
  460.             if ($champ->getNom() == 'contact_email_secure') {
  461.                 $champLiee->getFormulaireEtape()->setSecure('Email');
  462.                 $champLiee->setObligatoire(true);
  463.             } else if ($champ->getNom() == 'contact_tel_secure') {
  464.                 $champLiee->getFormulaireEtape()->setSecure('SMS');
  465.                 $champLiee->setObligatoire(true);
  466.             } else {
  467.                 $champLiee->getFormulaireEtape()->setSecure(null);
  468.             }
  469.         }
  470.         $champLiee->setFormulaireChamp($champ);
  471.         if ($champLiee->getIdImport() == null || $champLiee->getIdImport() == '') {
  472.             $champLiee->setIdImport(date('Y-m-d-H-i-s') . '-formulaire-champ-liee-' $champLiee->getId() . "-" $champLiee->getFormulaireEtape()->getId() . "-" $champLiee->getFormulaireEtape()->getFormulaire()->getId() . "-" $champLiee->getFormulaireEtape()->getFormulaire()->getProjet()->getId());
  473.         }
  474.         $champLiee->setIdImportChamp($champLiee->getFormulaireChamp()->getIdImport());
  475.         $champLiee->setIdImportEtape($champLiee->getFormulaireEtape()->getIdImport());
  476.         $entityManager $this->manager->getManager();
  477.         $entityManager->flush();
  478.         $url $this->adminUrlGenerator
  479.             ->setController(FormulaireCrudController::class)
  480.             ->setAction(Action::EDIT)
  481.             // ->set('tabactive', 'contenu')
  482.             ->generateUrl();
  483.         return $this->redirect($url);
  484.     }
  485.     public function supprimerEtape(AdminContext $context)
  486.     {
  487.         $entityManager $this->manager->getManager();
  488.         $idFormEtape $context->getRequest()->get('etapeId');
  489.         $formEtape $this->manager->getRepository(FormulaireEtape::class)->findOneBy(['id' => $idFormEtape]);
  490.         $entityManager->remove($formEtape);
  491.         $entityManager->flush();
  492.         $url $this->adminUrlGenerator
  493.             ->setController(FormulaireCrudController::class)
  494.             ->setAction(Action::EDIT)
  495.             ->generateUrl();
  496.         return $this->redirect($url);
  497.     }
  498.     public function supprimerChampLiee(AdminContext $context)
  499.     {
  500.         $entityManager $this->manager->getManager();
  501.         $champLieeId $context->getRequest()->get('champLieeId');
  502.         $champLiee $this->manager->getRepository(FormulaireChampLiee::class)->findOneBy(['id' => $champLieeId]);
  503.         if ($champLiee->getFormulaireChamp()->getNom() == 'contact_email_secure' || $champLiee->getFormulaireChamp()->getNom() == 'contact_tel_secure') {
  504.             $champLiee->getFormulaireEtape()->setSecure(null);
  505.         }
  506.         $entityManager->remove($champLiee);
  507.         $entityManager->flush();
  508.         $url $this->adminUrlGenerator
  509.             ->setController(FormulaireCrudController::class)
  510.             ->setAction(Action::EDIT)
  511.             ->generateUrl();
  512.         return $this->redirect($url);
  513.     }
  514. }