src/Controller/ThemesWebsite/Cvs/GestionCandidates/GenerateController.php line 63

Open in your IDE?
  1. <?php
  2. namespace App\Controller\ThemesWebsite\Cvs\GestionCandidates;
  3. use App\Entity\Core\Mails;
  4. use App\Entity\Cvs\Candidates;
  5. use App\Entity\Cvs\CandidatesHasExperiences;
  6. use App\Entity\Cvs\CandidatesHasProjects;
  7. use App\Entity\Cvs\CandidatesHasServices;
  8. use App\Entity\Cvs\CandidatesHasSkills;
  9. use App\Entity\Cvs\CandidatesHasTitles;
  10. use App\Entity\Cvs\History;
  11. use App\Entity\Cvs\Invitations;
  12. use App\Form\Cvs\CandidatesSearchForm;
  13. use App\Form\Cvs\CandidatesSettingsForm;
  14. use App\Form\Cvs\CandidatesStep1Form;
  15. use App\Form\Cvs\CandidatesStep2Form;
  16. use App\Form\Cvs\ExperiencesForm;
  17. use App\Form\Cvs\ProjectsForm;
  18. use App\Form\Cvs\ServicesForm;
  19. use App\Form\Cvs\SkillsForm;
  20. use App\Services\Core\Core;
  21. use App\Services\Core\RequestData;
  22. use App\Services\Core\Users;
  23. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
  24. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  25. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  26. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  27. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  28. use Symfony\Component\HttpFoundation\Request;
  29. use Symfony\Component\HttpFoundation\Response;
  30. use Symfony\Component\Routing\Annotation\Route;
  31. use Symfony\Component\HttpFoundation\Cookie;
  32. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  33. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  34. use Doctrine\ORM\EntityManagerInterface;
  35. use Symfony\Component\HttpFoundation\JsonResponse;
  36. /**
  37.  * Générateur de CV
  38.  */
  39. class GenerateController extends AbstractController
  40. {
  41.     private $rd;
  42.     private $em;
  43.     private $ms;
  44.     public function __construct(RequestData $rd,
  45.                                 EntityManagerInterface $em,
  46.                                 \App\Services\Mails $ms
  47.     ){
  48.         $this->rd $rd;
  49.         $this->em $em;
  50.         $this->ms $ms;
  51.     }
  52.     /**
  53.      * Mes informations
  54.      * @param Request $request
  55.      * @return Response
  56.      */
  57.     public function coordinates(Request $request): Response
  58.     {
  59.         $session $request->getSession();
  60.         $session->set("navbar-section","dashboard");
  61.         $session->set("sidebar-section","generate");
  62.         $user $this->getUser();
  63.         if($user == null) {
  64.             Throw new \Exception("Aucun utilisateur");
  65.         }
  66.         $candidate $user->getCandidate();
  67.         if($candidate == null) {
  68.             $candidate = new Candidates();
  69.             $candidate->setName($user->getName());
  70.             $candidate->setLastname($user->getLastname());
  71.             $candidate->setEmail($user->getEmail());
  72.             $candidate->setFirst(true);
  73.             $this->em->persist($candidate);
  74.             $this->em->flush();
  75.             $user->setCandidate($candidate);
  76.             $this->em->persist($user);
  77.             $this->em->flush();
  78.         }
  79.         
  80.         $form $this->createForm(CandidatesStep1Form::class, $candidate);
  81.         $form->handleRequest($request);
  82.         if ($form->isSubmitted() && $form->isValid()) {
  83.             $data $request->request->all();
  84.             $data $data['candidates_step1_form'];
  85.             $infoAddress $this->rd->searchAddress($data['address']);
  86.             $infoAddress $infoAddress[0];
  87.             $points $this->rd->getPoints($data['address']);
  88.             $candidate->setAddress($infoAddress['streetAddress']);
  89.             $candidate->setZipcode($infoAddress['postcode']);
  90.             $candidate->setCity($infoAddress['city']);
  91.             $candidate->setCountry($infoAddress['country']);
  92.             $candidate->setPointX($points[0]);
  93.             $candidate->setPointY($points[1]);
  94.             $this->em->persist($candidate);
  95.             $this->em->flush();
  96.             $user->setName($candidate->getName());
  97.             $user->setLastname($candidate->getLastname());
  98.             $this->em->persist($user);
  99.             $this->em->flush();
  100.             $session->getFlashBag()->add('success''Mise à jour des informations');
  101.             return $this->redirectToRoute('cvs_gestion_candidates_generate_informations');
  102.         }
  103.         $queryAddress $candidate->getAddress().", ".$candidate->getZipcode().", ".$candidate->getCity().", ".$candidate->getCountry();
  104.         return $this->render('themesWebsite/cvs/gestion/candidates/generate/coordinates/fiche.html.twig',[
  105.             'form' =>  $form->createView(),
  106.             'queryAddress' => $queryAddress
  107.         ]);
  108.     }
  109.     /**
  110.      * Ma recherche
  111.      * @param Request $request
  112.      * @return Response
  113.      * @throws \Exception
  114.      */
  115.     public function informations(Request $request): Response
  116.     {
  117.         $session $request->getSession();
  118.         $session->set("navbar-section","dashboard");
  119.         $session->set("sidebar-section","generate");
  120.         $user $this->getUser();
  121.         if($user == null) {
  122.             Throw new \Exception("Aucun utilisateur");
  123.         }
  124.         $candidate $user->getCandidate();
  125.         if($candidate == null) {
  126.             Throw new \Exception("Aucun CV");
  127.         }
  128.         $form $this->createForm(CandidatesStep2Form::class, $candidate);
  129.         $form->handleRequest($request);
  130.         if ($form->isSubmitted() && $form->isValid()) {
  131.             $data $request->request->all();
  132.             $this->em->persist($candidate);
  133.             $this->em->flush();
  134.             $session->getFlashBag()->add('success''Mise à jour des informations');
  135.             if($data['submit'] == "0") {
  136.                 return $this->redirectToRoute('cvs_gestion_candidates_generate_coordinates');
  137.             }
  138.             return $this->redirectToRoute('cvs_gestion_candidates_generate_search');
  139.         }
  140.         return $this->render('themesWebsite/cvs/gestion/candidates/generate/informations/fiche.html.twig',[
  141.             'form' =>  $form->createView()
  142.         ]);
  143.     }
  144.     /**
  145.      * Ma recherche
  146.      * @param Request $request
  147.      * @return Response
  148.      * @throws \Exception
  149.      */
  150.     public function search(Request $request): Response
  151.     {
  152.         $session $request->getSession();
  153.         $session->set("navbar-section","dashboard");
  154.         $session->set("sidebar-section","generate");
  155.         $user $this->getUser();
  156.         if($user == null) {
  157.             Throw new \Exception("Aucun utilisateur");
  158.         }
  159.         $candidate $user->getCandidate();
  160.         if($candidate == null) {
  161.             Throw new \Exception("Aucun CV");
  162.         }
  163.         $titles $this->em->getRepository(CandidatesHasTitles::class)->findBy(['candidate' => $candidate],['title' => 'ASC']);
  164.         $cht = new CandidatesHasTitles();
  165.         $cht->setCandidate($candidate);
  166.         $form $this->createForm(CandidatesSearchForm::class, $cht);
  167.         $form->handleRequest($request);
  168.         if ($form->isSubmitted() && $form->isValid()) {
  169.             $this->em->persist($cht);
  170.             $this->em->flush();
  171.             $session->getFlashBag()->add('success''Mise à jour des informations');
  172.             return $this->redirectToRoute('cvs_gestion_candidates_generate_search');
  173.         }
  174.         return $this->render('themesWebsite/cvs/gestion/candidates/generate/search/list.html.twig',[
  175.             'form' =>  $form->createView(),
  176.             'titles' => $titles
  177.         ]);
  178.     }
  179.     /**
  180.      * Modifier un titre
  181.      * @param Request $request
  182.      * @param CandidatesHasTitles $title
  183.      * @return Response
  184.      * @throws \Exception
  185.      */
  186.     public function titlesEdit(Request $requestCandidatesHasTitles $title): Response
  187.     {
  188.         $session $request->getSession();
  189.         $session->set("navbar-section","dashboard");
  190.         $session->set("sidebar-section","generate");
  191.         $user $this->getUser();
  192.         if($user == null) {
  193.             Throw new \Exception("Aucun utilisateur");
  194.         }
  195.         $candidate $user->getCandidate();
  196.         if($candidate == null) {
  197.             Throw new \Exception("Aucun CV");
  198.         }
  199.         if($title->getCandidate() != $candidate) {
  200.             Throw new \Exception("Mauvaise fiche");
  201.         }
  202.         $form $this->createForm(CandidatesSearchForm::class, $title);
  203.         $form->handleRequest($request);
  204.         if ($form->isSubmitted() && $form->isValid()) {
  205.             $this->em->persist($title);
  206.             $this->em->flush();
  207.             $session->getFlashBag()->add('success''Mise à jour des informations');
  208.             return $this->redirectToRoute('cvs_gestion_candidates_generate_search');
  209.         }
  210.         return $this->render('themesWebsite/cvs/gestion/candidates/generate/search/edit.html.twig',[
  211.             'form' =>  $form->createView(),
  212.             'title' => $title
  213.         ]);
  214.     }
  215.     /**
  216.      * Confirmer la suppression d'un titre
  217.      * @param Request $request
  218.      * @param CandidatesHasTitles $title
  219.      * @return Response
  220.      * @throws \Exception
  221.      */
  222.     public function titlesRemove(Request $requestCandidatesHasTitles $title): Response
  223.     {
  224.         $session $request->getSession();
  225.         $session->set("navbar-section","dashboard");
  226.         $session->set("sidebar-section","generate");
  227.         $user $this->getUser();
  228.         if($user == null) {
  229.             Throw new \Exception("Aucun utilisateur");
  230.         }
  231.         $candidate $user->getCandidate();
  232.         if($candidate == null) {
  233.             Throw new \Exception("Aucun CV");
  234.         }
  235.         if($title->getCandidate() != $candidate) {
  236.             Throw new \Exception("Mauvaise fiche");
  237.         }
  238.         return $this->render('themesWebsite/cvs/gestion/candidates/generate/search/remove.html.twig',[
  239.             'title' => $title
  240.         ]);
  241.     }
  242.     /**
  243.      * Supprimer un titre
  244.      * @param Request $request
  245.      * @param CandidatesHasTitles $title
  246.      * @return Response
  247.      * @throws \Exception
  248.      */
  249.     public function titlesDelete(Request $requestCandidatesHasTitles $title): Response
  250.     {
  251.         $session $request->getSession();
  252.         $session->set("navbar-section","dashboard");
  253.         $session->set("sidebar-section","generate");
  254.         $user $this->getUser();
  255.         if($user == null) {
  256.             Throw new \Exception("Aucun utilisateur");
  257.         }
  258.         $candidate $user->getCandidate();
  259.         if($candidate == null) {
  260.             Throw new \Exception("Aucun CV");
  261.         }
  262.         if($title->getCandidate() != $candidate) {
  263.             Throw new \Exception("Mauvaise fiche");
  264.         }
  265.         $this->em->remove($title);
  266.         $this->em->flush();
  267.         $session->getFlashBag()->add('success''Mise à jour des informations');
  268.         return $this->redirectToRoute('cvs_gestion_candidates_generate_search');
  269.     }
  270.     /**
  271.      * Mes services
  272.      * @param Request $request
  273.      * @return Response
  274.      * @throws \Exception
  275.      */
  276.     public function services(Request $request): Response
  277.     {
  278.         $session $request->getSession();
  279.         $session->set("navbar-section","dashboard");
  280.         $session->set("sidebar-section","generate");
  281.         $user $this->getUser();
  282.         if($user == null) {
  283.             Throw new \Exception("Aucun utilisateur");
  284.         }
  285.         $candidate $user->getCandidate();
  286.         if($candidate == null) {
  287.             Throw new \Exception("Aucun CV");
  288.         }
  289.         $service = new CandidatesHasServices();
  290.         $service->setCandidate($candidate);
  291.         $service->setOnline(true);
  292.         $form $this->createForm(ServicesForm::class, $service);
  293.         $form->handleRequest($request);
  294.         if ($form->isSubmitted() && $form->isValid()) {
  295.             $this->em->persist($service);
  296.             $this->em->flush();
  297.             $session->getFlashBag()->add('success''Mise à jour des informations');
  298.             return $this->redirectToRoute('cvs_gestion_candidates_generate_services');
  299.         }
  300.         $services $this->em->getRepository(CandidatesHasServices::class)->findBy(['candidate' => $candidate]);
  301.         return $this->render('themesWebsite/cvs/gestion/candidates/generate/services/list.html.twig',[
  302.             'form' =>  $form->createView(),
  303.             'services' => $services
  304.         ]);
  305.     }
  306.     /**
  307.      * Modifier un service
  308.      * @param Request $request
  309.      * @param CandidatesHasExperiences $experience
  310.      * @return Response
  311.      * @throws \Exception
  312.      */
  313.     public function servicesEdit(Request $requestCandidatesHasServices $service): Response
  314.     {
  315.         $session $request->getSession();
  316.         $session->set("navbar-section","dashboard");
  317.         $session->set("sidebar-section","generate");
  318.         $user $this->getUser();
  319.         if($user == null) {
  320.             Throw new \Exception("Aucun utilisateur");
  321.         }
  322.         $candidate $user->getCandidate();
  323.         if($candidate == null) {
  324.             Throw new \Exception("Aucun CV");
  325.         }
  326.         if($service->getCandidate() != $candidate) {
  327.             Throw new \Exception("Mauvaise fiche");
  328.         }
  329.         $form $this->createForm(ServicesForm::class, $service);
  330.         $form->handleRequest($request);
  331.         if ($form->isSubmitted() && $form->isValid()) {
  332.             $this->em->persist($service);
  333.             $this->em->flush();
  334.             $session->getFlashBag()->add('success''Mise à jour des informations');
  335.             return $this->redirectToRoute('cvs_gestion_candidates_generate_services');
  336.         }
  337.         return $this->render('themesWebsite/cvs/gestion/candidates/generate/services/edit.html.twig',[
  338.             'form' =>  $form->createView(),
  339.             'service' => $service
  340.         ]);
  341.     }
  342.     /**
  343.      * Confirmer la suppresison d'un service
  344.      * @param Request $request
  345.      * @param CandidatesHasExperiences $experience
  346.      * @return Response
  347.      * @throws \Exception
  348.      */
  349.     public function servicesRemove(Request $requestCandidatesHasServices $service): Response
  350.     {
  351.         $session $request->getSession();
  352.         $session->set("navbar-section","dashboard");
  353.         $session->set("sidebar-section","generate");
  354.         $user $this->getUser();
  355.         if($user == null) {
  356.             Throw new \Exception("Aucun utilisateur");
  357.         }
  358.         $candidate $user->getCandidate();
  359.         if($candidate == null) {
  360.             Throw new \Exception("Aucun CV");
  361.         }
  362.         if($service->getCandidate() != $candidate) {
  363.             Throw new \Exception("Mauvaise fiche");
  364.         }
  365.         return $this->render('themesWebsite/cvs/gestion/candidates/generate/services/remove.html.twig',[
  366.             'service' => $service
  367.         ]);
  368.     }
  369.     /**
  370.      * Supprimer un service
  371.      * @param Request $request
  372.      * @param CandidatesHasExperiences $experience
  373.      * @return Response
  374.      * @throws \Exception
  375.      */
  376.     public function servicesDelete(Request $requestCandidatesHasServices $service): Response
  377.     {
  378.         $session $request->getSession();
  379.         $session->set("navbar-section","dashboard");
  380.         $session->set("sidebar-section","generate");
  381.         $user $this->getUser();
  382.         if($user == null) {
  383.             Throw new \Exception("Aucun utilisateur");
  384.         }
  385.         $candidate $user->getCandidate();
  386.         if($candidate == null) {
  387.             Throw new \Exception("Aucun CV");
  388.         }
  389.         if($service->getCandidate() != $candidate) {
  390.             Throw new \Exception("Mauvaise fiche");
  391.         }
  392.         $this->em->remove($service);
  393.         $this->em->flush();
  394.         $session->getFlashBag()->add('success''Mise à jour des informations');
  395.         return $this->redirectToRoute('cvs_gestion_candidates_generate_services');
  396.     }
  397.     /**
  398.      * Mes expériences
  399.      * @param Request $request
  400.      * @return Response
  401.      * @throws \Exception
  402.      */
  403.     public function step3(Request $request): Response
  404.     {
  405.         $session $request->getSession();
  406.         $session->set("navbar-section","dashboard");
  407.         $session->set("sidebar-section","generate");
  408.         $user $this->getUser();
  409.         if($user == null) {
  410.             Throw new \Exception("Aucun utilisateur");
  411.         }
  412.         $candidate $user->getCandidate();
  413.         if($candidate == null) {
  414.             Throw new \Exception("Aucun CV");
  415.         }
  416.         $services $this->em->getRepository(CandidatesHasServices::class)->findBy(['candidate' => $candidate]);
  417.         /*
  418.         if($services == null) {
  419.             return $this->redirectToRoute('cvs_gestion_candidates_generate_services');
  420.         }*/
  421.         $exp = new CandidatesHasExperiences();
  422.         $exp->setCandidate($candidate);
  423.         $exp->setOnline(true);
  424.         $form $this->createForm(ExperiencesForm::class, $exp);
  425.         $form->handleRequest($request);
  426.         if ($form->isSubmitted() && $form->isValid()) {
  427.             $this->em->persist($exp);
  428.             $this->em->flush();
  429.             $session->getFlashBag()->add('success''Mise à jour des informations');
  430.             return $this->redirectToRoute('cvs_gestion_candidates_generate_step3');
  431.         }
  432.         $experiences $this->em->getRepository(CandidatesHasExperiences::class)->findBy(['candidate' => $candidate],['start' => 'DESC']);
  433.         return $this->render('themesWebsite/cvs/gestion/candidates/generate/step3.html.twig',[
  434.             'form' =>  $form->createView(),
  435.             'experiences' => $experiences
  436.         ]);
  437.     }
  438.     /**
  439.      * Modifier une expérience
  440.      * @param Request $request
  441.      * @param CandidatesHasExperiences $experience
  442.      * @return Response
  443.      * @throws \Exception
  444.      */
  445.     public function step3Edit(Request $requestCandidatesHasExperiences $experience): Response
  446.     {
  447.         $session $request->getSession();
  448.         $session->set("navbar-section","dashboard");
  449.         $session->set("sidebar-section","generate");
  450.         $user $this->getUser();
  451.         if($user == null) {
  452.             Throw new \Exception("Aucun utilisateur");
  453.         }
  454.         $candidate $user->getCandidate();
  455.         if($candidate == null) {
  456.             Throw new \Exception("Aucun CV");
  457.         }
  458.         if($experience->getCandidate() != $candidate) {
  459.             Throw new \Exception("Mauvaise fiche");
  460.         }
  461.         $form $this->createForm(ExperiencesForm::class, $experience);
  462.         $form->handleRequest($request);
  463.         if ($form->isSubmitted() && $form->isValid()) {
  464.             $this->em->persist($experience);
  465.             $this->em->flush();
  466.             $session->getFlashBag()->add('success''Mise à jour des informations');
  467.             return $this->redirectToRoute('cvs_gestion_candidates_generate_step3');
  468.         }
  469.         return $this->render('themesWebsite/cvs/gestion/candidates/generate/step3_edit.html.twig',[
  470.             'form' =>  $form->createView(),
  471.             'experience' => $experience
  472.         ]);
  473.     }
  474.     /**
  475.      * Confirmer la suppression d'une expérience
  476.      * @param Request $request
  477.      * @param CandidatesHasExperiences $experience
  478.      * @return Response
  479.      * @throws \Exception
  480.      */
  481.     public function step3Remove(Request $requestCandidatesHasExperiences $experience): Response
  482.     {
  483.         $session $request->getSession();
  484.         $session->set("navbar-section","dashboard");
  485.         $session->set("sidebar-section","generate");
  486.         $user $this->getUser();
  487.         if($user == null) {
  488.             Throw new \Exception("Aucun utilisateur");
  489.         }
  490.         $candidate $user->getCandidate();
  491.         if($candidate == null) {
  492.             Throw new \Exception("Aucun CV");
  493.         }
  494.         if($experience->getCandidate() != $candidate) {
  495.             Throw new \Exception("Mauvaise fiche");
  496.         }
  497.         return $this->render('themesWebsite/cvs/gestion/candidates/generate/step3_remove.html.twig',[
  498.             'experience' => $experience
  499.         ]);
  500.     }
  501.     /**
  502.      * Supprimer une expérience
  503.      * @param Request $request
  504.      * @param CandidatesHasExperiences $experience
  505.      * @return Response
  506.      * @throws \Exception
  507.      */
  508.     public function step3Delete(Request $requestCandidatesHasExperiences $experience): Response
  509.     {
  510.         $session $request->getSession();
  511.         $session->set("navbar-section","dashboard");
  512.         $session->set("sidebar-section","generate");
  513.         $user $this->getUser();
  514.         if($user == null) {
  515.             Throw new \Exception("Aucun utilisateur");
  516.         }
  517.         $candidate $user->getCandidate();
  518.         if($candidate == null) {
  519.             Throw new \Exception("Aucun CV");
  520.         }
  521.         if($experience->getCandidate() != $candidate) {
  522.             Throw new \Exception("Mauvaise fiche");
  523.         }
  524.         $this->em->remove($experience);
  525.         $this->em->flush();
  526.         $session->getFlashBag()->add('success''Mise à jour des informations');
  527.         return $this->redirectToRoute('cvs_gestion_candidates_generate_step3');
  528.     }
  529.     /**
  530.      * Projets
  531.      * @param Request $request
  532.      * @return Response
  533.      * @throws \Exception
  534.      */
  535.     public function step4(Request $request): Response
  536.     {
  537.         $session $request->getSession();
  538.         $session->set("navbar-section","dashboard");
  539.         $session->set("sidebar-section","generate");
  540.         $user $this->getUser();
  541.         if($user == null) {
  542.             Throw new \Exception("Aucun utilisateur");
  543.         }
  544.         $candidate $user->getCandidate();
  545.         if($candidate == null) {
  546.             Throw new \Exception("Aucun CV");
  547.         }
  548.         $experiences $this->em->getRepository(CandidatesHasExperiences::class)->findBy(['candidate' => $candidate]);
  549.         /*
  550.         if($experiences == null) {
  551.             return $this->redirectToRoute('cvs_gestion_candidates_generate_step3');
  552.         }
  553.         */
  554.         $project = new CandidatesHasProjects();
  555.         $project->setCandidate($candidate);
  556.         $project->setOnline(false);
  557.         $form $this->createForm(ProjectsForm::class, $project);
  558.         $form->handleRequest($request);
  559.         if ($form->isSubmitted() && $form->isValid()) {
  560.             $this->em->persist($project);
  561.             $this->em->flush();
  562.             $session->getFlashBag()->add('success''Mise à jour des informations');
  563.             return $this->redirectToRoute('cvs_gestion_candidates_generate_step4');
  564.         }
  565.         $projects $this->em->getRepository(CandidatesHasProjects::class)->findBy(['candidate' => $candidate]);
  566.         return $this->render('themesWebsite/cvs/gestion/candidates/generate/step4.html.twig',[
  567.             'form' =>  $form->createView(),
  568.             'projects' => $projects
  569.         ]);
  570.     }
  571.     /**
  572.      * Modifier une expérience
  573.      * @param Request $request
  574.      * @param CandidatesHasExperiences $experience
  575.      * @return Response
  576.      * @throws \Exception
  577.      */
  578.     public function step4Edit(Request $requestCandidatesHasProjects $project): Response
  579.     {
  580.         $session $request->getSession();
  581.         $session->set("navbar-section","dashboard");
  582.         $session->set("sidebar-section","generate");
  583.         $user $this->getUser();
  584.         if($user == null) {
  585.             Throw new \Exception("Aucun utilisateur");
  586.         }
  587.         $candidate $user->getCandidate();
  588.         if($candidate == null) {
  589.             Throw new \Exception("Aucun CV");
  590.         }
  591.         if($project->getCandidate() != $candidate) {
  592.             Throw new \Exception("Mauvaise fiche");
  593.         }
  594.         $form $this->createForm(ProjectsForm::class, $project);
  595.         $form->handleRequest($request);
  596.         if ($form->isSubmitted() && $form->isValid()) {
  597.             $this->em->persist($project);
  598.             $this->em->flush();
  599.             $session->getFlashBag()->add('success''Mise à jour des informations');
  600.             return $this->redirectToRoute('cvs_gestion_candidates_generate_step4');
  601.         }
  602.         return $this->render('themesWebsite/cvs/gestion/candidates/generate/step4_edit.html.twig',[
  603.             'form' =>  $form->createView(),
  604.             'project' => $project
  605.         ]);
  606.     }
  607.     /**
  608.      * Confirmer la suppresison d'une expérience
  609.      * @param Request $request
  610.      * @param CandidatesHasExperiences $experience
  611.      * @return Response
  612.      * @throws \Exception
  613.      */
  614.     public function step4Remove(Request $requestCandidatesHasProjects $project): Response
  615.     {
  616.         $session $request->getSession();
  617.         $session->set("navbar-section","dashboard");
  618.         $session->set("sidebar-section","generate");
  619.         $user $this->getUser();
  620.         if($user == null) {
  621.             Throw new \Exception("Aucun utilisateur");
  622.         }
  623.         $candidate $user->getCandidate();
  624.         if($candidate == null) {
  625.             Throw new \Exception("Aucun CV");
  626.         }
  627.         if($project->getCandidate() != $candidate) {
  628.             Throw new \Exception("Mauvaise fiche");
  629.         }
  630.         return $this->render('themesWebsite/cvs/gestion/candidates/generate/step3_remove.html.twig',[
  631.             'project' => $project
  632.         ]);
  633.     }
  634.     /**
  635.      * Supprimer une expérience
  636.      * @param Request $request
  637.      * @param CandidatesHasExperiences $experience
  638.      * @return Response
  639.      * @throws \Exception
  640.      */
  641.     public function step4Delete(Request $requestCandidatesHasProjects $project): Response
  642.     {
  643.         $session $request->getSession();
  644.         $session->set("navbar-section","dashboard");
  645.         $session->set("sidebar-section","generate");
  646.         $user $this->getUser();
  647.         if($user == null) {
  648.             Throw new \Exception("Aucun utilisateur");
  649.         }
  650.         $candidate $user->getCandidate();
  651.         if($candidate == null) {
  652.             Throw new \Exception("Aucun CV");
  653.         }
  654.         if($project->getCandidate() != $candidate) {
  655.             Throw new \Exception("Mauvaise fiche");
  656.         }
  657.         $this->em->remove($project);
  658.         $this->em->flush();
  659.         $session->getFlashBag()->add('success''Mise à jour des informations');
  660.         return $this->redirectToRoute('cvs_gestion_candidates_generate_step4');
  661.     }
  662.     /**
  663.      * Mes compétences
  664.      * @param Request $request
  665.      * @return Response
  666.      * @throws \Exception
  667.      */
  668.     public function skills(Request $request): Response
  669.     {
  670.         $session $request->getSession();
  671.         $session->set("navbar-section","dashboard");
  672.         $session->set("sidebar-section","generate");
  673.         $user $this->getUser();
  674.         if($user == null) {
  675.             Throw new \Exception("Aucun utilisateur");
  676.         }
  677.         $candidate $user->getCandidate();
  678.         if($candidate == null) {
  679.             Throw new \Exception("Aucun CV");
  680.         }
  681.         $skill = new CandidatesHasSkills();
  682.         $skill->setCandidate($candidate);
  683.         $skill->setFav(false);
  684.         $form $this->createForm(SkillsForm::class, $skill);
  685.         $form->handleRequest($request);
  686.         if ($form->isSubmitted() && $form->isValid()) {
  687.             $this->em->persist($skill);
  688.             $this->em->flush();
  689.             $session->getFlashBag()->add('success''Mise à jour des informations');
  690.             return $this->redirectToRoute('cvs_gestion_candidates_generate_skills');
  691.         }
  692.         $skills $this->em->getRepository(CandidatesHasSkills::class)->findBy(['candidate' => $candidate]);
  693.         return $this->render('themesWebsite/cvs/gestion/candidates/generate/skills/list.html.twig',[
  694.             'form' =>  $form->createView(),
  695.             'skills' => $skills
  696.         ]);
  697.     }
  698.     /**
  699.      * Supprimer une compétence
  700.      * @param Request $request
  701.      * @param CandidatesHasExperiences $experience
  702.      * @return Response
  703.      * @throws \Exception
  704.      */
  705.     public function skillsEdit(Request $requestCandidatesHasSkills $skill): Response
  706.     {
  707.         $session $request->getSession();
  708.         $session->set("navbar-section","dashboard");
  709.         $session->set("sidebar-section","generate");
  710.         $user $this->getUser();
  711.         if($user == null) {
  712.             Throw new \Exception("Aucun utilisateur");
  713.         }
  714.         $candidate $user->getCandidate();
  715.         if($candidate == null) {
  716.             Throw new \Exception("Aucun CV");
  717.         }
  718.         if($skill->getCandidate() != $candidate) {
  719.             Throw new \Exception("Mauvaise fiche");
  720.         }
  721.         $form $this->createForm(SkillsForm::class, $skill);
  722.         $form->handleRequest($request);
  723.         if ($form->isSubmitted() && $form->isValid()) {
  724.             $this->em->persist($skill);
  725.             $this->em->flush();
  726.             $session->getFlashBag()->add('success''Mise à jour des informations');
  727.             return $this->redirectToRoute('cvs_gestion_candidates_generate_skills');
  728.         }
  729.         return $this->render('themesWebsite/cvs/gestion/candidates/generate/skills/edit.html.twig',[
  730.             'form' =>  $form->createView(),
  731.             'skill' => $skill
  732.         ]);
  733.     }
  734.     /**
  735.      * Supprimer une compétence
  736.      * @param Request $request
  737.      * @param CandidatesHasExperiences $experience
  738.      * @return Response
  739.      * @throws \Exception
  740.      */
  741.     public function skillsRemove(Request $requestCandidatesHasSkills $skill): Response
  742.     {
  743.         $session $request->getSession();
  744.         $session->set("navbar-section","dashboard");
  745.         $session->set("sidebar-section","generate");
  746.         $user $this->getUser();
  747.         if($user == null) {
  748.             Throw new \Exception("Aucun utilisateur");
  749.         }
  750.         $candidate $user->getCandidate();
  751.         if($candidate == null) {
  752.             Throw new \Exception("Aucun CV");
  753.         }
  754.         if($skill->getCandidate() != $candidate) {
  755.             Throw new \Exception("Mauvaise fiche");
  756.         }
  757.         return $this->render('themesWebsite/cvs/gestion/candidates/generate/skills/remove.html.twig',[
  758.             'skill' => $skill
  759.         ]);
  760.     }
  761.     /**
  762.      * Supprimer une compétence
  763.      * @param Request $request
  764.      * @param CandidatesHasExperiences $experience
  765.      * @return Response
  766.      * @throws \Exception
  767.      */
  768.     public function skillsDelete(Request $requestCandidatesHasSkills $skill): Response
  769.     {
  770.         $session $request->getSession();
  771.         $session->set("navbar-section","dashboard");
  772.         $session->set("sidebar-section","generate");
  773.         $user $this->getUser();
  774.         if($user == null) {
  775.             Throw new \Exception("Aucun utilisateur");
  776.         }
  777.         $candidate $user->getCandidate();
  778.         if($candidate == null) {
  779.             Throw new \Exception("Aucun CV");
  780.         }
  781.         if($skill->getCandidate() != $candidate) {
  782.             Throw new \Exception("Mauvaise fiche");
  783.         }
  784.         $this->em->remove($skill);
  785.         $this->em->flush();
  786.         $session->getFlashBag()->add('success''Mise à jour des informations');
  787.         return $this->redirectToRoute('cvs_gestion_candidates_generate_skills');
  788.     }
  789.     /**
  790.      * Réglages
  791.      * @param Request $request
  792.      * @return Response
  793.      * @throws \Exception
  794.      */
  795.     public function step5(Request $request): Response
  796.     {
  797.         $session $request->getSession();
  798.         $session->set("navbar-section","dashboard");
  799.         $session->set("sidebar-section","generate");
  800.         $user $this->getUser();
  801.         if($user == null) {
  802.             Throw new \Exception("Aucun utilisateur");
  803.         }
  804.         $candidate $user->getCandidate();
  805.         if($candidate == null) {
  806.             Throw new \Exception("Aucun CV");
  807.         }
  808.         $projects $this->em->getRepository(CandidatesHasProjects::class)->findBy(['candidate' => $candidate]);
  809.         /*
  810.         if($projects == null) {
  811.             return $this->redirectToRoute('cvs_gestion_candidates_generate_skills');
  812.         }*/
  813.         $form $this->createForm(CandidatesSettingsForm::class, $candidate);
  814.         $form->handleRequest($request);
  815.         if ($form->isSubmitted() && $form->isValid()) {
  816.             $data $request->request->all();
  817.             $this->em->persist($candidate);
  818.             $this->em->flush();
  819.             $session->getFlashBag()->add('success''Mise à jour des informations');
  820.             if($data['submit'] == "0") {
  821.                 return $this->redirectToRoute('cvs_gestion_candidates_generate_step4');
  822.             }
  823.             return $this->redirectToRoute('cvs_gestion_candidates_generate_validation');
  824.         }
  825.         $projects $this->em->getRepository(CandidatesHasProjects::class)->findBy(['candidate' => $candidate]);
  826.         return $this->render('themesWebsite/cvs/gestion/candidates/generate/step5.html.twig',[
  827.             'form' =>  $form->createView(),
  828.             'projects' => $projects
  829.         ]);
  830.     }
  831.     /**
  832.      * Valider le profil + valider l'invitation de l'inscription..
  833.      * @param Request $request
  834.      * @return Response
  835.      * @throws \Exception
  836.      */
  837.     public function validation(Request $requestUsers $us): Response
  838.     {
  839.         $session $request->getSession();
  840.         $session->set("navbar-section","dashboard");
  841.         $session->set("sidebar-section","generate");
  842.         $user $this->getUser();
  843.         if($user == null) {
  844.             Throw new \Exception("Aucun utilisateur");
  845.         }
  846.         $candidate $user->getCandidate();
  847.         if($candidate == null) {
  848.             Throw new \Exception("Aucun CV");
  849.         }
  850.         if(empty($candidate->getSlug())) {
  851.             $slug $us->getUniqueCvSlug(10);
  852.             $candidate->setSlug($slug);
  853.         }
  854.         if(empty($candidate->getSlugAnonyme())) {
  855.             $slug $us->getUniqueCvAnonymeSlug(10);
  856.             $candidate->setSlugAnonyme($slug);
  857.         }
  858.         if(empty($candidate->getInvitationCode())) {
  859.             $code $us->getUniqueCvInvitationCode(15);
  860.             $candidate->setInvitationCode($code);
  861.         }
  862.         if(empty($candidate->getInvitationCodeAnonyme())) {
  863.             $code $us->getUniqueCvInvitationCodeAnonyme(15);
  864.             $candidate->setInvitationcodeAnonyme($code);
  865.         }
  866.         $candidate->setFirst(false);
  867.         $this->em->persist($candidate);
  868.         $this->em->flush();
  869.         $shareInvitation $user->getShare();
  870.         if($shareInvitation !== null) {
  871.             $agencyTarget $shareInvitation->getAgencyTarget();
  872.             $userTarget $shareInvitation->getUserTarget();
  873.             $invitation =  $this->em->getRepository(Invitations::class)->findOneBy(['user' => $user]);
  874.             if($invitation === null) {
  875.                 $invitation = new Invitations();
  876.                 $invitation->setEmail(null);
  877.                 $invitation->setAgency(null);
  878.                 $invitation->setUser($user); // Candidat.
  879.                 $invitation->setAgencyTarget($agencyTarget); // Entreprise.
  880.                 $invitation->setUserTarget($userTarget); // Entreprise utilisateur.
  881.                 $invitation->setUserView(true);
  882.                 $invitation->setAgencyView(false);
  883.                 $this->em->persist($invitation);
  884.                 $this->em->flush();
  885.                 if($userTarget !== null) {
  886.                     $history $this->em->getRepository(History::class)->findOneBy(['user' => $user'userTarget' => $userTarget'anonyme' => true]);
  887.                     if($history === null) {
  888.                         $history = new History();
  889.                         $history->setAnonyme(true);
  890.                         $history->setAccepted(false);
  891.                         $history->setRefused(false);
  892.                         $history->setUser($user);
  893.                         $history->setUserTarget($userTarget);
  894.                         $history->setAgencyTarget($agencyTarget);
  895.                         $this->em->persist($history);
  896.                         $this->em->flush();
  897.                     }
  898.                     // Envoyer un mail !
  899.                     $this->sendEmailAnonyme($userTarget->getEmail(),$candidate->getSlugAnonyme());
  900.                 }
  901.             }
  902.         }
  903.         return $this->redirectToRoute('cvs_gestion_candidates_dashboard');
  904.     }
  905.     /**
  906.      * Envoyer un CV anonyme d'une invitation directement.
  907.      * @param $emailTarget
  908.      * @param $slugAnonyme
  909.      * @return true|null
  910.      */
  911.     private function sendEmailAnonyme($emailTarget,$slugAnonyme)
  912.     {
  913.         $templateMail $this->em->getRepository(Mails::class)->findOneBy(['name' => "new_cv_anonyme"]);
  914.         if($templateMail == null) {
  915.             return null;
  916.         }
  917.         $subject $templateMail->getTitle();
  918.         $description $templateMail->getDescription();
  919.         $pathCV = (string)$this->generateUrl('cvs_application_cv_anonyme', ['slug' => $slugAnonyme], UrlGeneratorInterface::ABSOLUTE_URL);
  920.         $searchHTML = ['%EMAIL%','%PATH_CV%','%SLUG%'];
  921.         $replaceHTML = [$emailTarget,$pathCV,$slugAnonyme];
  922.         $cleanSubject str_replace($searchHTML$replaceHTML$subject);
  923.         $cleanDescription str_replace($searchHTML$replaceHTML$description);
  924.         $this->ms->register($cleanSubject,$cleanDescription,null,$emailTarget,null,null);
  925.         return true;
  926.     }
  927. }