src/Controller/FormationController.php line 542

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\CvFormation;
  4. use App\Entity\Formation;
  5. use App\Repository\FormationRepository;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\File\Exception\FileException;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use Symfony\Component\String\Slugger\SluggerInterface;
  13. use Symfony\Component\Form\Extension\Core\Type\TextType;
  14. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  15. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  16. use Symfony\Component\Form\Extension\Core\Type\FileType;
  17. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  18. use Symfony\Component\Validator\Constraints\File;
  19. class FormationController extends AbstractController
  20. {
  21.     private $em;
  22.     public function __construct(EntityManagerInterface $em)
  23.     {
  24.         $this->em $em;
  25.     }
  26.     /**
  27.      * @Route("/batiment/{nom<[a-zA-Z0-9\_]*>}", name="batiment")
  28.      */
  29.     public function batiment(String $nomFormationRepository $repoRequest $requestSluggerInterface $slugger, \Swift_Mailer $mailer): Response
  30.     {
  31.         $cvform = new CvFormation;
  32.         #dd($repo->findOneByCode($nom)->getNom());
  33.         $form $this->createFormBuilder($cvform, ['attr' => ['id' => 'postuler-form']])
  34.             ->add('nom'TextType::class, [
  35.                 'required' => true
  36.                 'label' => false,
  37.                 'attr' => [
  38.                     'autofocus' => false,                    
  39.                     'placeholder' => 'Nom*'
  40.                 ]
  41.             ])
  42.             ->add('prenom'TextType::class, [
  43.                 'required' => true
  44.                 'label' => false,
  45.                 'attr' => [
  46.                     'autofocus' => false,                    
  47.                     'placeholder' => 'Prénom*'
  48.                 ]
  49.             ])
  50.             ->add('mail'EmailType::class, [
  51.                 'required' => true
  52.                 'label' => false,
  53.                 'attr' => [
  54.                     'autofocus' => false,                    
  55.                     'placeholder' => 'Adresse mail*'
  56.                 ]
  57.             ])
  58.             ->add('telephone'TextType::class, [
  59.                 'required' => false
  60.                 'label' => false,
  61.                 'attr' => [
  62.                     'autofocus' => false,                    
  63.                     'placeholder' => 'Téléphone'
  64.                 ]
  65.             ])
  66.             ->add('cv'FileType::class, [
  67.                 'label' => false,
  68.                 // unmapped means that this field is not associated to any entity property
  69.                 'mapped' => false,
  70.                 // make it optional so you don't have to re-upload the PDF file
  71.                 // every time you edit the Product details
  72.                 'required' => true,
  73.                 // unmapped fields can't define their validation using annotations
  74.                 // in the associated entity, so you can use the PHP constraint classes
  75.                 'constraints' => [
  76.                     new File([
  77.                         'maxSize' => '1024k',
  78.                         'mimeTypes' => [
  79.                             'application/pdf',
  80.                             'application/x-pdf',
  81.                         ],
  82.                         'mimeTypesMessage' => 'Please upload a valid PDF document',
  83.                     ])
  84.                 ],
  85.             ])
  86.             /*->add('idFormation', HiddenType::class, [
  87.                 'required' => true, 
  88.                 'label' => false,
  89.                 'attr' => [
  90.                     'autofocus' => false,                    
  91.                     'value' => $repo->findOneByCode($nom)->getNom()
  92.                 ]
  93.             ])*/
  94.             ->add('submit'SubmitType::class, [
  95.                 'label' => 'Envoyer mon cv'
  96.             ])
  97.             ->getForm()
  98.         ;
  99.         $form->handleRequest($request);
  100.         if ($form->isSubmitted() && $form->isValid() && isset($_POST['raison']) && empty($_POST['raison'])) {
  101.             $cv $form->get('cv')->getData();
  102.             // this condition is needed because the 'brochure' field is not required
  103.             // so the PDF file must be processed only when a file is uploaded
  104.             if ($cv) {
  105.                 $originalFilename pathinfo($cv->getClientOriginalName(), PATHINFO_FILENAME);
  106.                 // this is needed to safely include the file name as part of the URL
  107.                 $safeFilename $slugger->slug($originalFilename);
  108.                 $newFilename $safeFilename.'-'.uniqid().'.'.$cv->guessExtension();
  109.                 // Move the file to the directory where brochures are stored
  110.                 try {
  111.                     $cv->move(
  112.                         $this->getParameter('cvform_repo'),
  113.                         $newFilename
  114.                     );
  115.                 } catch (FileException $e) {
  116.                     // ... handle exception if something happens during file upload
  117.                 }
  118.                 // updates the 'brochureFilename' property to store the PDF file name
  119.                 // instead of its contents
  120.                 $cvform->setCvname($newFilename);
  121.             }
  122.             $cvform->setIdFormation($repo->findOneByCode($nom)->getId().' - '.$repo->findOneByCode($nom)->getNom());
  123.             $this->em->persist($cvform);
  124.             $this->em->flush();        
  125.             
  126.             #dd($cvform);
  127.             
  128.             $postu $form->getData();
  129.             $adresseNom $form['mail']->getData();
  130.             $expNom $form['nom']->getData().' '.$form['prenom']->getData();
  131.             $pdf '/uploads/cvformation/'.$form['cv']->getData();
  132.             $pdfname $form['nom']->getData().'-'.$form['prenom']->getData().'.pdf';
  133.             // On crée le message
  134.             $message = (new \Swift_Message('CNFP - Nouvelle postulation - Formation '.$repo->findOneByCode($nom)->getNom()))
  135.                 // On attribue l'expéditeur
  136.                 ->setFrom('cnfpcontact@gmail.com')
  137.                 // On attribue le destinataire
  138.                 ->setTo('contact@cnfpformations.fr')
  139.                 // On crée le texte avec la vue
  140.                 ->setBody(
  141.                     $this->renderView(
  142.                         'formation/mail.html.twig'compact('postu')
  143.                     ),
  144.                     'text/html'
  145.                 )
  146.                 // Optionally add any attachments
  147.                 ->attach(\Swift_Attachment::fromPath($pdf)->setFilename($pdfname))
  148.             ;      
  149.             
  150.             $mailer->send($message);
  151.             $this->addFlash('success''Votre CV a bien été déposé.');
  152.             return $this->redirectToRoute('batiment', array('nom' => $repo->findOneByCode($nom)->getcode()));
  153.         }
  154.         return $this->render('formation/formation.html.twig', [
  155.             'formation' => $repo->findOneByCode($nom),
  156.             'titre' => $repo->findOneByCode($nom)->getNom(),
  157.             'cate' => $repo->findOneByCode($nom)->getCategorie(),
  158.             'formPostuler' => $form->createView()
  159.         ]);
  160.     }
  161.     /**
  162.      * @Route("/comptabilite_gestion/{nom<[a-zA-Z\_]*>}", name="comptabilite_gestion")
  163.      */
  164.     public function cg(String $nomFormationRepository $repoRequest $requestSluggerInterface $slugger, \Swift_Mailer $mailer): Response
  165.     {
  166.         $cvform = new CvFormation;
  167.         $form $this->createFormBuilder($cvform, ['attr' => ['id' => 'postuler-form']])
  168.             ->add('nom'TextType::class, [
  169.                 'required' => true
  170.                 'label' => false,
  171.                 'attr' => [
  172.                     'autofocus' => false,                    
  173.                     'placeholder' => 'Nom*'
  174.                 ]
  175.             ])
  176.             ->add('prenom'TextType::class, [
  177.                 'required' => true
  178.                 'label' => false,
  179.                 'attr' => [
  180.                     'autofocus' => false,                    
  181.                     'placeholder' => 'Prénom*'
  182.                 ]
  183.             ])
  184.             ->add('mail'EmailType::class, [
  185.                 'required' => true
  186.                 'label' => false,
  187.                 'attr' => [
  188.                     'autofocus' => false,                    
  189.                     'placeholder' => 'Adresse mail*'
  190.                 ]
  191.             ])
  192.             ->add('telephone'TextType::class, [
  193.                 'required' => false
  194.                 'label' => false,
  195.                 'attr' => [
  196.                     'autofocus' => false,                    
  197.                     'placeholder' => 'Téléphone'
  198.                 ]
  199.             ])
  200.             ->add('cv'FileType::class, [
  201.                 'label' => false,
  202.                 // unmapped means that this field is not associated to any entity property
  203.                 'mapped' => false,
  204.                 // make it optional so you don't have to re-upload the PDF file
  205.                 // every time you edit the Product details
  206.                 'required' => true,
  207.                 // unmapped fields can't define their validation using annotations
  208.                 // in the associated entity, so you can use the PHP constraint classes
  209.                 'constraints' => [
  210.                     new File([
  211.                         'maxSize' => '1024k',
  212.                         'mimeTypes' => [
  213.                             'application/pdf',
  214.                             'application/x-pdf',
  215.                         ],
  216.                         'mimeTypesMessage' => 'Please upload a valid PDF document',
  217.                     ])
  218.                 ],
  219.             ])
  220.             ->add('id_formation'HiddenType::class, [
  221.                 'required' => true
  222.                 'label' => false,
  223.                 'attr' => [
  224.                     'autofocus' => false,                    
  225.                     'value' => $repo->findOneByCode($nom)->getId().' - '.$repo->findOneByCode($nom)->getNom()
  226.                 ]
  227.             ])
  228.             ->add('submit'SubmitType::class, [
  229.                 'label' => 'Envoyer mon cv'
  230.             ])
  231.             ->getForm()
  232.         ;
  233.         $form->handleRequest($request);
  234.         if ($form->isSubmitted() && $form->isValid() && isset($_POST['raison']) && empty($_POST['raison'])) {
  235.             $cv $form->get('cv')->getData();
  236.             // this condition is needed because the 'brochure' field is not required
  237.             // so the PDF file must be processed only when a file is uploaded
  238.             if ($cv) {
  239.                 $originalFilename pathinfo($cv->getClientOriginalName(), PATHINFO_FILENAME);
  240.                 // this is needed to safely include the file name as part of the URL
  241.                 $safeFilename $slugger->slug($originalFilename);
  242.                 $newFilename $safeFilename.'-'.uniqid().'.'.$cv->guessExtension();
  243.                 // Move the file to the directory where brochures are stored
  244.                 try {
  245.                     $cv->move(
  246.                         $this->getParameter('cvform_repo'),
  247.                         $newFilename
  248.                     );
  249.                 } catch (FileException $e) {
  250.                     // ... handle exception if something happens during file upload
  251.                 }
  252.                 // updates the 'brochureFilename' property to store the PDF file name
  253.                 // instead of its contents
  254.                 $cvform->setCvname($newFilename);
  255.             }
  256.             $this->em->persist($cvform);
  257.             $this->em->flush();
  258.             
  259.             $postu $form->getData();
  260.             $adresseNom $form['mail']->getData();
  261.             $expNom $form['nom']->getData().' '.$form['prenom']->getData();
  262.             $pdf '/uploads/cvformation/'.$form['cv']->getData();
  263.             $pdfname $form['nom']->getData().'-'.$form['prenom']->getData().'.pdf';
  264.             // On crée le message
  265.             $message = (new \Swift_Message('CNFP - Nouvelle postulation - Formation '.$repo->findOneByCode($nom)->getNom()))
  266.                 // On attribue l'expéditeur
  267.                 ->setFrom('cnfpcontact@gmail.com')
  268.                 // On attribue le destinataire
  269.                 ->setTo('contact@cnfpformations.fr')
  270.                 // On crée le texte avec la vue
  271.                 ->setBody(
  272.                     $this->renderView(
  273.                         'formation/mail.html.twig'compact('postu')
  274.                     ),
  275.                     'text/html'
  276.                 )
  277.                 // Optionally add any attachments
  278.                 ->attach(\Swift_Attachment::fromPath($pdf)->setFilename($pdfname))
  279.             ;      
  280.             
  281.             $mailer->send($message);
  282.             $this->addFlash('success''Votre CV a bien été déposé.');
  283.             return $this->redirectToRoute('comptabilite_gestion', array('nom' => $repo->findOneByCode($nom)->getcode()));
  284.         }
  285.         return $this->render('formation/formation.html.twig', [
  286.             'formation' => $repo->findOneByCode($nom),
  287.             'titre' => $repo->findOneByCode($nom)->getNom(),
  288.             'cate' => $repo->findOneByCode($nom)->getCategorie(),
  289.             'formPostuler' => $form->createView()
  290.         ]);
  291.     }
  292.     /**
  293.      * @Route("/services/{nom<[a-zA-Z\_]*>}", name="services")
  294.      */
  295.     public function services(String $nomFormationRepository $repoRequest $requestSluggerInterface $slugger, \Swift_Mailer $mailer): Response
  296.     {
  297.         $cvform = new CvFormation;
  298.         $form $this->createFormBuilder($cvform, ['attr' => ['id' => 'postuler-form']])
  299.             ->add('nom'TextType::class, [
  300.                 'required' => true
  301.                 'label' => false,
  302.                 'attr' => [
  303.                     'autofocus' => false,                    
  304.                     'placeholder' => 'Nom*'
  305.                 ]
  306.             ])
  307.             ->add('prenom'TextType::class, [
  308.                 'required' => true
  309.                 'label' => false,
  310.                 'attr' => [
  311.                     'autofocus' => false,                    
  312.                     'placeholder' => 'Prénom*'
  313.                 ]
  314.             ])
  315.             ->add('mail'EmailType::class, [
  316.                 'required' => true
  317.                 'label' => false,
  318.                 'attr' => [
  319.                     'autofocus' => false,                    
  320.                     'placeholder' => 'Adresse mail*'
  321.                 ]
  322.             ])
  323.             ->add('telephone'TextType::class, [
  324.                 'required' => false
  325.                 'label' => false,
  326.                 'attr' => [
  327.                     'autofocus' => false,                    
  328.                     'placeholder' => 'Téléphone'
  329.                 ]
  330.             ])
  331.             ->add('cv'FileType::class, [
  332.                 'label' => false,
  333.                 // unmapped means that this field is not associated to any entity property
  334.                 'mapped' => false,
  335.                 // make it optional so you don't have to re-upload the PDF file
  336.                 // every time you edit the Product details
  337.                 'required' => true,
  338.                 // unmapped fields can't define their validation using annotations
  339.                 // in the associated entity, so you can use the PHP constraint classes
  340.                 'constraints' => [
  341.                     new File([
  342.                         'maxSize' => '1024k',
  343.                         'mimeTypes' => [
  344.                             'application/pdf',
  345.                             'application/x-pdf',
  346.                         ],
  347.                         'mimeTypesMessage' => 'Please upload a valid PDF document',
  348.                     ])
  349.                 ],
  350.             ])
  351.             ->add('id_formation'HiddenType::class, [
  352.                 'required' => true
  353.                 'label' => false,
  354.                 'attr' => [
  355.                     'autofocus' => false,                    
  356.                     'value' => $repo->findOneByCode($nom)->getId().' - '.$repo->findOneByCode($nom)->getNom()
  357.                 ]
  358.             ])
  359.             ->add('submit'SubmitType::class, [
  360.                 'label' => 'Envoyer mon cv'
  361.             ])
  362.             ->getForm()
  363.         ;
  364.         $form->handleRequest($request);
  365.         if ($form->isSubmitted() && $form->isValid() && isset($_POST['raison']) && empty($_POST['raison'])) {
  366.             $cv $form->get('cv')->getData();
  367.             // this condition is needed because the 'brochure' field is not required
  368.             // so the PDF file must be processed only when a file is uploaded
  369.             if ($cv) {
  370.                 $originalFilename pathinfo($cv->getClientOriginalName(), PATHINFO_FILENAME);
  371.                 // this is needed to safely include the file name as part of the URL
  372.                 $safeFilename $slugger->slug($originalFilename);
  373.                 $newFilename $safeFilename.'-'.uniqid().'.'.$cv->guessExtension();
  374.                 // Move the file to the directory where brochures are stored
  375.                 try {
  376.                     $cv->move(
  377.                         $this->getParameter('cvform_repo'),
  378.                         $newFilename
  379.                     );
  380.                 } catch (FileException $e) {
  381.                     // ... handle exception if something happens during file upload
  382.                 }
  383.                 // updates the 'brochureFilename' property to store the PDF file name
  384.                 // instead of its contents
  385.                 $cvform->setCvname($newFilename);
  386.             }
  387.             $this->em->persist($cvform);
  388.             $this->em->flush();
  389.             
  390.             $postu $form->getData();
  391.             $adresseNom $form['mail']->getData();
  392.             $expNom $form['nom']->getData().' '.$form['prenom']->getData();
  393.             $pdf '/uploads/cvformation/'.$form['cv']->getData();
  394.             $pdfname $form['nom']->getData().'-'.$form['prenom']->getData().'.pdf';
  395.             // On crée le message
  396.             $message = (new \Swift_Message('CNFP - Nouvelle postulation - Formation '.$repo->findOneByCode($nom)->getNom()))
  397.                 // On attribue l'expéditeur
  398.                 ->setFrom('cnfpcontact@gmail.com')
  399.                 // On attribue le destinataire
  400.                 ->setTo('contact@cnfpformations.fr')
  401.                 // On crée le texte avec la vue
  402.                 ->setBody(
  403.                     $this->renderView(
  404.                         'formation/mail.html.twig'compact('postu')
  405.                     ),
  406.                     'text/html'
  407.                 )
  408.                 // Optionally add any attachments
  409.                 ->attach(\Swift_Attachment::fromPath($pdf)->setFilename($pdfname))
  410.             ;      
  411.             
  412.             $mailer->send($message);
  413.             $this->addFlash('success''Votre CV a bien été déposé.');
  414.             return $this->redirectToRoute('services', array('nom' => $repo->findOneByCode($nom)->getcode()));
  415.         }
  416.         return $this->render('formation/formation.html.twig', [
  417.             'formation' => $repo->findOneByCode($nom),
  418.             'titre' => $repo->findOneByCode($nom)->getNom(),
  419.             'cate' => $repo->findOneByCode($nom)->getCategorie(),
  420.             'formPostuler' => $form->createView()
  421.         ]);
  422.     }
  423.     /**
  424.      * @Route("/diagnostic_immobilier", name="diagnostic_immobilier")
  425.      */
  426.     public function diag(): Response
  427.     {
  428.         return $this->render('formation/diag.html.twig', [
  429.             'titre' => "Diagnostic immobilier"
  430.         ]);
  431.     }
  432.     /**
  433.      * @Route("/diagnostic_immobilier/cursus_complet", name="diagnostic_immobilier_cursus")
  434.      */
  435.     public function diag_cursus(FormationRepository $repoRequest $requestSluggerInterface $slugger, \Swift_Mailer $mailer): Response
  436.     {
  437.         $nom "diagnostic_immobilier";
  438.         $cvform = new CvFormation;
  439.         $form $this->createFormBuilder($cvform, ['attr' => ['id' => 'postuler-form']])
  440.             ->add('nom'TextType::class, [
  441.                 'required' => true
  442.                 'label' => false,
  443.                 'attr' => [
  444.                     'autofocus' => false,                    
  445.                     'placeholder' => 'Nom*'
  446.                 ]
  447.             ])
  448.             ->add('prenom'TextType::class, [
  449.                 'required' => true
  450.                 'label' => false,
  451.                 'attr' => [
  452.                     'autofocus' => false,                    
  453.                     'placeholder' => 'Prénom*'
  454.                 ]
  455.             ])
  456.             ->add('mail'EmailType::class, [
  457.                 'required' => true
  458.                 'label' => false,
  459.                 'attr' => [
  460.                     'autofocus' => false,                    
  461.                     'placeholder' => 'Adresse mail*'
  462.                 ]
  463.             ])
  464.             ->add('telephone'TextType::class, [
  465.                 'required' => false
  466.                 'label' => false,
  467.                 'attr' => [
  468.                     'autofocus' => false,                    
  469.                     'placeholder' => 'Téléphone'
  470.                 ]
  471.             ])
  472.             ->add('cv'FileType::class, [
  473.                 'label' => false,
  474.                 // unmapped means that this field is not associated to any entity property
  475.                 'mapped' => false,
  476.                 // make it optional so you don't have to re-upload the PDF file
  477.                 // every time you edit the Product details
  478.                 'required' => true,
  479.                 // unmapped fields can't define their validation using annotations
  480.                 // in the associated entity, so you can use the PHP constraint classes
  481.                 'constraints' => [
  482.                     new File([
  483.                         'maxSize' => '1024k',
  484.                         'mimeTypes' => [
  485.                             'application/pdf',
  486.                             'application/x-pdf',
  487.                         ],
  488.                         'mimeTypesMessage' => 'Please upload a valid PDF document',
  489.                     ])
  490.                 ],
  491.             ])
  492.             ->add('id_formation'HiddenType::class, [
  493.                 'required' => true
  494.                 'label' => false,
  495.                 'attr' => [
  496.                     'autofocus' => false,                    
  497.                     'value' => $repo->findOneByCode($nom)->getId().' - '.$repo->findOneByCode($nom)->getNom()
  498.                 ]
  499.             ])
  500.             ->add('submit'SubmitType::class, [
  501.                 'label' => 'Envoyer mon cv'
  502.             ])
  503.             ->getForm()
  504.         ;
  505.         $form->handleRequest($request);
  506.         if ($form->isSubmitted() && $form->isValid() && isset($_POST['raison']) && empty($_POST['raison'])) {
  507.             $cv $form->get('cv')->getData();
  508.             // this condition is needed because the 'brochure' field is not required
  509.             // so the PDF file must be processed only when a file is uploaded
  510.             if ($cv) {
  511.                 $originalFilename pathinfo($cv->getClientOriginalName(), PATHINFO_FILENAME);
  512.                 // this is needed to safely include the file name as part of the URL
  513.                 $safeFilename $slugger->slug($originalFilename);
  514.                 $newFilename $safeFilename.'-'.uniqid().'.'.$cv->guessExtension();
  515.                 // Move the file to the directory where brochures are stored
  516.                 try {
  517.                     $cv->move(
  518.                         $this->getParameter('cvform_repo'),
  519.                         $newFilename
  520.                     );
  521.                 } catch (FileException $e) {
  522.                     // ... handle exception if something happens during file upload
  523.                 }
  524.                 // updates the 'brochureFilename' property to store the PDF file name
  525.                 // instead of its contents
  526.                 $cvform->setCvname($newFilename);
  527.             }
  528.             $this->em->persist($cvform);
  529.             $this->em->flush();
  530.             
  531.             $postu $form->getData();
  532.             $adresseNom $form['mail']->getData();
  533.             $expNom $form['nom']->getData().' '.$form['prenom']->getData();
  534.             $pdf '/uploads/cvformation/'.$form['cv']->getData();
  535.             $pdfname $form['nom']->getData().'-'.$form['prenom']->getData().'.pdf';
  536.             // On crée le message
  537.             $message = (new \Swift_Message('CNFP - Nouvelle postulation - Formation '.$repo->findOneByCode($nom)->getNom()))
  538.                 // On attribue l'expéditeur
  539.                 ->setFrom('cnfpcontact@gmail.com')
  540.                 // On attribue le destinataire
  541.                 ->setTo('contact@cnfpformations.fr')
  542.                 // On crée le texte avec la vue
  543.                 ->setBody(
  544.                     $this->renderView(
  545.                         'formation/mail.html.twig'compact('postu')
  546.                     ),
  547.                     'text/html'
  548.                 )
  549.                 // Optionally add any attachments
  550.                 ->attach(\Swift_Attachment::fromPath($pdf)->setFilename($pdfname))
  551.             ;      
  552.             
  553.             $mailer->send($message);
  554.             $this->addFlash('success''Votre CV a bien été déposé.');
  555.             return $this->redirectToRoute('diagnostic_immobilier_cursus');
  556.         }
  557.         return $this->render('formation/diag_cursus.html.twig', [
  558.             'formation' => $repo->findOneByCode("diagnostic_immobilier"),
  559.             'titre' => "Diagnostic immobilier - Cursus complet",
  560.             'formPostuler' => $form->createView()
  561.         ]);
  562.     }
  563.     /**
  564.      * @Route("/diagnostic_immobilier/modules", name="diagnostic_immobilier_modules")
  565.      */
  566.     public function diag_modules(): Response
  567.     {
  568.         return $this->render('formation/diag_modules.html.twig', [
  569.             'titre' => "Diagnostic immobilier - Modules à la carte"
  570.         ]);
  571.     }
  572.     /**
  573.      * @Route("/ascensoriste", name="ascensoriste")
  574.      */
  575.     public function asc(FormationRepository $repoRequest $requestSluggerInterface $slugger, \Swift_Mailer $mailer): Response
  576.     {
  577.         $nom "ascensoriste";
  578.         $cvform = new CvFormation;
  579.         $form $this->createFormBuilder($cvform, ['attr' => ['id' => 'postuler-form']])
  580.             ->add('nom'TextType::class, [
  581.                 'required' => true
  582.                 'label' => false,
  583.                 'attr' => [
  584.                     'autofocus' => false,                    
  585.                     'placeholder' => 'Nom*'
  586.                 ]
  587.             ])
  588.             ->add('prenom'TextType::class, [
  589.                 'required' => true
  590.                 'label' => false,
  591.                 'attr' => [
  592.                     'autofocus' => false,                    
  593.                     'placeholder' => 'Prénom*'
  594.                 ]
  595.             ])
  596.             ->add('mail'EmailType::class, [
  597.                 'required' => true
  598.                 'label' => false,
  599.                 'attr' => [
  600.                     'autofocus' => false,                    
  601.                     'placeholder' => 'Adresse mail*'
  602.                 ]
  603.             ])
  604.             ->add('telephone'TextType::class, [
  605.                 'required' => false
  606.                 'label' => false,
  607.                 'attr' => [
  608.                     'autofocus' => false,                    
  609.                     'placeholder' => 'Téléphone'
  610.                 ]
  611.             ])
  612.             ->add('cv'FileType::class, [
  613.                 'label' => false,
  614.                 // unmapped means that this field is not associated to any entity property
  615.                 'mapped' => false,
  616.                 // make it optional so you don't have to re-upload the PDF file
  617.                 // every time you edit the Product details
  618.                 'required' => true,
  619.                 // unmapped fields can't define their validation using annotations
  620.                 // in the associated entity, so you can use the PHP constraint classes
  621.                 'constraints' => [
  622.                     new File([
  623.                         'maxSize' => '1024k',
  624.                         'mimeTypes' => [
  625.                             'application/pdf',
  626.                             'application/x-pdf',
  627.                         ],
  628.                         'mimeTypesMessage' => 'Please upload a valid PDF document',
  629.                     ])
  630.                 ],
  631.             ])
  632.             ->add('id_formation'HiddenType::class, [
  633.                 'required' => true
  634.                 'label' => false,
  635.                 'attr' => [
  636.                     'autofocus' => false,                    
  637.                     'value' => $repo->findOneByCode($nom)->getId().' - '.$repo->findOneByCode($nom)->getNom()
  638.                 ]
  639.             ])
  640.             ->add('submit'SubmitType::class, [
  641.                 'label' => 'Envoyer mon cv'
  642.             ])
  643.             ->getForm()
  644.         ;
  645.         $form->handleRequest($request);
  646.         if ($form->isSubmitted() && $form->isValid() && isset($_POST['raison']) && empty($_POST['raison'])) {
  647.             $cv $form->get('cv')->getData();
  648.             // this condition is needed because the 'brochure' field is not required
  649.             // so the PDF file must be processed only when a file is uploaded
  650.             if ($cv) {
  651.                 $originalFilename pathinfo($cv->getClientOriginalName(), PATHINFO_FILENAME);
  652.                 // this is needed to safely include the file name as part of the URL
  653.                 $safeFilename $slugger->slug($originalFilename);
  654.                 $newFilename $safeFilename.'-'.uniqid().'.'.$cv->guessExtension();
  655.                 // Move the file to the directory where brochures are stored
  656.                 try {
  657.                     $cv->move(
  658.                         $this->getParameter('cvform_repo'),
  659.                         $newFilename
  660.                     );
  661.                 } catch (FileException $e) {
  662.                     // ... handle exception if something happens during file upload
  663.                 }
  664.                 // updates the 'brochureFilename' property to store the PDF file name
  665.                 // instead of its contents
  666.                 $cvform->setCvname($newFilename);
  667.             }
  668.             $this->em->persist($cvform);
  669.             $this->em->flush(); 
  670.             
  671.             $postu $form->getData();
  672.             $adresseNom $form['mail']->getData();
  673.             $expNom $form['nom']->getData().' '.$form['prenom']->getData();
  674.             $pdf '/uploads/cvformation/'.$form['cv']->getData();
  675.             $pdfname $form['nom']->getData().'-'.$form['prenom']->getData().'.pdf';
  676.             // On crée le message
  677.             $message = (new \Swift_Message('CNFP - Nouvelle postulation - Formation '.$repo->findOneByCode($nom)->getNom()))
  678.                 // On attribue l'expéditeur
  679.                 ->setFrom('cnfpcontact@gmail.com')
  680.                 // On attribue le destinataire
  681.                 ->setTo('contact@cnfpformations.fr')
  682.                 // On crée le texte avec la vue
  683.                 ->setBody(
  684.                     $this->renderView(
  685.                         'formation/mail.html.twig'compact('postu')
  686.                     ),
  687.                     'text/html'
  688.                 )
  689.                 // Optionally add any attachments
  690.                 ->attach(\Swift_Attachment::fromPath($pdf)->setFilename($pdfname))
  691.             ;      
  692.             
  693.             $mailer->send($message);
  694.             $this->addFlash('success''Votre CV a bien été déposé.');
  695.             return $this->redirectToRoute('ascensoriste');
  696.         }
  697.         return $this->render('formation/asc.html.twig', [
  698.             'formation' => $repo->findOneByCode($nom),
  699.             'titre' => "Ascensoriste",
  700.             'formPostuler' => $form->createView()
  701.         ]);
  702.     }
  703. }