src/Controller/OffresController.php line 42

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\ChampScientifique;
  4. use App\Entity\TypePoste;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Doctrine\Persistence\ManagerRegistry;
  10. use App\Service\sendNotification;
  11. use App\Service\logCandidatureService;
  12. use Symfony\Component\Finder\Exception\AccessDeniedException as ExceptionAccessDeniedException;
  13. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  14. use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
  15. use App\Entity\User;
  16. use App\Entity\Candidature;
  17. use App\Entity\PropositionRecrutement;
  18. use App\Entity\Demandeur;
  19. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  20. use Symfony\Component\Security\Http\Authentication\UserAuthenticatorInterface;
  21. use App\Form\RegistrationFormType;
  22. use App\Form\Type\CandidatureType;
  23. use App\Form\Type\EditCandidatureType;
  24. use App\Security\AppCustomAuthenticator;
  25. use App\Form\Type\CandidatureAcceptType;
  26. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  27. use Symfony\Component\HttpFoundation\File\Exception\FileException;
  28. use Symfony\Component\HttpFoundation\File\UploadedFile;
  29. use Symfony\Component\String\Slugger\SluggerInterface;
  30. use Symfony\Component\HttpFoundation\File\File;
  31. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  32. use Knp\Component\Pager\PaginatorInterface;
  33. class OffresController extends AbstractController
  34. {
  35.     /**
  36.      * @Route("/offres/{lang}", name="app_offres_index", defaults={"lang": "fr"})
  37.      */
  38.     public function index(Request $requestManagerRegistry $doctrinePaginatorInterface $paginator$lang): Response
  39.     {
  40.         $entityManager $doctrine->getManager();
  41.         // Filtre
  42.         $filtre $request->get("filtre");
  43.         $tri    $request->get("tri");
  44.         $sens   $request->get("sens");
  45.         $pagination $paginator->paginate ($entityManager->getRepository(Demandeur::class)->findForPublic($filtre$tri$sens), $request->get('page',1));
  46.         //$offres = $entityManager->getRepository(Demandeur::class)->findForPublic($filtre, $tri, $sens); 
  47.         $types_poste $entityManager->getRepository(TypePoste::class)->findAll(); 
  48.         $champs_scientifiques $entityManager->getRepository(ChampScientifique::class)->findAll();
  49.         foreach($champs_scientifiques as $key => $champs_scientifique) {
  50.             $champs_scientifique->setTranslatableLocale($lang);
  51.             $entityManager->refresh($champs_scientifique);
  52.             $champs_scientifiques[$key] = $champs_scientifique;
  53.         }
  54.         
  55.         return $this->renderForm('offres/index.html.twig', [
  56.             //'offres'                => $offres,
  57.             'pagination'                => $pagination,
  58.             'types_poste'           => $types_poste,
  59.             'champs_scientifiques'  => $champs_scientifiques,
  60.             'filtre' => $filtre,
  61.             'tri' => $tri,
  62.             'sens' => $sens,
  63.             'lang' => $lang
  64.         ]);
  65.     }
  66.     /**
  67.      * @Route("/iframe/offres/{lang}", name="app_offres_iframe", defaults={"lang": "fr"})
  68.      */
  69.     public function iframe(Request $requestManagerRegistry $doctrinePaginatorInterface $paginator$lang): Response
  70.     {
  71.         $entityManager $doctrine->getManager();
  72.         // Filtre
  73.         $filtre $request->get("filtre");
  74.         $tri    $request->get("tri");
  75.         $sens   $request->get("sens");
  76.         $pagination $paginator->paginate ($entityManager->getRepository(Demandeur::class)->findForPublic($filtre$tri$sens), $request->get('page',1));
  77.         //$offres = $entityManager->getRepository(Demandeur::class)->findForPublic($filtre, $tri, $sens); 
  78.         $types_poste $entityManager->getRepository(TypePoste::class)->findAll(); 
  79.         $champs_scientifiques $entityManager->getRepository(ChampScientifique::class)->findAll();
  80.         foreach($champs_scientifiques as $key => $champs_scientifique) {
  81.             $champs_scientifique->setTranslatableLocale($lang);
  82.             $entityManager->refresh($champs_scientifique);
  83.             $champs_scientifiques[$key] = $champs_scientifique;
  84.         }
  85.         
  86.         return $this->renderForm('offres/iframe.html.twig', [
  87.             //'offres'                => $offres,
  88.             'pagination'                => $pagination,
  89.             'types_poste'           => $types_poste,
  90.             'champs_scientifiques'  => $champs_scientifiques,
  91.             'filtre' => $filtre,
  92.             'tri' => $tri,
  93.             'sens' => $sens,
  94.             'lang' => $lang
  95.         ]);
  96.     }
  97.     /**
  98.      * @Route("/offres/voir/{id}/{lang}", name="app_offres_voir")
  99.      */
  100.     public function voir(   Request $request
  101.                             ManagerRegistry $doctrine
  102.                             $id,
  103.                             $lang='fr',
  104.                             UserAuthenticatorInterface $userAuthenticator,
  105.                             UserPasswordHasherInterface $userPasswordHasher,
  106.                             AppCustomAuthenticator $appAuthenticator,
  107.                             AuthenticationUtils $authenticationUtils,
  108.                             sendNotification $sendNotification
  109.                             SluggerInterface $slugger
  110.                             logCandidatureService $logCandidatureService
  111.                             ): Response
  112.     {
  113.         $entityManager $doctrine->getManager();
  114.         $session $request->getSession();
  115.         $demandeur $entityManager->getRepository(Demandeur::class)->find($id);
  116.         if(!$demandeur) {
  117.             throw new InvalidArgumentException("Cette demande n'existe pas");
  118.         }
  119.         if($demandeur->getEtat()->getId() != 5) {
  120.             throw new InvalidArgumentException("Cette offre n'a pas été validée");
  121.         }
  122.         // place l'id de l'offre en session pour une redirection après login
  123.         $session->getFlashBag()->get('redirect_id_demandeur');      // vider le "flashbag"
  124.         $session->getFlashBag()->add('redirect_id_demandeur'$id);
  125.         // Creation de compte
  126.         $user $this->getUser();
  127.         if(!$user) {
  128.             $user = new User();
  129.         }
  130.         $formRegister $this->createForm(RegistrationFormType::class, $user);
  131.         $formRegister->handleRequest($request);
  132.         if ($formRegister->isSubmitted() && $formRegister->isValid()) {
  133.             // username = email
  134.             $user->setUsername($formRegister->get('email')->getData());
  135.             // encode the plain password
  136.             $user->setPassword(
  137.                 $userPasswordHasher->hashPassword(
  138.                     $user,
  139.                     $formRegister->get('plainPassword')->getData()
  140.                 )
  141.             );
  142.             // Role
  143.             $user->setRoles(['ROLE_EN_ATTENTE']);
  144.             $user->setEmailValidationChecksum(md5("P13".time()));
  145.             $entityManager->persist($user);
  146.             $entityManager->flush();
  147.             $sendNotification->send("validation-email-creation-compte"NULL$user);
  148.             //return $userAuthenticator->authenticateUser($user, $appAuthenticator, $request);
  149.             
  150.             $session->getFlashBag()->add('message'"Votre inscription sera finalisée après validation de votre adresse email. Vous allez recevoir un message contenant un lien permettant de finaliser l'inscription.");
  151.             return $this->redirectToRoute('app_edito');
  152.         }
  153.         // FIN - Creation de compte
  154.         // Gestion du login
  155.         // get the login error if there is one
  156.         $error_login $authenticationUtils->getLastAuthenticationError();
  157.         // last username entered by the user
  158.         $lastUsername $authenticationUtils->getLastUsername();
  159.         // FIN - Gestion du login
  160.         // === Candidature
  161.         $candidature = new Candidature;
  162.         $candidature->setCreatedAt(new \DateTimeImmutable(date("Y-m-d H:i:s")));
  163.         $candidature->setDemandeur($demandeur);
  164.         $candidature->setUser($user);
  165.         $etat_candidature $entityManager->getReference('App\Entity\EtatCandidature'1);  // brouillon
  166.         $candidature->setEtatCandidature($etat_candidature);
  167.         $formCandidature $this->createForm(CandidatureType::class, $candidature);
  168.         $formCandidature->handleRequest($request);
  169.         if ($formCandidature->isSubmitted() && $formCandidature->isValid()) {
  170.             /** @var UploadedFile $fichierCv */
  171.             $fichierCv $formCandidature->get('fichierCv')->getData();
  172.             if ($fichierCv) {
  173.                 $originalFilename pathinfo($fichierCv->getClientOriginalName(), PATHINFO_FILENAME);
  174.                 $safeFilename $slugger->slug($originalFilename);                              // this is needed to safely include the file name as part of the URL
  175.                 $newFilename $safeFilename.'-'.uniqid().'.'.$fichierCv->guessExtension();
  176.                 try {                                                                           // Move the file to the directory where brochures are stored
  177.                     $fichierCv->move(
  178.                         $this->getParameter('cv_directory'),
  179.                         $newFilename
  180.                     );
  181.                 } catch (FileException $e) {
  182.                     $session->getFlashBag()->add('error'"Le fichier CV n'a pas pu être enregistré");
  183.                 }
  184.                 $candidature->setFichierCv($newFilename);
  185.             }
  186.             /** @var UploadedFile $fichierLm */
  187.             $fichierLm $formCandidature->get('fichierLm')->getData();
  188.             if ($fichierLm) {
  189.                 $originalFilename pathinfo($fichierLm->getClientOriginalName(), PATHINFO_FILENAME);
  190.                 $safeFilename $slugger->slug($originalFilename);                              // this is needed to safely include the file name as part of the URL
  191.                 $newFilename $safeFilename.'-'.uniqid().'.'.$fichierLm->guessExtension();
  192.                 try {                                                                           // Move the file to the directory where brochures are stored
  193.                     $fichierLm->move(
  194.                         $this->getParameter('lm_directory'),
  195.                         $newFilename
  196.                     );
  197.                 } catch (FileException $e) {
  198.                     $session->getFlashBag()->add('error'"Le fichier LM n'a pas pu être enregistré");
  199.                 }
  200.                 $candidature->setFichierLm($newFilename);
  201.             }
  202.             /** @var UploadedFile $fichierIdentite */
  203.             $fichierIdentite $formCandidature->get('fichierIdentite')->getData();
  204.             if ($fichierIdentite) {
  205.                 $originalFilename pathinfo($fichierIdentite->getClientOriginalName(), PATHINFO_FILENAME);
  206.                 $safeFilename $slugger->slug($originalFilename);                              // this is needed to safely include the file name as part of the URL
  207.                 $newFilename $safeFilename.'-'.uniqid().'.'.$fichierIdentite->guessExtension();
  208.                 try {                                                                           // Move the file to the directory where brochures are stored
  209.                     $fichierIdentite->move(
  210.                         $this->getParameter('identite_directory'),
  211.                         $newFilename
  212.                     );
  213.                 } catch (FileException $e) {
  214.                     $session->getFlashBag()->add('error'"Le fichier pièce d'identité n'a pas pu être enregistré");
  215.                 }
  216.                 $candidature->setFichierIdentite($newFilename);
  217.             }
  218.             /** @var UploadedFile $fichierDiplome */
  219.             $fichierDiplome $formCandidature->get('fichierDiplome')->getData();
  220.             if ($fichierDiplome) {
  221.                 $originalFilename pathinfo($fichierDiplome->getClientOriginalName(), PATHINFO_FILENAME);
  222.                 $safeFilename $slugger->slug($originalFilename);                              // this is needed to safely include the file name as part of the URL
  223.                 $newFilename $safeFilename.'-'.uniqid().'.'.$fichierDiplome->guessExtension();
  224.                 try {                                                                           // Move the file to the directory where brochures are stored
  225.                     $fichierDiplome->move(
  226.                         $this->getParameter('diplomes_directory'),
  227.                         $newFilename
  228.                     );
  229.                 } catch (FileException $e) {
  230.                     $session->getFlashBag()->add('error'"Le fichier Diplôme n'a pas pu être enregistré");
  231.                 }
  232.                 $candidature->setFichierDiplome($newFilename);
  233.             }
  234.             
  235.             /** @var UploadedFile $fichierRecommandation */
  236.             /*
  237.             $fichierRecommandation = $formCandidature->get('fichierRecommandation')->getData();
  238.             if ($fichierRecommandation) {
  239.                 $originalFilename = pathinfo($fichierRecommandation->getClientOriginalName(), PATHINFO_FILENAME);
  240.                 $safeFilename = $slugger->slug($originalFilename);                              // this is needed to safely include the file name as part of the URL
  241.                 $newFilename = $safeFilename.'-'.uniqid().'.'.$fichierRecommandation->guessExtension();
  242.                 try {                                                                           // Move the file to the directory where brochures are stored
  243.                     $fichierRecommandation->move(
  244.                         $this->getParameter('recommandation_directory'),
  245.                         $newFilename
  246.                     );
  247.                 } catch (FileException $e) {
  248.                     $session->getFlashBag()->add('error', "La lettre de recommendation n'a pas pu être enregistrée");
  249.                 }
  250.                 $candidature->setFichierRecommandation($newFilename);
  251.             }*/
  252.             $etat_candidature $entityManager->getReference('App\Entity\EtatCandidature'2);   // En attente de validation par l'administrateur
  253.             $candidature->setEtatCandidature($etat_candidature);
  254.             // Civilité
  255.             if($formCandidature->get("civilite")->getData()) {
  256.                 $user->setCivilite($formCandidature->get("civilite")->getData());
  257.                 $entityManager->persist($user);
  258.             }
  259.             $entityManager->persist($candidature);
  260.             $entityManager->flush();
  261.             // logCandidature
  262.             $logCandidatureService->log("Création de la candidature par le candidat"$candidature$user);
  263.            
  264.             $session->getFlashBag()->add('message'"Votre candidature a été enregistrée. Elle va être examinée par un administrateur.");
  265.         }
  266.         // FIN Candidature
  267.         // test de candidatures existante
  268.         $candidatures_existantes $entityManager->getRepository(Candidature::class)->findBy(['demandeur' => $demandeur'user' => $user]);
  269.         
  270.         $demandeur->setTranslatableLocale($lang);
  271.         $entityManager->refresh($demandeur);
  272.         return $this->renderForm('offres/voir.html.twig', [
  273.             'demandeur'                => $demandeur,
  274.             'registrationForm'         => $formRegister,
  275.             'candidatureForm'          => $formCandidature,
  276.             'error_login'              => $error_login,
  277.             'last_username'            => $lastUsername,
  278.             'lang'                     => $lang,
  279.             'candidatures_existantes'  => $candidatures_existantes
  280.         ]);
  281.     }
  282.     
  283.     /**
  284.      * @Route("/user/mes-candidatures/edit/{id}", name="app_candidature_edit")
  285.      */
  286.     public function editCandidature(   Request $request
  287.                             ManagerRegistry $doctrine
  288.                             $id,
  289.                             $lang='fr',
  290.                             sendNotification $sendNotification
  291.                             SluggerInterface $slugger
  292.                             logCandidatureService $logCandidatureService
  293.                             ): Response
  294.     {
  295.         $entityManager $doctrine->getManager();
  296.         $session $request->getSession();
  297.         $user $this->getUser();
  298.         $candidature $entityManager->getRepository(Candidature::class)->find($id);
  299.         if(!$candidature) {
  300.             throw new InvalidArgumentException("Cette candidature n'existe pas");
  301.         }
  302.         if( !($candidature->getEtatCandidature()->getId() == || $candidature->getEtatCandidature()->getId() == 3)) {
  303.             throw new InvalidArgumentException("Cette candidature n'est pas éditable");
  304.         }
  305.         if( $candidature->getUser()->getId() != $user->getId()) {
  306.             throw new InvalidArgumentException("Cette candidature n'est pas liée a votre compte");
  307.         }
  308.         $formCandidature $this->createForm(EditCandidatureType::class, $candidature);
  309.         $formCandidature->handleRequest($request);
  310.         if ($formCandidature->isSubmitted() && $formCandidature->isValid()) {
  311.             /** @var UploadedFile $fichierCv */
  312.             $fichierCv $formCandidature->get('fichierCv')->getData();
  313.             if ($fichierCv) {
  314.                 $originalFilename pathinfo($fichierCv->getClientOriginalName(), PATHINFO_FILENAME);
  315.                 $safeFilename $slugger->slug($originalFilename);                              // this is needed to safely include the file name as part of the URL
  316.                 $newFilename $safeFilename.'-'.uniqid().'.'.$fichierCv->guessExtension();
  317.                 try {                                                                           // Move the file to the directory where brochures are stored
  318.                     $fichierCv->move(
  319.                         $this->getParameter('cv_directory'),
  320.                         $newFilename
  321.                     );
  322.                 } catch (FileException $e) {
  323.                     $session->getFlashBag()->add('error'"Le fichier CV n'a pas pu être enregistré");
  324.                 }
  325.                 $candidature->setFichierCv($newFilename);
  326.             }
  327.             /** @var UploadedFile $fichierLm */
  328.             $fichierLm $formCandidature->get('fichierLm')->getData();
  329.             if ($fichierLm) {
  330.                 $originalFilename pathinfo($fichierLm->getClientOriginalName(), PATHINFO_FILENAME);
  331.                 $safeFilename $slugger->slug($originalFilename);                              // this is needed to safely include the file name as part of the URL
  332.                 $newFilename $safeFilename.'-'.uniqid().'.'.$fichierLm->guessExtension();
  333.                 try {                                                                           // Move the file to the directory where brochures are stored
  334.                     $fichierLm->move(
  335.                         $this->getParameter('lm_directory'),
  336.                         $newFilename
  337.                     );
  338.                 } catch (FileException $e) {
  339.                     $session->getFlashBag()->add('error'"Le fichier LM n'a pas pu être enregistré");
  340.                 }
  341.                 $candidature->setFichierLm($newFilename);
  342.             }
  343.             /** @var UploadedFile $fichierIdentite */
  344.             $fichierIdentite $formCandidature->get('fichierIdentite')->getData();
  345.             if ($fichierIdentite) {
  346.                 $originalFilename pathinfo($fichierIdentite->getClientOriginalName(), PATHINFO_FILENAME);
  347.                 $safeFilename $slugger->slug($originalFilename);                              // this is needed to safely include the file name as part of the URL
  348.                 $newFilename $safeFilename.'-'.uniqid().'.'.$fichierIdentite->guessExtension();
  349.                 try {                                                                           // Move the file to the directory where brochures are stored
  350.                     $fichierIdentite->move(
  351.                         $this->getParameter('identite_directory'),
  352.                         $newFilename
  353.                     );
  354.                 } catch (FileException $e) {
  355.                     $session->getFlashBag()->add('error'"Le fichier pièce d'identité n'a pas pu être enregistré");
  356.                 }
  357.                 $candidature->setFichierIdentite($newFilename);
  358.             }
  359.             /** @var UploadedFile $fichierDiplome */
  360.             $fichierDiplome $formCandidature->get('fichierDiplome')->getData();
  361.             if ($fichierDiplome) {
  362.                 $originalFilename pathinfo($fichierDiplome->getClientOriginalName(), PATHINFO_FILENAME);
  363.                 $safeFilename $slugger->slug($originalFilename);                              // this is needed to safely include the file name as part of the URL
  364.                 $newFilename $safeFilename.'-'.uniqid().'.'.$fichierDiplome->guessExtension();
  365.                 try {                                                                           // Move the file to the directory where brochures are stored
  366.                     $fichierDiplome->move(
  367.                         $this->getParameter('diplomes_directory'),
  368.                         $newFilename
  369.                     );
  370.                 } catch (FileException $e) {
  371.                     $session->getFlashBag()->add('error'"Le fichier Diplôme n'a pas pu être enregistré");
  372.                 }
  373.                 $candidature->setFichierDiplome($newFilename);
  374.             }
  375.             
  376.             /** @var UploadedFile $fichierRecommandation */
  377.             /*
  378.             $fichierRecommandation = $formCandidature->get('fichierRecommandation')->getData();
  379.             if ($fichierRecommandation) {
  380.                 $originalFilename = pathinfo($fichierRecommandation->getClientOriginalName(), PATHINFO_FILENAME);
  381.                 $safeFilename = $slugger->slug($originalFilename);                              // this is needed to safely include the file name as part of the URL
  382.                 $newFilename = $safeFilename.'-'.uniqid().'.'.$fichierRecommandation->guessExtension();
  383.                 try {                                                                           // Move the file to the directory where brochures are stored
  384.                     $fichierRecommandation->move(
  385.                         $this->getParameter('recommandation_directory'),
  386.                         $newFilename
  387.                     );
  388.                 } catch (FileException $e) {
  389.                     $session->getFlashBag()->add('error', "La lettre de recommendation n'a pas pu être enregistrée");
  390.                 }
  391.                 $candidature->setFichierRecommandation($newFilename);
  392.             }*/
  393.             $etat_candidature $entityManager->getReference('App\Entity\EtatCandidature'2);   // En attente de validation par l'administrateur
  394.             $candidature->setEtatCandidature($etat_candidature);
  395.             $entityManager->persist($candidature);
  396.             $entityManager->flush();
  397.             // logCandidature
  398.             $logCandidatureService->log("Modification de la candidature par le candidat"$candidature$user);
  399.            
  400.             $session->getFlashBag()->add('message'"Votre candidature a été enregistrée. Elle va être examinée par un administrateur.");
  401.             return $this->redirectToRoute('mes_candidatures');
  402.             
  403.         }
  404.         // FIN Candidature
  405.         return $this->renderForm('offres/editCandidature.html.twig', [
  406.             'candidature'              => $candidature,
  407.             'candidatureForm'          => $formCandidature,
  408.             'lang'                     => $lang
  409.         ]);
  410.     }
  411.     /**
  412.      * @Route("/candidature/voir-pj/{type}/{id_candidature}", name="candidature_voir_pj")
  413.      */
  414.     public function voirPJ($type$id_candidature,
  415.                             Request $request
  416.                             ManagerRegistry $doctrine
  417.                           
  418.     {
  419.         $entityManager $doctrine->getManager();
  420.         $session $request->getSession();
  421.         $filePath="";
  422.         /** @var Candidature $candidature */
  423.         $candidature $entityManager->getRepository(Candidature::class)->find($id_candidature);
  424.         if(!$candidature
  425.         {
  426.             throw new InvalidArgumentException("Cette candidature n'existe pas");
  427.         }
  428.         // TODO: vérification des droits
  429.         if($type == 'cv')
  430.         {
  431.             $filePath $this->getParameter('cv_directory')."/".$candidature->getFichierCv();
  432.             if(file_exists($filePath)) {
  433.                 $file = new File($filePath);
  434.                 return $this->file($filenullResponseHeaderBag::DISPOSITION_INLINE);
  435.             }
  436.         }
  437.         if($type == 'lm')
  438.         {
  439.             $filePath $this->getParameter('lm_directory')."/".$candidature->getFichierLm();
  440.             if(file_exists($filePath)) {
  441.                 $file = new File($filePath);
  442.                 return $this->file($filenullResponseHeaderBag::DISPOSITION_INLINE);
  443.             }
  444.         }
  445.         if($type == 'diplome')
  446.         {
  447.             $filePath $this->getParameter('diplomes_directory')."/".$candidature->getFichierDiplome();
  448.             if(file_exists($filePath)) {
  449.                 $file = new File($filePath);
  450.                 return $this->file($filenullResponseHeaderBag::DISPOSITION_INLINE);
  451.             }
  452.         }
  453.         if($type == 'recommendation')
  454.         {
  455.             $filePath $this->getParameter('recommandation_directory')."/".$candidature->getFichierRecommandation();
  456.             if(file_exists($filePath)) {
  457.                 $file = new File($filePath);
  458.                 return $this->file($filenullResponseHeaderBag::DISPOSITION_INLINE);
  459.             }
  460.         }
  461.         if($type == 'identite')
  462.         {
  463.             $filePath $this->getParameter('identite_directory')."/".$candidature->getFichierIdentite();
  464.             if(file_exists($filePath)) {
  465.                 $file = new File($filePath);
  466.                 return $this->file($filenullResponseHeaderBag::DISPOSITION_INLINE);
  467.             }
  468.         }
  469.         throw new InvalidArgumentException("Fichier introuvable : ".$filePath);
  470.     }
  471.     /**
  472.      * @Route("/user/mes-candidatures", name="mes_candidatures")
  473.      */
  474.     public function mesCandidatures(
  475.                             Request $request
  476.                             ManagerRegistry $doctrine
  477.                           
  478.     {
  479.         $entityManager $doctrine->getManager();
  480.         $candidatures $entityManager->getRepository(Candidature::class)->findBy(['user' => $this->getUser()]);
  481.         return $this->renderForm('offres/mesCandidatures.html.twig', [
  482.             'candidatures'                => $candidatures,
  483.         ]);
  484.     }
  485.     /**
  486.      * @Route("/user/mes-candidatures/accepte/{id}", name="app_candidature_accepte")
  487.      */
  488.     public function accepteCandidature(   Request $request
  489.                             ManagerRegistry $doctrine
  490.                             $id,
  491.                             $lang='fr',
  492.                             sendNotification $sendNotification
  493.                             logCandidatureService $logCandidatureService
  494.                             ): Response
  495.     {
  496.         $entityManager $doctrine->getManager();
  497.         $session $request->getSession();
  498.         $user_connected $this->getUser();
  499.         $candidature $entityManager->getRepository(Candidature::class)->find($id);
  500.         if(!$candidature) {
  501.             throw new InvalidArgumentException("Cette candidature n'existe pas");
  502.         }
  503.         if($candidature->getEtatCandidature()->getId() != 6) {
  504.             throw new InvalidArgumentException("Cette candidature n'est pas retenue");
  505.         }
  506.         if( $candidature->getUser()->getId() != $user_connected->getId()) {
  507.             throw new InvalidArgumentException("Cette candidature n'est pas liée a votre compte");
  508.         }
  509.         $formCandidature $this->createForm(CandidatureAcceptType::class, $candidature);
  510.         $formCandidature->handleRequest($request);
  511.         if ($formCandidature->isSubmitted() && $formCandidature->isValid()) {
  512.             
  513.             $etat_candidature $entityManager->getReference('App\Entity\EtatCandidature'7);   // Invitation acceptée
  514.             $candidature->setEtatCandidature($etat_candidature);
  515.             $entityManager->persist($candidature);
  516.             $entityManager->flush();
  517.             // logCandidature
  518.             $logCandidatureService->log("Invitation acceptée par le candidat"$candidature$user_connected);
  519.             $session->getFlashBag()->add('message'"Votre candidature est acceptée, vous allez être contacté par le gestionnaire et recevoir une proposition de recrutement.");
  520.             // notifiaction email aux admin 
  521.             $sendNotification->send("notification-acceptation-candidat"$candidature->getDemandeur(), $candidature->getUser(), $candidature);
  522.             // Notification de refus email aux autres candidats
  523.             $candidatures $entityManager->getRepository(Candidature::class)->findByDemandeurOrderByRang($candidature->getDemandeur());    
  524.             $etat_candidature_refus $entityManager->getReference('App\Entity\EtatCandidature'9);   // refusée 
  525.             foreach($candidatures as $candidature_refus) {
  526.                 if($candidature_refus->getId() != $candidature->getId()) {
  527.                     $candidature_refus->setEtatCandidature($etat_candidature_refus);
  528.                     $entityManager->persist($candidature_refus);
  529.                     $entityManager->flush();
  530.                     // logCandidature
  531.                     $logCandidatureService->log("Candidature refusée après acceptation du candidat de rang ".$candidature->getRang()." Email de refus envoyé"$candidature_refus$user_connected);
  532.                     $sendNotification->send("refus-apres-confirmation-du-candidat-1"$candidature->getDemandeur(), $candidature_refus->getUser(), $candidature_refus);
  533.                 }
  534.             }
  535.             return $this->redirectToRoute('mes_candidatures');
  536.             
  537.         }
  538.         // FIN Candidature
  539.         return $this->renderForm('offres/accepteCandidature.html.twig', [
  540.             'candidature'              => $candidature,
  541.             'candidatureForm'          => $formCandidature,
  542.             'lang'                     => $lang
  543.         ]);
  544.     }
  545.     /**
  546.      * @Route("/candidature/voir-proposition/{id_proposition}", name="candidature_voir_proposition")
  547.      */
  548.     public function voirProposition($id_proposition,
  549.                             Request $request
  550.                             ManagerRegistry $doctrine,
  551.                             logCandidatureService $logCandidatureService
  552.                           
  553.     {
  554.         $entityManager $doctrine->getManager();
  555.         $session $request->getSession();
  556.         $user_connected $this->getUser();
  557.         $filePath="";
  558.         /** @var Candidature $candidature */
  559.         $propositionRecrutement $entityManager->getRepository(PropositionRecrutement::class)->find($id_proposition);
  560.         if(!$propositionRecrutement
  561.         {
  562.             throw new InvalidArgumentException("Cette proposition n'existe pas");
  563.         }
  564.         if( $propositionRecrutement->getCandidature()->getUser()->getId() != $user_connected->getId()) {
  565.             throw new InvalidArgumentException("Cette proposition n'est pas liée a votre compte");
  566.         }
  567.         if($request->get("signer")) {
  568.             $etat_proposition $entityManager->getReference('App\Entity\EtatPropositionRecrutement'3);         // signée
  569.             $propositionRecrutement->setEtat($etat_proposition);
  570.             $entityManager->persist($propositionRecrutement);
  571.             $entityManager->flush();
  572.             // logCandidature
  573.             $logCandidatureService->log("Signature par le candidat de la proposition de recrutement"$propositionRecrutement->getCandidature(), $user_connected);
  574.             
  575.             $session->getFlashBag()->add('message'"Votre signature a bien été enregistrée.");
  576.         }
  577.         return $this->renderForm('offres/voirPropositionRecrutement.html.twig', [
  578.             'propositionRecrutement'              => $propositionRecrutement,
  579.         ]);
  580.     }
  581. }