<?php
namespace App\Controller\Frontend;
use App\Entity\RecCandidat;
use App\Entity\RecCandidature;
use App\Entity\RecCandidatureStatut;
use App\Entity\RecCategoryPopulation;
use App\Entity\RecDocument;
use App\Entity\RecMouvementInterne;
use App\Entity\RecParameters;
use App\Entity\RecPoste;
use App\Entity\RecTypePopulation;
use App\Form\RecCandidatType;
use App\Form\RecCandidatProfilType;
use App\Form\RecCandidatPwdType;
use App\Form\Model\Registration;
use App\Form\Type\RegistrationType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Doctrine\Common\Collections\ArrayCollection;
class CandidatController extends AbstractController
{
/**
* @Route("/", name="frontend_candidat", host="%recrutement_subdomain%", methods={"GET","POST"})
* @Route("/poste/{poste}", name="frontend_candidat_poste", host="%recrutement_subdomain%", methods={"GET","POST"})
*/
public function index(AuthenticationUtils $authenticationUtils,EncoderFactoryInterface $encoderFactory, MailerInterface $mailer, $poste=false)
{
$em = $this->getDoctrine()->getManager();
$poste_title = "";
$poste_description = "";
$poste_fiche = false;
$poste_annexe = false;
$is_spontane= false;
$private=false;
$type="";
$message="";
$cats = $em->getRepository(RecCategoryPopulation::class)->findBy(['archive'=>false]);
$parameters = $em->getRepository(RecParameters::class)->find(1);
$postesByCategory = array();
foreach($cats as $cat)
{
$p = $em->getRepository(RecPoste::class)->getPostes($cat->getId());
$postesByCategory[$cat->getId()]=$p;
}
if($poste)
{
$entity = $em->getRepository(RecPoste::class);
$q = $entity
->createQueryBuilder('p')
->where('p.idInterne = :idInterne')
->setParameter('idInterne', $poste)
->getQuery();
$poste_cand = $q->getOneOrNullResult();
if(!$poste_cand)
return $this->redirect($this->generateUrl('frontend_candidat'));
else
{
$now = new \DateTime('now');
if(($now>=$poste_cand->getOpenDate() && $now<=$poste_cand->getCloseDate()) || $poste_cand->getIsSpontane()==true)
{
$poste_title = $poste_cand->getTitle();
$poste_description = $poste_cand->getDescription();
$poste_fiche = $poste_cand->getFiche();
$poste_annexe = $poste_cand->getAnnexe();
$is_spontane = $poste_cand->getIsSpontane();
$private = $poste_cand->getTypePopulation()->getPrivate();
}
else
return $this->redirect($this->generateUrl('frontend_candidat'));
}
}
// Gestion du login
$request = Request::createFromGlobals();
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
$form = $this->createForm(RecCandidatType::class,new RecCandidat());
if ($request->getMethod() == 'POST') {
$form->handleRequest($request);
if ($form->isValid() && $poste) {
$user = $form->getData();
$em = $this->getDoctrine()->getManager();
$user_exist = $em->getRepository(RecCandidat::class)->findUser($user->getEmail());
if(!$user_exist)
{
$encoder = $encoderFactory->getEncoder($user);
$passmail = $user->getPassword();
$password = $encoder->encodePassword($user->getPassword(), $user->getSalt());
$user->setPassword($password);
$user->setNom(strtoupper($user->getNom()));
$user->setPrenom(ucfirst(strtolower($user->getPrenom())));
$user->setAdresse(ucwords(strtolower($user->getAdresse())));
$user->setVille(ucwords(strtolower($user->getVille())));
$user->setPays(ucwords(strtolower($user->getPays())));
$entity = $em->getRepository(RecPoste::class);
$q = $entity
->createQueryBuilder('p')
->where('p.idInterne = :idInterne')
->setParameter('idInterne', trim($poste))
->getQuery();
$poste_cand = $q->getSingleResult();
$candidature = new RecCandidature();
$candidature->setPoste($poste_cand);
$candidature->setCandidat($user);
$entity = $em->getRepository(RecCandidatureStatut::class);
$q = $entity
->createQueryBuilder('p')
->where('p.id = :id')
->setParameter('id',1)
->getQuery();
$statut= $q->getOneOrNullResult();
if($statut)
$candidature->setCandidatureStatut($statut);
$user->addCandidature($candidature);
$poste_cand->addCandidature($candidature);
$em->persist($candidature);
$em->persist($user);
$em->persist($poste_cand);
$em->flush();
$mail_noreply = $this->container->get('parameter_bag')->get('mail_noreply');
$site_short_name = $this->container->get('parameter_bag')->get('site_short_name');
$signature_rh_recrutement = $poste_cand->getTypePopulation()->getSignatureMail();
if(trim($signature_rh_recrutement)=='')
$signature_rh_recrutement = $this->container->get('parameter_bag')->get('signature_rh_recrutement');
$mail = (new TemplatedEmail())
->from($mail_noreply)
->to($user->getEmail())
->subject('['.$site_short_name.'] Votre création de compte pour le poste')
->htmlTemplate('Courriel/create.html.twig')
->context(['user' => $user,'serveur'=>$_SERVER['HTTP_HOST'],'poste'=>$poste,'signature_rh_recrutement'=>$signature_rh_recrutement]);
try{
$mailer->send($mail);
$error = false;
}catch(TransportExceptionInterface $e) {
$response = $e->getMessage();
$error = true;
}
return $this->render('Frontend/Candidat/index.html.twig', array('form' => $form->createView(),'last_username' => $lastUsername,
'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));
}
else
return $this->render('Frontend/Candidat/index.html.twig', array('form' => $form->createView(),'last_username' => $lastUsername,
'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));
}
if(!$form->isValid())
{
$post = $request->request->get('rec_candidat');
$password = $post['password']['password'];
$confirmation = $post['password']['confirmation'];
if($password!=$confirmation)
{
$message = "Le mots de passe et la confirmation doivent correspondre";
$type="danger";
}
else if(strlen($password)<7)
{
$message = "Mot de passe inférieur à 7 caractères";
$type="danger";
}
}
}
return $this->render('Frontend/Candidat/index.html.twig', array('form' => $form->createView(),'last_username' => $lastUsername,
'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));
}
/**
* @Route("/candidat-externe", name="frontend_candidat_externe_view", host="%recrutement_subdomain%", methods={"GET"})
* @Route("/candidat-interne", name="frontend_candidat_interne_view", host="%recrutement_subdomain%", methods={"GET"})
*/
public function view()
{
$request = Request::createFromGlobals();
$referer = $request->headers->get('referer');
$em = $this->getDoctrine()->getManager();
$pos = strpos($referer,'/poste/');
$user = $this->get('security.token_storage')->getToken()->getUser();
$candidat = $em->getRepository(RecCandidat::class)->loadUserByUsername($user->getEmail());
$mouvementInterne = $em->getRepository(RecMouvementInterne::class)->getActive();
$formPwd = $this->createForm(RecCandidatPwdType::class);
if($pos)
{
$pos+=7;
$id_poste=substr($referer,$pos,strlen($referer)-$pos);
$entity = $em->getRepository(RecCandidature::class);
$q = $entity
->createQueryBuilder('c')
->leftJoin('c.poste','p')
->leftJoin('c.candidat','u')
->where('p.idInterne = :idInterne')
->andWhere('u.id = :user')
->setParameter('idInterne', $id_poste)
->setParameter('user', $candidat->getId())
->getQuery();
$candidature = $q->getOneOrNullResult();
if(!$candidature)
{
$entity = $em->getRepository(RecPoste::class);
$q = $entity
->createQueryBuilder('p')
->where('p.idInterne = :idInterne')
->setParameter('idInterne', $id_poste)
->getQuery();
$poste_cand = $q->getOneOrNullResult();
if($poste_cand)
{
$candidature = new RecCandidature();
$candidature->setPoste($poste_cand);
$candidature->setCandidat($user);
$entity = $em->getRepository(RecCandidatureStatut::class);
$q = $entity
->createQueryBuilder('p')
->where('p.id = :id')
->setParameter('id',1)
->getQuery();
$statut= $q->getOneOrNullResult();
if($statut)
$candidature->setCandidatureStatut($statut);
$user->addCandidature($candidature);
$poste_cand->addCandidature($candidature);
$em->persist($candidature);
$em->persist($user);
$em->persist($poste_cand);
$em->flush();
$candidatures = $user->getCandidaturesInInit();
return $this->render('Frontend/Candidature/candidate.html.twig',array('candidatures'=>$candidatures));
}
else
return $this->render('Frontend/Candidat/view.html.twig',array('candidatures'=>$candidat->getCandidatures(),'mouvementInterne'=>$mouvementInterne,'dossiers'=>$candidat->getDossiers(),"formPwd"=>$formPwd->createView()));
}
else
{
$candidatures = $candidat->getCandidaturesInInit();
if($candidatures)
{
return $this->render('Frontend/Candidature/candidate.html.twig',array('candidatures'=>$candidatures));
}
else
return $this->render('Frontend/Candidat/view.html.twig',array('candidatures'=>$candidat->getCandidatures(),'mouvementInterne'=>$mouvementInterne,'dossiers'=>$candidat->getDossiers(),"formPwd"=>$formPwd->createView()));
}
}
else
{
$candidatures = $candidat->getCandidaturesInInit();
if($candidatures)
{
return $this->render('Frontend/Candidature/candidate.html.twig',array('candidatures'=>$candidatures));
}
else
return $this->render('Frontend/Candidat/view.html.twig',array('candidatures'=>$candidat->getCandidatures(),'mouvementInterne'=>$mouvementInterne,'dossiers'=>$candidat->getDossiers(),"formPwd"=>$formPwd->createView()));
}
}
public function register()
{
$form = $this->createForm(RegistrationType::class, new Registration());
return $this->render('Frontend/Candidat/register.html.twig', array('form' => $form->createView()));
}
/**
* @Route("/login-externe", name="frontend_candidat_login", host="%recrutement_subdomain%", methods={"GET"})
*/
public function login(Request $request)
{
$request = Request::createFromGlobals();
$referer = $request->headers->get('referer');
if(trim($referer)!="")
return $this->redirect($referer);
else
return $this->redirect($this->generateUrl('frontend_candidat'));
}
/**
* @Route("/vacation", name="frontend_candidat_vacation", methods={"GET"})
*/
public function vacation()
{
return $this->redirect($this->generateUrl('frontend_vacataire'));
}
/**
* @Route("/postes", name="frontend_postes", host="%recrutement_subdomain%", methods={"GET"})
* @Route("/candidat-externe/postes", name="frontend_candidat_externe_postes", host="%recrutement_subdomain%", methods={"GET"})
*/
public function postes()
{
$em = $this->getDoctrine()->getManager();
$cats = $em->getRepository(RecCategoryPopulation::class)->findBy(['archive'=>false]);
$postesByCategory = array();
$catsTypePop = array();
foreach($cats as $cat)
{
//$types = $cat->getTypePopulation();
$types = $em->getRepository(RecTypePopulation::class)->findByCategory($cat->getId());
foreach($types as $type)
{
if(!isset($catsTypePop[$cat->getId()]))
{
$catsTypePop[$cat->getId()] = array();
$catsTypePop[$cat->getId()]['cat'] = $cat;
$catsTypePop[$cat->getId()]['types'] = array();
}
if(!isset($postesByCategory[$cat->getId()]))
$postesByCategory[$cat->getId()]=array();
$catsTypePop[$cat->getId()]['types'][]=$type;
$p = $em->getRepository(RecPoste::class)->getPostesByType($type->getId());
$postesByCategory[$cat->getId()][$type->getId()]=$p;
}
}
return $this->render('Frontend/Candidat/postes.html.twig', array('catsTypePop'=>$catsTypePop,'postesByCategory' => $postesByCategory));
}
/**
* @Route("/candidat-interne/postes", name="frontend_candidat_interne_postes", host="%recrutement_subdomain%", methods={"GET"})
*/
public function postesInterne()
{
$em = $this->getDoctrine()->getManager();
$cats = $em->getRepository(RecCategoryPopulation::class)->findAll();
$postesByCategory = array();
$catsTypePop = array();
foreach($cats as $cat) {
$types = $cat->getTypePopulation();
if (!$types->isEmpty()) {
$catsTypePop[$cat->getId()] = array();
$catsTypePop[$cat->getId()]['cat'] = $cat;
$catsTypePop[$cat->getId()]['types'] = $types;
foreach ($types as $type) {
$p = $em->getRepository(RecPoste::class)->getPostesByType($type->getId());
if (!isset($postesByCategory[$cat->getId()]))
$postesByCategory[$cat->getId()] = array();
$postesByCategory[$cat->getId()][$type->getId()] = $p;
}
}
}
return $this->render('Frontend/Candidat/postes.html.twig', array('catsTypePop'=>$catsTypePop,'postesByCategory' => $postesByCategory));
}
/**
* @Route("/candidat-externe/modpwd", name="frontend_candidature_externe_mod_pwd", host="%recrutement_subdomain%", methods={"POST"})
*/
public function modifyPwd(EncoderFactoryInterface $encoderFactory)
{
$request = Request::createFromGlobals();
$password = $request->request->get("password");
$confirm = $request->request->get("confirm");
$user = $this->get('security.token_storage')->getToken()->getUser();
$em = $this->getDoctrine()->getManager();
$encoder = $encoderFactory->getEncoder($user);
if($password==$confirm)
{
$password = $encoder->encodePassword($password, $user->getSalt());
$user->setPassword($password);
$em->persist($user);
$em->flush();
}
$data = array("success"=>1);
$response = new JsonResponse($data);
return $response;
}
/**
* @Route("/candidat-interne/sendmsg", name="frontend_candidature_interne_send_msg", host="%recrutement_subdomain%", methods={"POST"})
* @Route("/candidat-externe/sendmsg", name="frontend_candidature_externe_send_msg", host="%recrutement_subdomain%", methods={"POST"})
*/
public function sendMsg(MailerInterface $mailer)
{
$request = Request::createFromGlobals();
$title = $request->request->get("title");
$message = $request->request->get("message");
$output=false;
$user = $this->get('security.token_storage')->getToken()->getUser();
$mail_noreply = $this->container->get('parameter_bag')->get('mail_noreply');
$mail_admin = $this->container->get('parameter_bag')->get('mail_admin');
$mail_rh_recrutement = $this->container->get('parameter_bag')->get('mail_rh_recrutement');
$mail = (new TemplatedEmail())
->from($mail_noreply)
->to($mail_rh_recrutement)
->cc($mail_admin)
->subject("Nouveau commentaire d'un utilisateur pour l'application de recrutement")
->htmlTemplate('Courriel/candidat_msg.html.twig')
->context(['user' => $user, 'title'=>$title, 'message'=>$message]);
try{
$mailer->send($mail);
$error = false;
}catch(TransportExceptionInterface $e) {
$response = $e->getMessage();
$error = true;
}
$data = array("success"=>$output);
$response = new JsonResponse($data);
return $response;
}
/**
* @Route("/activate-account", name="candidat_sendMailActivateAccount", host="%recrutement_subdomain%", methods={"POST"})
*/
public function sendMailActivateAccount(MailerInterface $mailer)
{
$request = Request::createFromGlobals();
$email = $request->request->get('mail');
$em = $this->getDoctrine()->getManager();
$user = $em->getRepository(RecCandidat::class)->findUser($email);
$site_short_name = $this->container->get('parameter_bag')->get('site_short_name');
if($user)
{
$poste = $user->getCandidatures()[0]->getPoste()->getIdInterne();
$mail_noreply = $this->container->get('parameter_bag')->get('mail_noreply');
$signature_rh_recrutement = $this->container->get('parameter_bag')->get('signature_rh_recrutement');
$mail = (new TemplatedEmail())
->from($mail_noreply)
->to($user->getEmail())
->subject('['.$site_short_name.'] Votre creation de compte pour le poste')
->htmlTemplate('Courriel/resend_mail_activate_account.html.twig')
->context(['user' => $user,'serveur'=>$_SERVER['HTTP_HOST'],'poste'=>$poste,'signature_rh_recrutement'=>$signature_rh_recrutement]);
try{
$mailer->send($mail);
$error = false;
}catch(TransportExceptionInterface $e) {
$response = $e->getMessage();
$error = true;
}
$data = array("success"=>1,"message"=>"Un nouveau courriel d'activation vient d'être envoyé à l'adresse : ".$user->getEmail());
$response = new JsonResponse($data);
return $response;
}
else
{
$data = array("success"=>0,"message"=>"L'adresse de messagerie ne correspond à aucun compte.");
$response = new JsonResponse($data);
return $response;
}
}
/**
* @Route("/reset-pwd", name="candidat_resetPwd", host="%recrutement_subdomain%", methods={"POST"})
*/
public function resetPwd(UserPasswordEncoderInterface $encoder, MailerInterface $mailer)
{
$request = Request::createFromGlobals();
$email = trim($request->request->get('mail'));
$em = $this->getDoctrine()->getManager();
$user = $em->getRepository(RecCandidat::class)->findUser($email);
$site_short_name = $this->container->get('parameter_bag')->get('site_short_name');
if($user)
{
$passmail = $this->getPasswordRandom(7);
$password = $encoder->encodePassword($user,$passmail);
$user->setPassword($password);
$em->persist($user);
$em->flush();
$mail_noreply = $this->container->get('parameter_bag')->get('mail_noreply');
$signature_rh_recrutement = $this->container->get('parameter_bag')->get('signature_rh_recrutement');
$mail = (new TemplatedEmail())
->from($mail_noreply)
->to($user->getEmail())
->subject('['.$site_short_name.'] Mise à jour de votre mot de passe')
->htmlTemplate('Courriel/reset_pwd.html.twig')
->context(['user' => $user,'passmail'=>$passmail,'serveur'=>$_SERVER['HTTP_HOST'],'signature_rh_recrutement'=>$signature_rh_recrutement]);
try{
$mailer->send($mail);
$error = false;
}catch(TransportExceptionInterface $e) {
$response = $e->getMessage();
$error = true;
}
$data = array("success"=>1,"message"=>"Un nouveau mot de passe vient d'être envoyé à l'adresse : ".$user->getEmail(),"password"=>$password);
return new JsonResponse($data);
}
else
{
$data = array("success"=>0,"message"=>"L'adresse de messagerie ne correspond à aucun compte.");
return new JsonResponse($data);
}
}
protected function getPasswordRandom($nb_caractere = 12)
{
$mot_de_passe = "";
$chaine = "abcdefghjkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ023456789";
$longeur_chaine = strlen($chaine);
for($i = 1; $i <= $nb_caractere; $i++)
{
$place_aleatoire = mt_rand(0,($longeur_chaine-1));
$mot_de_passe .= $chaine[$place_aleatoire];
}
return $mot_de_passe;
}
/**
* @Route("/candidat-externe/profil", name="frontend_candidat_externe_profil", host="%recrutement_subdomain%", methods={"GET","POST"})
* @Route("/candidat-interne/profil", name="frontend_candidat_interne_profil", host="%recrutement_subdomain%", methods={"GET","POST"})
*/
public function profil()
{
$user = $this->get('security.token_storage')->getToken()->getUser();
$formProfil = $this->createForm(RecCandidatProfilType::class,$user);
$request = Request::createFromGlobals();
if ($request->getMethod() == 'POST') {
$formProfil->handleRequest($request);
if ($formProfil->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($user);
$em->flush();
return $this->redirect($this->generateUrl('frontend_candidat_externe_view'));
}
}
return $this->render('Frontend/Candidat/profil.html.twig',array("formProfil"=>$formProfil->createView()));
}
/**
* @Route("/candidat-externe/poste/{id}/candidate", name="frontend_candidat_externe_candidate", host="%recrutement_subdomain%", methods={"GET"})
* @Route("/candidat-interne/poste/{id}/candidate", name="frontend_candidat_interne_candidate", host="%recrutement_subdomain%", methods={"GET"})
*/
public function candidate($id)
{
$user = $this->get('security.token_storage')->getToken()->getUser();
$em = $this->getDoctrine()->getManager();
$candidat = $em->getRepository(RecCandidat::class)->loadUserByUsername($user->getEmail());
if(!$candidat->isCandidat($id))
{
$poste = $em->getRepository(RecPoste::class)->find($id);
$candidature = new RecCandidature();
$candidature->setPoste($poste);
$candidature->setCandidat($candidat);
$entity = $em->getRepository(RecCandidatureStatut::class);
$q = $entity
->createQueryBuilder('p')
->where('p.id = :id')
->setParameter('id',1)
->getQuery();
$statut= $q->getOneOrNullResult();
if($statut)
$candidature->setCandidatureStatut($statut);
$candidat->addCandidature($candidature);
$poste->addCandidature($candidature);
$em->persist($candidature);
$em->persist($candidat);
$em->persist($poste);
$em->flush();
}
$candidatures = $candidat->getCandidaturesInInit();
return $this->render('Frontend/Candidature/candidate.html.twig',array('candidatures'=>$candidatures));
}
/**
* @Route("/poste/download_fiche/{id}", name="frontend_download_fiche_poste", host="%recrutement_subdomain%", methods={"GET"})
*/
public function downloadFiche($id)
{
$em = $this->getDoctrine()->getManager();
$document = $em->getRepository(RecDocument::class)->find($id);
if($document && (substr($document->getHiddenName(),0,2)=='F_' || substr($document->getHiddenName(),0,2)=='A_'))
return $this->file($document->getAbsolutePath().'/'.$document->getHiddenName(), $document->getName(), ResponseHeaderBag::DISPOSITION_INLINE);
else
return $this->redirectToRoute('frontend_candidat');
}
/**
* @Route("/candidat-interne", name="frontend_candidat_interne_view", host="%recrutement_subdomain%", methods={"GET"})
*/
public function Interne(EncoderFactoryInterface $encoderFactory, $poste=false)
{
$user = $this->get('security.token_storage')->getToken()->getUser();
$em = $this->getDoctrine()->getManager();
$candidat = $em->getRepository(RecCandidat::class)->findUser($user->getEmail());
$mouvementInterne = $em->getRepository(RecMouvementInterne::class)->getActive();
$request = Request::createFromGlobals();
$referer = $request->headers->get('referer');
if (!$candidat) {
$attributes = $user->getAttributes();
$candidat = new RecCandidat();
$candidat->setNom(strtoupper($attributes['sn']));
$candidat->setPrenom($attributes['givenName']);
$candidat->setEmail($user->getEmail());
$candidat->setIsActive(true);
$passmail = $this->getPasswordRandom(12);
$encoder = $encoderFactory->getEncoder($candidat);
$password = $encoder->encodePassword($passmail,$candidat->getSalt());
$candidat->setPassword($password);
$candidat->setDateNaissance(new \DateTime("now"));
$candidat->setLieuNaissance("-");
$em->persist($candidat);
$em->flush();
}
$pos = strpos($referer, '/poste/');
$mouvementInterne = $em->getRepository(RecMouvementInterne::class)->getActive();
if ($pos) {
$pos += 7;
$id_poste = substr($referer, $pos, strlen($referer) - $pos);
$entity = $em->getRepository(RecCandidature::class);
$q = $entity
->createQueryBuilder('c')
->leftJoin('c.poste', 'p')
->leftJoin('c.candidat', 'u')
->where('p.idInterne = :idInterne')
->andWhere('u.id = :user')
->setParameter('idInterne', $id_poste)
->setParameter('user', $candidat->getId())
->getQuery();
$candidature = $q->getOneOrNullResult();
if (!$candidature) {
$entity = $em->getRepository(RecPoste::class);
$q = $entity
->createQueryBuilder('p')
->where('p.idInterne = :idInterne')
->setParameter('idInterne', $id_poste)
->getQuery();
$poste_cand = $q->getOneOrNullResult();
if ($poste_cand) {
$candidature = new RecCandidature();
$candidature->setPoste($poste_cand);
$candidature->setCandidat($candidat);
$entity = $em->getRepository(RecCandidatureStatut::class);
$q = $entity
->createQueryBuilder('p')
->where('p.id = :id')
->setParameter('id', 1)
->getQuery();
$statut = $q->getOneOrNullResult();
if ($statut)
$candidature->setCandidatureStatut($statut);
$candidat->addCandidature($candidature);
$poste_cand->addCandidature($candidature);
$em->persist($candidature);
$em->persist($candidat);
$em->persist($poste_cand);
$em->flush();
$candidatures = $candidat->getCandidaturesInInit();
return $this->render('Frontend/Candidature/candidate.html.twig', array('candidatures' => $candidatures));
} else
return $this->render('Frontend/Candidat/view.html.twig', array('candidatures' => $candidat->getCandidatures(), 'mouvementInterne' => $mouvementInterne, 'dossiers' => $candidat->getDossiers()));
} else {
$candidatures = $candidat->getCandidaturesInInit();
if ($candidatures) {
return $this->render('Frontend/Candidature/candidate.html.twig', array('candidatures' => $candidatures));
} else
return $this->render('Frontend/Candidat/view.html.twig', array('candidatures' => $candidat->getCandidatures(), 'mouvementInterne' => $mouvementInterne, 'dossiers' => $candidat->getDossiers()));
}
}
else
return $this->render('Frontend/Candidat/view.html.twig', array('candidatures' => $candidat->getCandidatures(), 'mouvementInterne' => $mouvementInterne, 'dossiers' => $candidat->getDossiers()));
}
}