src/Controller/Frontend/CandidatController.php line 46

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Frontend;
  3. use App\Entity\RecCandidat;
  4. use App\Entity\RecCandidature;
  5. use App\Entity\RecCandidatureStatut;
  6. use App\Entity\RecCategoryPopulation;
  7. use App\Entity\RecDocument;
  8. use App\Entity\RecMouvementInterne;
  9. use App\Entity\RecParameters;
  10. use App\Entity\RecPoste;
  11. use App\Entity\RecTypePopulation;
  12. use App\Form\RecCandidatType;
  13. use App\Form\RecCandidatProfilType;
  14. use App\Form\RecCandidatPwdType;
  15. use App\Form\Model\Registration;
  16. use App\Form\Type\RegistrationType;
  17. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. use Symfony\Component\HttpFoundation\JsonResponse;
  20. use Symfony\Component\HttpFoundation\Response;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  23. use Symfony\Component\Mailer\MailerInterface;
  24. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  25. use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
  26. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  27. use Symfony\Component\Security\Core\Security;
  28. use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
  29. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  30. use Doctrine\Common\Collections\ArrayCollection;
  31. class CandidatController extends AbstractController
  32. {
  33.     /**
  34.      * @Route("/", name="frontend_candidat", host="%recrutement_subdomain%", methods={"GET","POST"})
  35.      * @Route("/poste/{poste}", name="frontend_candidat_poste", host="%recrutement_subdomain%", methods={"GET","POST"})
  36.      */
  37.     public function index(AuthenticationUtils $authenticationUtils,EncoderFactoryInterface $encoderFactoryMailerInterface $mailer$poste=false)
  38.     {
  39.         $em $this->getDoctrine()->getManager();
  40.         $poste_title "";
  41.         $poste_description "";
  42.         $poste_fiche false;
  43.         $poste_annexe false;
  44.         $is_spontanefalse;
  45.         $private=false;
  46.         $type="";
  47.         $message="";
  48.         $cats $em->getRepository(RecCategoryPopulation::class)->findBy(['archive'=>false]);
  49.         $parameters $em->getRepository(RecParameters::class)->find(1);
  50.         $postesByCategory = array();
  51.         foreach($cats as $cat)
  52.         {
  53.             $p $em->getRepository(RecPoste::class)->getPostes($cat->getId());
  54.             $postesByCategory[$cat->getId()]=$p;
  55.         }
  56.         if($poste)
  57.         {
  58.             $entity $em->getRepository(RecPoste::class);
  59.             $q $entity
  60.                 ->createQueryBuilder('p')
  61.                 ->where('p.idInterne = :idInterne')
  62.                 ->setParameter('idInterne'$poste)
  63.                 ->getQuery();
  64.             $poste_cand $q->getOneOrNullResult();
  65.             if(!$poste_cand)
  66.                 return $this->redirect($this->generateUrl('frontend_candidat'));
  67.             else
  68.             {
  69.                 $now = new \DateTime('now');
  70.                 if(($now>=$poste_cand->getOpenDate() && $now<=$poste_cand->getCloseDate()) || $poste_cand->getIsSpontane()==true)
  71.                 {
  72.                     $poste_title $poste_cand->getTitle();
  73.                     $poste_description $poste_cand->getDescription();
  74.                     $poste_fiche $poste_cand->getFiche();
  75.                     $poste_annexe $poste_cand->getAnnexe();
  76.                     $is_spontane $poste_cand->getIsSpontane();
  77.                     $private $poste_cand->getTypePopulation()->getPrivate();
  78.                 }
  79.                 else
  80.                     return $this->redirect($this->generateUrl('frontend_candidat'));
  81.             }
  82.         }
  83.         // Gestion du login
  84.         $request Request::createFromGlobals();
  85.         // get the login error if there is one
  86.         $error $authenticationUtils->getLastAuthenticationError();
  87.         // last username entered by the user
  88.         $lastUsername $authenticationUtils->getLastUsername();
  89.         $form $this->createForm(RecCandidatType::class,new RecCandidat());
  90.         if ($request->getMethod() == 'POST') {
  91.             $form->handleRequest($request);
  92.             if ($form->isValid() && $poste) {
  93.                 $user $form->getData();
  94.                 $em $this->getDoctrine()->getManager();
  95.                 $user_exist $em->getRepository(RecCandidat::class)->findUser($user->getEmail());
  96.                 if(!$user_exist)
  97.                 {
  98.                     $encoder $encoderFactory->getEncoder($user);
  99.                     $passmail $user->getPassword();
  100.                     $password $encoder->encodePassword($user->getPassword(), $user->getSalt());
  101.                     $user->setPassword($password);
  102.                     $user->setNom(strtoupper($user->getNom()));
  103.                     $user->setPrenom(ucfirst(strtolower($user->getPrenom())));
  104.                     $user->setAdresse(ucwords(strtolower($user->getAdresse())));
  105.                     $user->setVille(ucwords(strtolower($user->getVille())));
  106.                     $user->setPays(ucwords(strtolower($user->getPays())));
  107.                     $entity $em->getRepository(RecPoste::class);
  108.                     $q $entity
  109.                         ->createQueryBuilder('p')
  110.                         ->where('p.idInterne = :idInterne')
  111.                         ->setParameter('idInterne'trim($poste))
  112.                         ->getQuery();
  113.                     $poste_cand $q->getSingleResult();
  114.                     $candidature = new RecCandidature();
  115.                     $candidature->setPoste($poste_cand);
  116.                     $candidature->setCandidat($user);
  117.                     $entity $em->getRepository(RecCandidatureStatut::class);
  118.                     $q $entity
  119.                         ->createQueryBuilder('p')
  120.                         ->where('p.id = :id')
  121.                         ->setParameter('id',1)
  122.                         ->getQuery();
  123.                     $statut$q->getOneOrNullResult();
  124.                     if($statut)
  125.                         $candidature->setCandidatureStatut($statut);
  126.                     $user->addCandidature($candidature);
  127.                     $poste_cand->addCandidature($candidature);
  128.                     $em->persist($candidature);
  129.                     $em->persist($user);
  130.                     $em->persist($poste_cand);
  131.                     $em->flush();
  132.                     $mail_noreply $this->container->get('parameter_bag')->get('mail_noreply');
  133.                     $site_short_name $this->container->get('parameter_bag')->get('site_short_name');
  134.                     $signature_rh_recrutement $poste_cand->getTypePopulation()->getSignatureMail();
  135.                     if(trim($signature_rh_recrutement)=='')
  136.                         $signature_rh_recrutement $this->container->get('parameter_bag')->get('signature_rh_recrutement');
  137.                     $mail = (new TemplatedEmail())
  138.                         ->from($mail_noreply)
  139.                         ->to($user->getEmail())
  140.                         ->subject('['.$site_short_name.'] Votre création de compte pour le poste')
  141.                         ->htmlTemplate('Courriel/create.html.twig')
  142.                         ->context(['user' => $user,'serveur'=>$_SERVER['HTTP_HOST'],'poste'=>$poste,'signature_rh_recrutement'=>$signature_rh_recrutement]);
  143.                     try{
  144.                         $mailer->send($mail);
  145.                         $error false;
  146.                     }catch(TransportExceptionInterface $e) {
  147.                         $response $e->getMessage();
  148.                         $error true;
  149.                     }
  150.                     return $this->render('Frontend/Candidat/index.html.twig', array('form' => $form->createView(),'last_username' => $lastUsername,
  151.                         'error' => $error,'parameters'=>$parameters,'poste'=> false,'message'=>"Un courriel vient d'être envoyé Ã  l'adresse : ".$user->getEmail()." afin de valider votre compte.",'poste_title'=>$poste_title,'postesByCategory'=>$postesByCategory,'cats'=>$cats,'poste_description'=>$poste_description,'poste_annexe'=>$poste_annexe,'poste_fiche'=>$poste_fiche,'private'=>$private,"message_type"=>"success",'is_spontane'=>$is_spontane));
  152.                 }
  153.                 else
  154.                     return $this->render('Frontend/Candidat/index.html.twig', array('form' => $form->createView(),'last_username' => $lastUsername,
  155.                         'error' => $error,'parameters'=>$parameters,'poste'=>$poste,'poste_title'=>$poste_title,'private'=>$private,'poste_description'=>$poste_description,'poste_annexe'=>$poste_annexe,'poste_fiche'=>$poste_fiche,'postesByCategory'=>$postesByCategory,'cats'=>$cats'message'=>"Vous disposez déjà d'un compte Ã  cette adresse !","message_type"=>"danger",'is_spontane'=>$is_spontane));
  156.             }
  157.             if(!$form->isValid())
  158.             {
  159.                 $post $request->request->get('rec_candidat');
  160.                 $password $post['password']['password'];
  161.                 $confirmation =  $post['password']['confirmation'];
  162.                 if($password!=$confirmation)
  163.                 {
  164.                     $message "Le mots de passe et la confirmation doivent correspondre";
  165.                     $type="danger";
  166.                 }
  167.                 else if(strlen($password)<7)
  168.                 {
  169.                     $message "Mot de passe inférieur Ã  7 caractères";
  170.                     $type="danger";
  171.                 }
  172.             }
  173.         }
  174.         return $this->render('Frontend/Candidat/index.html.twig', array('form' => $form->createView(),'last_username' => $lastUsername,
  175.             'error' => $error,'parameters'=>$parameters'poste'=>$poste,'poste_title'=>$poste_title,'private'=>$private,'poste_description'=>$poste_description,'poste_annexe'=>$poste_annexe,'poste_fiche'=>$poste_fiche,'postesByCategory'=>$postesByCategory,'cats'=>$cats,'message'=>$message,"message_type"=>$type,'is_spontane'=>$is_spontane));
  176.     }
  177.     /**
  178.      * @Route("/candidat-externe", name="frontend_candidat_externe_view", host="%recrutement_subdomain%", methods={"GET"})
  179.      * @Route("/candidat-interne", name="frontend_candidat_interne_view", host="%recrutement_subdomain%", methods={"GET"})
  180.      */
  181.     public function view()
  182.     {
  183.         $request Request::createFromGlobals();
  184.         $referer $request->headers->get('referer');
  185.         $em $this->getDoctrine()->getManager();
  186.         $pos strpos($referer,'/poste/');
  187.         $user $this->get('security.token_storage')->getToken()->getUser();
  188.         $candidat $em->getRepository(RecCandidat::class)->loadUserByUsername($user->getEmail());
  189.         $mouvementInterne $em->getRepository(RecMouvementInterne::class)->getActive();
  190.         $formPwd $this->createForm(RecCandidatPwdType::class);
  191.         if($pos)
  192.         {
  193.             $pos+=7;
  194.             $id_poste=substr($referer,$pos,strlen($referer)-$pos);
  195.             $entity $em->getRepository(RecCandidature::class);
  196.             $q $entity
  197.                 ->createQueryBuilder('c')
  198.                 ->leftJoin('c.poste','p')
  199.                 ->leftJoin('c.candidat','u')
  200.                 ->where('p.idInterne = :idInterne')
  201.                 ->andWhere('u.id = :user')
  202.                 ->setParameter('idInterne'$id_poste)
  203.                 ->setParameter('user'$candidat->getId())
  204.                 ->getQuery();
  205.             $candidature $q->getOneOrNullResult();
  206.             if(!$candidature)
  207.             {
  208.                 $entity $em->getRepository(RecPoste::class);
  209.                 $q $entity
  210.                     ->createQueryBuilder('p')
  211.                     ->where('p.idInterne = :idInterne')
  212.                     ->setParameter('idInterne'$id_poste)
  213.                     ->getQuery();
  214.                 $poste_cand $q->getOneOrNullResult();
  215.                 if($poste_cand)
  216.                 {
  217.                     $candidature = new RecCandidature();
  218.                     $candidature->setPoste($poste_cand);
  219.                     $candidature->setCandidat($user);
  220.                     $entity $em->getRepository(RecCandidatureStatut::class);
  221.                     $q $entity
  222.                         ->createQueryBuilder('p')
  223.                         ->where('p.id = :id')
  224.                         ->setParameter('id',1)
  225.                         ->getQuery();
  226.                     $statut$q->getOneOrNullResult();
  227.                     if($statut)
  228.                         $candidature->setCandidatureStatut($statut);
  229.                     $user->addCandidature($candidature);
  230.                     $poste_cand->addCandidature($candidature);
  231.                     $em->persist($candidature);
  232.                     $em->persist($user);
  233.                     $em->persist($poste_cand);
  234.                     $em->flush();
  235.                     $candidatures $user->getCandidaturesInInit();
  236.                     return $this->render('Frontend/Candidature/candidate.html.twig',array('candidatures'=>$candidatures));
  237.                 }
  238.                 else
  239.                     return $this->render('Frontend/Candidat/view.html.twig',array('candidatures'=>$candidat->getCandidatures(),'mouvementInterne'=>$mouvementInterne,'dossiers'=>$candidat->getDossiers(),"formPwd"=>$formPwd->createView()));
  240.             }
  241.             else
  242.             {
  243.                 $candidatures $candidat->getCandidaturesInInit();
  244.                 if($candidatures)
  245.                 {
  246.                     return $this->render('Frontend/Candidature/candidate.html.twig',array('candidatures'=>$candidatures));
  247.                 }
  248.                 else
  249.                     return $this->render('Frontend/Candidat/view.html.twig',array('candidatures'=>$candidat->getCandidatures(),'mouvementInterne'=>$mouvementInterne,'dossiers'=>$candidat->getDossiers(),"formPwd"=>$formPwd->createView()));
  250.             }
  251.         }
  252.         else
  253.         {
  254.             $candidatures $candidat->getCandidaturesInInit();
  255.             if($candidatures)
  256.             {
  257.                 return $this->render('Frontend/Candidature/candidate.html.twig',array('candidatures'=>$candidatures));
  258.             }
  259.             else
  260.                 return $this->render('Frontend/Candidat/view.html.twig',array('candidatures'=>$candidat->getCandidatures(),'mouvementInterne'=>$mouvementInterne,'dossiers'=>$candidat->getDossiers(),"formPwd"=>$formPwd->createView()));
  261.         }
  262.     }
  263.     public function register()
  264.     {
  265.         $form $this->createForm(RegistrationType::class, new Registration());
  266.         return $this->render('Frontend/Candidat/register.html.twig', array('form' => $form->createView()));
  267.     }
  268.     /**
  269.      * @Route("/login-externe", name="frontend_candidat_login", host="%recrutement_subdomain%", methods={"GET"})
  270.      */
  271.     public function login(Request $request)
  272.     {
  273.         $request Request::createFromGlobals();
  274.         $referer $request->headers->get('referer');
  275.         if(trim($referer)!="")
  276.             return $this->redirect($referer);
  277.         else
  278.             return $this->redirect($this->generateUrl('frontend_candidat'));
  279.     }
  280.     /**
  281.      * @Route("/vacation", name="frontend_candidat_vacation", methods={"GET"})
  282.      */
  283.     public function vacation()
  284.     {
  285.         return $this->redirect($this->generateUrl('frontend_vacataire'));
  286.     }
  287.     /**
  288.      * @Route("/postes", name="frontend_postes", host="%recrutement_subdomain%", methods={"GET"})
  289.      * @Route("/candidat-externe/postes", name="frontend_candidat_externe_postes", host="%recrutement_subdomain%", methods={"GET"})
  290.      */
  291.     public function postes()
  292.     {
  293.         $em $this->getDoctrine()->getManager();
  294.         $cats $em->getRepository(RecCategoryPopulation::class)->findBy(['archive'=>false]);
  295.         $postesByCategory = array();
  296.         $catsTypePop = array();
  297.         foreach($cats as $cat)
  298.         {
  299.             //$types = $cat->getTypePopulation();
  300.             $types $em->getRepository(RecTypePopulation::class)->findByCategory($cat->getId());
  301.             foreach($types as $type)
  302.             {
  303.                 if(!isset($catsTypePop[$cat->getId()]))
  304.                 {
  305.                     $catsTypePop[$cat->getId()] = array();
  306.                     $catsTypePop[$cat->getId()]['cat'] = $cat;
  307.                     $catsTypePop[$cat->getId()]['types'] = array();
  308.                 }
  309.                 if(!isset($postesByCategory[$cat->getId()]))
  310.                     $postesByCategory[$cat->getId()]=array();
  311.                 $catsTypePop[$cat->getId()]['types'][]=$type;
  312.                 $p $em->getRepository(RecPoste::class)->getPostesByType($type->getId());
  313.                 $postesByCategory[$cat->getId()][$type->getId()]=$p;
  314.             }
  315.         }
  316.         return $this->render('Frontend/Candidat/postes.html.twig', array('catsTypePop'=>$catsTypePop,'postesByCategory' => $postesByCategory));
  317.     }
  318.     /**
  319.      * @Route("/candidat-interne/postes", name="frontend_candidat_interne_postes", host="%recrutement_subdomain%", methods={"GET"})
  320.      */
  321.     public function postesInterne()
  322.     {
  323.         $em $this->getDoctrine()->getManager();
  324.         $cats $em->getRepository(RecCategoryPopulation::class)->findAll();
  325.         $postesByCategory = array();
  326.         $catsTypePop = array();
  327.         foreach($cats as $cat) {
  328.             $types $cat->getTypePopulation();
  329.             if (!$types->isEmpty()) {
  330.                 $catsTypePop[$cat->getId()] = array();
  331.                 $catsTypePop[$cat->getId()]['cat'] = $cat;
  332.                 $catsTypePop[$cat->getId()]['types'] = $types;
  333.                 foreach ($types as $type) {
  334.                     $p $em->getRepository(RecPoste::class)->getPostesByType($type->getId());
  335.                     if (!isset($postesByCategory[$cat->getId()]))
  336.                         $postesByCategory[$cat->getId()] = array();
  337.                     $postesByCategory[$cat->getId()][$type->getId()] = $p;
  338.                 }
  339.             }
  340.         }
  341.         return $this->render('Frontend/Candidat/postes.html.twig', array('catsTypePop'=>$catsTypePop,'postesByCategory' => $postesByCategory));
  342.     }
  343. /**
  344.  * @Route("/candidat-externe/modpwd", name="frontend_candidature_externe_mod_pwd", host="%recrutement_subdomain%", methods={"POST"})
  345.  */
  346.     public function modifyPwd(EncoderFactoryInterface $encoderFactory)
  347.     {
  348.         $request Request::createFromGlobals();
  349.         $password $request->request->get("password");
  350.         $confirm $request->request->get("confirm");
  351.         $user $this->get('security.token_storage')->getToken()->getUser();
  352.         $em $this->getDoctrine()->getManager();
  353.         $encoder $encoderFactory->getEncoder($user);
  354.         if($password==$confirm)
  355.         {
  356.             $password $encoder->encodePassword($password$user->getSalt());
  357.             $user->setPassword($password);
  358.             $em->persist($user);
  359.             $em->flush();
  360.         }
  361.         $data = array("success"=>1);
  362.         $response = new JsonResponse($data);
  363.         return $response;
  364.     }
  365. /**
  366.  * @Route("/candidat-interne/sendmsg", name="frontend_candidature_interne_send_msg", host="%recrutement_subdomain%", methods={"POST"})
  367.  * @Route("/candidat-externe/sendmsg", name="frontend_candidature_externe_send_msg", host="%recrutement_subdomain%", methods={"POST"})
  368.  */
  369.     public function sendMsg(MailerInterface $mailer)
  370.     {
  371.         $request Request::createFromGlobals();
  372.         $title $request->request->get("title");
  373.         $message $request->request->get("message");
  374.         $output=false;
  375.         $user $this->get('security.token_storage')->getToken()->getUser();
  376.         $mail_noreply $this->container->get('parameter_bag')->get('mail_noreply');
  377.         $mail_admin $this->container->get('parameter_bag')->get('mail_admin');
  378.         $mail_rh_recrutement $this->container->get('parameter_bag')->get('mail_rh_recrutement');
  379.         $mail = (new TemplatedEmail())
  380.             ->from($mail_noreply)
  381.             ->to($mail_rh_recrutement)
  382.             ->cc($mail_admin)
  383.             ->subject("Nouveau commentaire d'un utilisateur pour l'application de recrutement")
  384.             ->htmlTemplate('Courriel/candidat_msg.html.twig')
  385.             ->context(['user' => $user'title'=>$title'message'=>$message]);
  386.         try{
  387.             $mailer->send($mail);
  388.             $error false;
  389.         }catch(TransportExceptionInterface $e) {
  390.             $response $e->getMessage();
  391.             $error true;
  392.         }
  393.         $data = array("success"=>$output);
  394.         $response = new JsonResponse($data);
  395.         return $response;
  396.     }
  397.     /**
  398.      * @Route("/activate-account", name="candidat_sendMailActivateAccount", host="%recrutement_subdomain%", methods={"POST"})
  399.      */
  400.     public function sendMailActivateAccount(MailerInterface $mailer)
  401.     {
  402.         $request Request::createFromGlobals();
  403.         $email $request->request->get('mail');
  404.         $em $this->getDoctrine()->getManager();
  405.         $user $em->getRepository(RecCandidat::class)->findUser($email);
  406.         $site_short_name $this->container->get('parameter_bag')->get('site_short_name');
  407.         if($user)
  408.         {
  409.             $poste $user->getCandidatures()[0]->getPoste()->getIdInterne();
  410.             $mail_noreply $this->container->get('parameter_bag')->get('mail_noreply');
  411.             $signature_rh_recrutement $this->container->get('parameter_bag')->get('signature_rh_recrutement');
  412.             $mail = (new TemplatedEmail())
  413.                 ->from($mail_noreply)
  414.                 ->to($user->getEmail())
  415.                 ->subject('['.$site_short_name.'] Votre creation de compte pour le poste')
  416.                 ->htmlTemplate('Courriel/resend_mail_activate_account.html.twig')
  417.                 ->context(['user' => $user,'serveur'=>$_SERVER['HTTP_HOST'],'poste'=>$poste,'signature_rh_recrutement'=>$signature_rh_recrutement]);
  418.             try{
  419.                 $mailer->send($mail);
  420.                 $error false;
  421.             }catch(TransportExceptionInterface $e) {
  422.                 $response $e->getMessage();
  423.                 $error true;
  424.             }
  425.             $data = array("success"=>1,"message"=>"Un nouveau courriel d'activation vient d'être envoyé Ã  l'adresse : ".$user->getEmail());
  426.             $response = new JsonResponse($data);
  427.             return $response;
  428.         }
  429.         else
  430.         {
  431.             $data = array("success"=>0,"message"=>"L'adresse de messagerie ne correspond Ã  aucun compte.");
  432.             $response = new JsonResponse($data);
  433.             return $response;
  434.         }
  435.     }
  436.     /**
  437.      * @Route("/reset-pwd", name="candidat_resetPwd", host="%recrutement_subdomain%", methods={"POST"})
  438.      */
  439.     public function resetPwd(UserPasswordEncoderInterface $encoderMailerInterface $mailer)
  440.     {
  441.         $request Request::createFromGlobals();
  442.         $email trim($request->request->get('mail'));
  443.         $em $this->getDoctrine()->getManager();
  444.         $user $em->getRepository(RecCandidat::class)->findUser($email);
  445.         $site_short_name $this->container->get('parameter_bag')->get('site_short_name');
  446.         if($user)
  447.         {
  448.             $passmail $this->getPasswordRandom(7);
  449.             $password $encoder->encodePassword($user,$passmail);
  450.             $user->setPassword($password);
  451.             $em->persist($user);
  452.             $em->flush();
  453.             $mail_noreply $this->container->get('parameter_bag')->get('mail_noreply');
  454.             $signature_rh_recrutement $this->container->get('parameter_bag')->get('signature_rh_recrutement');
  455.             $mail = (new TemplatedEmail())
  456.                 ->from($mail_noreply)
  457.                 ->to($user->getEmail())
  458.                 ->subject('['.$site_short_name.'] Mise Ã  jour de votre mot de passe')
  459.                 ->htmlTemplate('Courriel/reset_pwd.html.twig')
  460.                 ->context(['user' => $user,'passmail'=>$passmail,'serveur'=>$_SERVER['HTTP_HOST'],'signature_rh_recrutement'=>$signature_rh_recrutement]);
  461.             try{
  462.                 $mailer->send($mail);
  463.                 $error false;
  464.             }catch(TransportExceptionInterface $e) {
  465.                 $response $e->getMessage();
  466.                 $error true;
  467.             }
  468.             $data = array("success"=>1,"message"=>"Un nouveau mot de passe vient d'être envoyé Ã  l'adresse : ".$user->getEmail(),"password"=>$password);
  469.             return new JsonResponse($data);
  470.         }
  471.         else
  472.         {
  473.             $data = array("success"=>0,"message"=>"L'adresse de messagerie ne correspond Ã  aucun compte.");
  474.             return new JsonResponse($data);
  475.         }
  476.     }
  477.     protected function getPasswordRandom($nb_caractere 12)
  478.     {
  479.         $mot_de_passe "";
  480.         $chaine "abcdefghjkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ023456789";
  481.         $longeur_chaine strlen($chaine);
  482.         for($i 1$i <= $nb_caractere$i++)
  483.         {
  484.             $place_aleatoire mt_rand(0,($longeur_chaine-1));
  485.             $mot_de_passe .= $chaine[$place_aleatoire];
  486.         }
  487.         return $mot_de_passe;
  488.     }
  489.     /**
  490.      * @Route("/candidat-externe/profil", name="frontend_candidat_externe_profil", host="%recrutement_subdomain%", methods={"GET","POST"})
  491.      * @Route("/candidat-interne/profil", name="frontend_candidat_interne_profil", host="%recrutement_subdomain%", methods={"GET","POST"})
  492.      */
  493.     public function profil()
  494.     {
  495.         $user $this->get('security.token_storage')->getToken()->getUser();
  496.         $formProfil $this->createForm(RecCandidatProfilType::class,$user);
  497.         $request Request::createFromGlobals();
  498.         if ($request->getMethod() == 'POST') {
  499.             $formProfil->handleRequest($request);
  500.             if ($formProfil->isValid()) {
  501.                 $em $this->getDoctrine()->getManager();
  502.                 $em->persist($user);
  503.                 $em->flush();
  504.                 return $this->redirect($this->generateUrl('frontend_candidat_externe_view'));
  505.             }
  506.         }
  507.         return $this->render('Frontend/Candidat/profil.html.twig',array("formProfil"=>$formProfil->createView()));
  508.     }
  509.     /**
  510.      * @Route("/candidat-externe/poste/{id}/candidate", name="frontend_candidat_externe_candidate", host="%recrutement_subdomain%", methods={"GET"})
  511.      * @Route("/candidat-interne/poste/{id}/candidate", name="frontend_candidat_interne_candidate", host="%recrutement_subdomain%", methods={"GET"})
  512.      */
  513.     public function candidate($id)
  514.     {
  515.         $user $this->get('security.token_storage')->getToken()->getUser();
  516.         $em $this->getDoctrine()->getManager();
  517.         $candidat $em->getRepository(RecCandidat::class)->loadUserByUsername($user->getEmail());
  518.         if(!$candidat->isCandidat($id))
  519.         {
  520.             $poste $em->getRepository(RecPoste::class)->find($id);
  521.             $candidature = new RecCandidature();
  522.             $candidature->setPoste($poste);
  523.             $candidature->setCandidat($candidat);
  524.             $entity $em->getRepository(RecCandidatureStatut::class);
  525.             $q $entity
  526.                 ->createQueryBuilder('p')
  527.                 ->where('p.id = :id')
  528.                 ->setParameter('id',1)
  529.                 ->getQuery();
  530.             $statut$q->getOneOrNullResult();
  531.             if($statut)
  532.                 $candidature->setCandidatureStatut($statut);
  533.             $candidat->addCandidature($candidature);
  534.             $poste->addCandidature($candidature);
  535.             $em->persist($candidature);
  536.             $em->persist($candidat);
  537.             $em->persist($poste);
  538.             $em->flush();
  539.         }
  540.         
  541.         $candidatures $candidat->getCandidaturesInInit();
  542.         return $this->render('Frontend/Candidature/candidate.html.twig',array('candidatures'=>$candidatures));
  543.     }
  544.     /**
  545.      * @Route("/poste/download_fiche/{id}", name="frontend_download_fiche_poste", host="%recrutement_subdomain%", methods={"GET"})
  546.      */
  547.     public function downloadFiche($id)
  548.     {
  549.         $em $this->getDoctrine()->getManager();
  550.         $document $em->getRepository(RecDocument::class)->find($id);
  551.         if($document && (substr($document->getHiddenName(),0,2)=='F_' || substr($document->getHiddenName(),0,2)=='A_'))
  552.             return $this->file($document->getAbsolutePath().'/'.$document->getHiddenName(), $document->getName(), ResponseHeaderBag::DISPOSITION_INLINE);
  553.         else
  554.             return $this->redirectToRoute('frontend_candidat');
  555.     }
  556.     /**
  557.      * @Route("/candidat-interne", name="frontend_candidat_interne_view", host="%recrutement_subdomain%", methods={"GET"})
  558.      */
  559.     public function Interne(EncoderFactoryInterface $encoderFactory$poste=false)
  560.     {
  561.         $user $this->get('security.token_storage')->getToken()->getUser();
  562.         $em $this->getDoctrine()->getManager();
  563.         $candidat $em->getRepository(RecCandidat::class)->findUser($user->getEmail());
  564.         $mouvementInterne $em->getRepository(RecMouvementInterne::class)->getActive();
  565.         $request Request::createFromGlobals();
  566.         $referer $request->headers->get('referer');
  567.         if (!$candidat) {
  568.             $attributes $user->getAttributes();
  569.             $candidat = new RecCandidat();
  570.             $candidat->setNom(strtoupper($attributes['sn']));
  571.             $candidat->setPrenom($attributes['givenName']);
  572.             $candidat->setEmail($user->getEmail());
  573.             $candidat->setIsActive(true);
  574.             $passmail $this->getPasswordRandom(12);
  575.             $encoder $encoderFactory->getEncoder($candidat);
  576.             $password $encoder->encodePassword($passmail,$candidat->getSalt());
  577.             $candidat->setPassword($password);
  578.             $candidat->setDateNaissance(new \DateTime("now"));
  579.             $candidat->setLieuNaissance("-");
  580.             $em->persist($candidat);
  581.             $em->flush();
  582.         }
  583.         $pos strpos($referer'/poste/');
  584.         $mouvementInterne $em->getRepository(RecMouvementInterne::class)->getActive();
  585.         if ($pos) {
  586.             $pos += 7;
  587.             $id_poste substr($referer$posstrlen($referer) - $pos);
  588.             $entity $em->getRepository(RecCandidature::class);
  589.             $q $entity
  590.                 ->createQueryBuilder('c')
  591.                 ->leftJoin('c.poste''p')
  592.                 ->leftJoin('c.candidat''u')
  593.                 ->where('p.idInterne = :idInterne')
  594.                 ->andWhere('u.id = :user')
  595.                 ->setParameter('idInterne'$id_poste)
  596.                 ->setParameter('user'$candidat->getId())
  597.                 ->getQuery();
  598.             $candidature $q->getOneOrNullResult();
  599.             if (!$candidature) {
  600.                 $entity $em->getRepository(RecPoste::class);
  601.                 $q $entity
  602.                     ->createQueryBuilder('p')
  603.                     ->where('p.idInterne = :idInterne')
  604.                     ->setParameter('idInterne'$id_poste)
  605.                     ->getQuery();
  606.                 $poste_cand $q->getOneOrNullResult();
  607.                 if ($poste_cand) {
  608.                     $candidature = new RecCandidature();
  609.                     $candidature->setPoste($poste_cand);
  610.                     $candidature->setCandidat($candidat);
  611.                     $entity $em->getRepository(RecCandidatureStatut::class);
  612.                     $q $entity
  613.                         ->createQueryBuilder('p')
  614.                         ->where('p.id = :id')
  615.                         ->setParameter('id'1)
  616.                         ->getQuery();
  617.                     $statut $q->getOneOrNullResult();
  618.                     if ($statut)
  619.                         $candidature->setCandidatureStatut($statut);
  620.                     $candidat->addCandidature($candidature);
  621.                     $poste_cand->addCandidature($candidature);
  622.                     $em->persist($candidature);
  623.                     $em->persist($candidat);
  624.                     $em->persist($poste_cand);
  625.                     $em->flush();
  626.                     $candidatures $candidat->getCandidaturesInInit();
  627.                     return $this->render('Frontend/Candidature/candidate.html.twig', array('candidatures' => $candidatures));
  628.                 } else
  629.                     return $this->render('Frontend/Candidat/view.html.twig', array('candidatures' => $candidat->getCandidatures(), 'mouvementInterne' => $mouvementInterne'dossiers' => $candidat->getDossiers()));
  630.             } else {
  631.                 $candidatures $candidat->getCandidaturesInInit();
  632.                 if ($candidatures) {
  633.                     return $this->render('Frontend/Candidature/candidate.html.twig', array('candidatures' => $candidatures));
  634.                 } else
  635.                     return $this->render('Frontend/Candidat/view.html.twig', array('candidatures' => $candidat->getCandidatures(), 'mouvementInterne' => $mouvementInterne'dossiers' => $candidat->getDossiers()));
  636.             }
  637.         }
  638.     else
  639.         return $this->render('Frontend/Candidat/view.html.twig', array('candidatures' => $candidat->getCandidatures(), 'mouvementInterne' => $mouvementInterne'dossiers' => $candidat->getDossiers()));
  640.     }
  641. }