src/Controller/Frontend/VacataireController.php line 85

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: dardennj
  5.  * Date: 30/05/18
  6.  * Time: 16:28
  7.  */
  8. namespace App\Controller\Frontend;
  9. use App\Entity\RecCandidat;
  10. use App\Entity\RecContratVacataire;
  11. use App\Entity\RecDocumentVacataire;
  12. use App\Entity\RecDossierVacataire;
  13. use App\Entity\RecEtatLiquidationVacataire;
  14. use App\Entity\RecEtatLiquidationDocVacataire;
  15. use App\Entity\RecLogDossierVacataire;
  16. use App\Entity\RecParameters;
  17. use App\Entity\RecServiceComposanteVacation;
  18. use App\Entity\RecTypeDocumentVacataire;
  19. use App\Entity\RecTypeVacataire;
  20. use App\Entity\RecVacation;
  21. use App\Entity\RecVacationEtatDossier;
  22. use App\Entity\RecVacationStatut;
  23. use App\Entity\RecVacationStatutContrat;
  24. use App\Entity\RecVacationStatutAC;
  25. use App\Entity\RecVacationStatutCP;
  26. use App\Entity\RecVacationStatutEtatLiquidation;
  27. use App\Form\RecCandidatType;
  28. use App\Form\RecCandidatProfilType;
  29. use App\Form\RecCandidatPwdType;
  30. use App\Form\RecDocumentType;
  31. use App\Form\Model\Registration;
  32. use App\Form\Type\RegistrationType;
  33. use Symfony\Component\HttpFoundation\JsonResponse;
  34. use Symfony\Component\HttpFoundation\Response;
  35. use APY\DataGridBundle\Grid\Source\Entity;
  36. use APY\DataGridBundle\Grid\Action\RowAction;
  37. use APY\DataGridBundle\Grid\Column\ActionsColumn;
  38. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  39. use Symfony\Component\Routing\Annotation\Route;
  40. use Symfony\Component\Mailer\MailerInterface;
  41. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  42. use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
  43. use Symfony\Component\HttpFoundation\Request;
  44. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  45. use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
  46. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  47. use Symfony\Component\Security\Core\Security;
  48. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  49. class VacataireController extends AbstractController
  50. {
  51.     /**
  52.      * @Route("/login", name="frontend_vacataire_login", host="%vacataire_subdomain%", methods={"GET"})
  53.      */
  54.     public function login()
  55.     {
  56.         return $this->redirect($this->generateUrl('frontend_vacataire'));
  57.     }
  58.     /**
  59.      * @Route("/", name="frontend_vacataire", host="%vacataire_subdomain%", methods={"GET","POST"})
  60.      */
  61.     public function index(AuthenticationUtils $authenticationUtilsEncoderFactoryInterface $encoderFactoryMailerInterface $mailer)
  62.     {
  63.         $type="";
  64.         $message="";
  65.         // Gestion du login
  66.         $request Request::createFromGlobals();
  67.         // get the login error if there is one
  68.         $error $authenticationUtils->getLastAuthenticationError();
  69.         // last username entered by the user
  70.         $lastUsername $authenticationUtils->getLastUsername();
  71.         $form $this->createForm(RecCandidatType::class);
  72.         $em $this->getDoctrine()->getManager();
  73.         $parameters $em->getRepository(RecParameters::class)->find(1);
  74.         if ($request->getMethod() == 'POST') {
  75.             $form->handleRequest($request);
  76.             if ($form->isValid()) {
  77.                 $user $form->getData();
  78.                 $user_exist $em->getRepository(RecCandidat::class)->findUser($user->getEmail());
  79.                 if(!$user_exist)
  80.                 {
  81.                     $passmail $user->getPassword();
  82.                     $encoder $encoderFactory->getEncoder($user);
  83.                     $password $encoder->encodePassword($user->getPassword(), $user->getSalt());
  84.                     $user->setPassword($password);
  85.                     $user->setNom(strtoupper($user->getNom()));
  86.                     $user->setPrenom(ucfirst(strtolower($user->getPrenom())));
  87.                     $user->setAdresse(ucwords(strtolower($user->getAdresse())));
  88.                     $user->setVille(ucwords(strtolower($user->getVille())));
  89.                     $user->setPays(ucwords(strtolower($user->getPays())));
  90.                     $em->persist($user);
  91.                     $em->flush();
  92.                     $mail_noreply $this->container->get('parameter_bag')->get('mail_noreply');
  93.                     $site_short_name $this->container->get('parameter_bag')->get('site_short_name');
  94.                     $mail = (new TemplatedEmail())
  95.                         ->from($mail_noreply)
  96.                         ->to($user->getEmail())
  97.                         ->subject('['.$site_short_name.'] Votre création de compte pour le dépôt de votre dossier de vacataire')
  98.                         ->htmlTemplate('Courriel/create_vacation.html.twig')
  99.                         ->context(['user' => $user,'passmail'=>$passmail,'serveur'=>$_SERVER['HTTP_HOST']]);
  100.                     try{
  101.                         $mailer->send($mail);
  102.                         $error false;
  103.                     }catch(TransportExceptionInterface $e) {
  104.                         $response $e->getMessage();
  105.                         $error true;
  106.                     }
  107.                     return $this->render('Frontend/Candidat/vacation.html.twig', array('form' => $form->createView(),'last_username' => $lastUsername,
  108.                         'error' => $error,'poste'=> false,'message'=>"Un courriel vient d'être envoyé à l'adresse : ".$user->getEmail()." afin de valider votre compte.","message_type"=>"success","parameters"=>$parameters));
  109.                 }
  110.                 else
  111.                     return $this->render('Frontend/Candidat/vacation.html.twig', array('form' => $form->createView(),'last_username' => $lastUsername,
  112.                         'error' => $error,'message'=>"Vous disposez déjà d'un compte à cette adresse !","message_type"=>"danger","parameters"=>$parameters));
  113.             }
  114.             else
  115.             {
  116.                 $post $request->request->get('rec_candidat');
  117.                 $password $post['password']['password'];
  118.                 $confirmation =  $post['password']['confirmation'];
  119.                 if($password!=$confirmation)
  120.                 {
  121.                     $message "Le mots de passe et la confirmation doivent correspondre";
  122.                     $type="danger";
  123.                 }
  124.                 else if(strlen($password)<7)
  125.                 {
  126.                     $message "Mot de passe inférieur à 7 caractères";
  127.                     $type="danger";
  128.                 }
  129.             }
  130.         }
  131.         return $this->render('Frontend/Candidat/vacation.html.twig', array('form' => $form->createView(),'last_username' => $lastUsername'error' => $error,'message'=>$message,"message_type"=>$type,"parameters"=>$parameters));
  132.     }
  133.     /**
  134.      * @Route("/activate/{id}", name="frontend_vacataire_activate", host="%vacataire_subdomain%", methods={"GET"})
  135.      */
  136.     public function activate(AuthenticationUtils $authenticationUtils$id)
  137.     {
  138.         $em $this->getDoctrine()->getManager();
  139.         $parameters $em->getRepository(RecParameters::class)->find(1);
  140.         $request Request::createFromGlobals();
  141.         $error false;
  142.         $lastUsername=false;
  143.         // get the login error if there is one
  144.         $error $authenticationUtils->getLastAuthenticationError();
  145.         // last username entered by the user
  146.         $lastUsername $authenticationUtils->getLastUsername();
  147.         $form $this->createForm(RecCandidatType::class);
  148.         $entity $em->getRepository(RecCandidat::class);
  149.         $q $entity
  150.             ->createQueryBuilder('u')
  151.             ->where('u.saltEmail = :salt')
  152.             ->setParameter('salt'$id)
  153.             ->getQuery();
  154.         $user $q->getSingleResult();
  155.         if($user)
  156.         {
  157.             $user->setIsActive(true);
  158.             $em->persist($user);
  159.             $em->flush();
  160.         }
  161.         return $this->render('Frontend/Candidat/vacation.html.twig', array('form' => $form->createView(),'last_username' => $lastUsername'error' => $error,'poste'=> false,'message'=>"Votre compte a été validé. Vous pouvez maintenant accéder à votre espace personnel en vous identifiant ci-dessous.","message_type"=>"success","parameters"=>$parameters));
  162.     }
  163.     /**
  164.      * @Route("/vacataire/profil", name="frontend_vacataire_profil", host="%vacataire_subdomain%", methods={"GET","POST"})
  165.      */
  166.     public function profil()
  167.     {
  168.         $user $this->get('security.token_storage')->getToken()->getUser();
  169.         $formProfil $this->createForm(RecCandidatProfilType::class,$user);
  170.         $request Request::createFromGlobals();
  171.         if ($request->getMethod() == 'POST') {
  172.             $formProfil->handleRequest($request);
  173.             if ($formProfil->isValid()) {
  174.                 $em $this->getDoctrine()->getManager();
  175.                 $em->persist($user);
  176.                 $em->flush();
  177.                 return $this->redirect($this->generateUrl('frontend_vacataire_view'));
  178.             }
  179.         }
  180.         return $this->render('Frontend/Vacataire/profil.html.twig',array("formProfil"=>$formProfil->createView()));
  181.     }
  182.     /**
  183.      * @Route("/reset-pwd", name="frontend_vacataire_mdp", host="%vacataire_subdomain%", methods={"POST"})
  184.      */
  185.     public function resetPwd(UserPasswordEncoderInterface $encoderMailerInterface $mailer)
  186.     {
  187.         $request Request::createFromGlobals();
  188.         $email trim($request->request->get('mail'));
  189.         $em $this->getDoctrine()->getManager();
  190.         $user $em->getRepository(RecCandidat::class)->findUser($email);
  191.         $site_short_name $this->container->get('parameter_bag')->get('site_short_name');
  192.         if($user)
  193.         {
  194.             $passmail $this->getPasswordRandom(7);
  195.             $password $encoder->encodePassword($user,$passmail);
  196.             $user->setPassword($password);
  197.             $em->persist($user);
  198.             $em->flush();
  199.             $mail_noreply $this->container->get('parameter_bag')->get('mail_noreply');
  200.             $mail = (new TemplatedEmail())
  201.                 ->from($mail_noreply)
  202.                 ->to($user->getEmail())
  203.                 ->subject('['.$site_short_name.'] Mise à jour de votre mot de passe')
  204.                 ->htmlTemplate('Courriel/reset_pwd_vacataire.html.twig')
  205.                 ->context(['user' => $user,'passmail'=>$passmail,'serveur'=>$_SERVER['HTTP_HOST']]);
  206.             try{
  207.                 $mailer->send($mail);
  208.                 $error false;
  209.             }catch(TransportExceptionInterface $e) {
  210.                 $response $e->getMessage();
  211.                 $error true;
  212.             }
  213.             $data = array("success"=>1,"message"=>"Un nouveau mot de passe vient d'être envoyé à l'adresse : ".$user->getEmail(),"password"=>$password);
  214.             return new JsonResponse($data);
  215.         }
  216.         else
  217.         {
  218.             $data = array("success"=>0,"message"=>"L'adresse de messagerie ne correspond à aucun compte.");
  219.             return new JsonResponse($data);
  220.         }
  221.     }
  222.     protected function getPasswordRandom($nb_caractere 12)
  223.     {
  224.         $mot_de_passe "";
  225.         $chaine "abcdefghjkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ023456789";
  226.         $longeur_chaine strlen($chaine);
  227.         for($i 1$i <= $nb_caractere$i++)
  228.         {
  229.             $place_aleatoire mt_rand(0,($longeur_chaine-1));
  230.             $mot_de_passe .= $chaine[$place_aleatoire];
  231.         }
  232.         return $mot_de_passe;
  233.     }
  234.     /**
  235.      * @Route("/activate-account", name="frontend_vacataire_activate_account", host="%vacataire_subdomain%", methods={"POST"})
  236.      */
  237.     public function sendMailActivateAccount(MailerInterface $mailer)
  238.     {
  239.         $request Request::createFromGlobals();
  240.         $email $request->request->get('mail');
  241.         $em $this->getDoctrine()->getManager();
  242.         $user $em->getRepository(RecCandidat::class)->findUser($email);
  243.         $site_short_name $this->container->get('parameter_bag')->get('site_short_name');
  244.         $signature_rh_recrutement $this->container->get('parameter_bag')->get('signature_rh_recrutement');
  245.         if($user)
  246.         {
  247.             $mail_noreply $this->container->get('parameter_bag')->get('mail_noreply');
  248.             $mail = (new TemplatedEmail())
  249.                 ->from($mail_noreply)
  250.                 ->to($user->getEmail())
  251.                 ->subject('['.$site_short_name.'] Votre création de compte pour le dépôt de votre dossier')
  252.                 ->htmlTemplate('Courriel/resend_mail_activate_account_vacataire.html.twig')
  253.                 ->context(['user' => $user,'serveur'=>$_SERVER['HTTP_HOST'],'signature_rh_recrutement'=>$signature_rh_recrutement]);
  254.             try{
  255.                 $mailer->send($mail);
  256.                 $error false;
  257.             }catch(TransportExceptionInterface $e) {
  258.                 $response $e->getMessage();
  259.                 $error true;
  260.             }
  261.             $data = array("success"=>1,"message"=>"Un nouveau courriel d'activation vient d'être envoyé à l'adresse : ".$user->getEmail());
  262.             $response = new JsonResponse($data);
  263.             return $response;
  264.         }
  265.         else
  266.         {
  267.             $data = array("success"=>0,"message"=>"L'adresse de messagerie ne correspond à aucun compte.");
  268.             $response = new JsonResponse($data);
  269.             return $response;
  270.         }
  271.     }
  272.     /**
  273.      * @Route("/vacataire", name="frontend_vacataire_view", host="%vacataire_subdomain%", methods={"GET"})
  274.      */
  275.     public function view()
  276.     {
  277.         $user $this->get('security.token_storage')->getToken()->getUser();
  278.         $em $this->getDoctrine()->getManager();
  279.         $formPwd $this->createForm(RecCandidatPwdType::class);
  280.         $dossiers $em->getRepository(RecDossierVacataire::class)->findByCandidat($user->getId());
  281.         $dossiersID = array();
  282.         $dossiersVac = array();
  283.         foreach ($dossiers as $d)
  284.         {
  285.             $dossiersID[]=$d->getVacation()->getId();
  286.             $dossiersVac[$d->getVacation()->getId()]=$d;
  287.         }
  288.         $vacations $em->getRepository(RecVacation::class)->findBy(["archive"=>false],['title'=>'DESC']);
  289.         foreach ($vacations as $v)
  290.         {
  291.             if(in_array($v->getId(),$dossiersID))
  292.                 $v->setDossier($dossiersVac[$v->getId()]);
  293.         }
  294.         return $this->render('Frontend/Vacataire/view.html.twig',array("vacations"=>$vacations,"dossiersID"=>$dossiersID,"formPwd"=>$formPwd->createView()));
  295.     }
  296.     /**
  297.      * @Route("/vacataire/create/{id}", name="frontend_vacation_create", host="%vacataire_subdomain%", methods={"GET"})
  298.      */
  299.     public function create($id)
  300.     {
  301.         $user $this->get('security.token_storage')->getToken()->getUser();
  302.         $em $this->getDoctrine()->getManager();
  303.         $vacation $em->getRepository(RecVacation::class)->find($id);
  304.         $dossier $em->getRepository(RecDossierVacataire::class)->findByCandidat($user->getId(),$id);
  305.         if(!$dossier) {
  306.             $dossierNmoins1 $em->getRepository(RecDossierVacataire::class)->findByCandidat($user->getId(),false,$vacation->getYear()-1);
  307.             $dossier = new RecDossierVacataire();
  308.             $dossier->setCandidat($user);
  309.             $dossier->setVacation($vacation);
  310.             $entity $em->getRepository(RecVacationStatut::class);
  311.             $q $entity
  312.                 ->createQueryBuilder('p')
  313.                 ->where('p.id = :id')
  314.                 ->setParameter('id'1)
  315.                 ->getQuery();
  316.             $statut $q->getOneOrNullResult();
  317.             if ($statut)
  318.                 $dossier->setVacationStatut($statut);
  319.             $entity $em->getRepository(RecVacationEtatDossier::class);
  320.             $q $entity
  321.                 ->createQueryBuilder('p')
  322.                 ->where('p.id = :id')
  323.                 ->setParameter('id'1)
  324.                 ->getQuery();
  325.             $etatDossier $q->getOneOrNullResult();
  326.             if ($etatDossier)
  327.                 $dossier->setVacationEtatDossier($etatDossier);
  328.             $entity $em->getRepository(RecVacationStatutCP::class);
  329.             $q $entity
  330.                 ->createQueryBuilder('p')
  331.                 ->where('p.id = :id')
  332.                 ->setParameter('id'1)
  333.                 ->getQuery();
  334.             $statutCP $q->getOneOrNullResult();
  335.             if ($statutCP)
  336.                 $dossier->setVacationStatutCP($statutCP);
  337.             $entity $em->getRepository(RecVacationStatutAC::class);
  338.             $q $entity
  339.                 ->createQueryBuilder('p')
  340.                 ->where('p.id = :id')
  341.                 ->setParameter('id'1)
  342.                 ->getQuery();
  343.             $statutAC $q->getOneOrNullResult();
  344.             if ($statutAC)
  345.                 $dossier->setVacationStatutAC($statutAC);
  346.             $user->addDossier($dossier);
  347.             $vacation->addDossier($dossier);
  348.             $em->persist($dossier);
  349.             $em->persist($user);
  350.             $em->persist($vacation);
  351.             $em->flush();
  352.             if($dossierNmoins1)
  353.             {
  354.                 foreach($dossierNmoins1->getDocuments() as $document)
  355.                 {
  356.                     if($document->getTypeDocument()->getTransfer() and $document->getTypeDocument()->getTransferDuration()>=$document->getNbTransfer() and $document->getVisaAC() and $document->getValidateCP()) {
  357.                         $dossier->setCommentaire($dossierNmoins1->getCommentaire());
  358.                         $dossier->setTypeVacataire($dossierNmoins1->getTypeVacataire());
  359.                         $newDocument = clone $document;
  360.                         $filePath $document->getAbsolutePath().'/'.$document->getHiddenName();
  361.                         if(file_exists($filePath)) {
  362.                             $newFilename sha1(uniqid(mt_rand(), true));
  363.                             $tmp explode("."$document->getHiddenName());
  364.                             $extension end($tmp);
  365.                             $newHiddenname "vac_" $newFilename '.' $extension;
  366.                             $newDocument->setHiddenName($newHiddenname);
  367.                             $newDocument->setNbTransfer($document->getNbTransfer()+1);
  368.                             $newFilePath $document->getAbsolutePath() . '/' $newHiddenname;
  369.                             copy($filePath$newFilePath);
  370.                         }
  371.                         $dossier->addDocument($newDocument);
  372.                         $newDocument->setDossier($dossier);
  373.                         $em->persist($newDocument);
  374.                     }
  375.                 }
  376.                 $em->persist($dossier);
  377.                 $em->flush();
  378.             }
  379.             $this->addLog($dossier"success""Création du dossier");
  380.         }
  381.         return $this->redirect($this->generateUrl('frontend_vacation_dossier',array("id"=>$dossier->getId())));
  382.     }
  383.     /**
  384.      * @Route("/vacataire/desactive-popup/{id}", name="frontend_vacation_dossier_desactive_popup", host="%vacataire_subdomain%", methods={"POST"})
  385.      */
  386.     public function desactivePopup($id)
  387.     {
  388.         $em $this->getDoctrine()->getManager();
  389.         $user $this->get('security.token_storage')->getToken()->getUser();
  390.         $dossier $em->getRepository(RecDossierVacataire::class)->find($id);
  391.         if($user->getId()==$dossier->getCandidat()->getId() && $dossier)
  392.         {
  393.             $dossier->setPopup(false);
  394.             $em->persist($dossier);
  395.             $em->flush();
  396.         }
  397.         return new JsonResponse();
  398.     }
  399.     /**
  400.      * @Route("/vacataire/dossier/{id}", name="frontend_vacation_dossier", host="%vacataire_subdomain%", methods={"GET"})
  401.      */
  402.     public function dossier($id)
  403.     {
  404.         $user $this->get('security.token_storage')->getToken()->getUser();
  405.         $em $this->getDoctrine()->getManager();
  406.         $dossier $em->getRepository(RecDossierVacataire::class)->find($id);
  407.         $candidat $em->getRepository(RecCandidat::class)->findUser($user->getEmail());
  408.         if($dossier->getVacation()->isArchive())
  409.             return $this->redirect($this->generateUrl('frontend_vacataire_view'));
  410.         if($dossier->getCandidat()->getId()!=$candidat->getId())
  411.             return $this->redirect($this->generateUrl('frontend_vacataire_view'));
  412.         $typeDocuments $em->getRepository(RecTypeDocumentVacataire::class)->findAll();
  413.         $typeVacataires $em->getRepository(RecTypeVacataire::class)->findBy(array('private'=>false));
  414.         $servcomps $em->getRepository(RecServiceComposanteVacation::class)->findAll();
  415.         $servcompsAffected = array();
  416.         foreach ($dossier->getServicesOrComposantes() as $s)
  417.         {
  418.             $servcompsAffected[]=$s->getId();
  419.         }
  420.         $typeDocAffected = array();
  421.         $typeDocNotAffected = array();
  422.         if($dossier->getTypeVacataire()) {
  423.             foreach ($dossier->getTypeVacataire()->getTypeDocuments() as $td)
  424.                 $typeDocAffected[] = $td->getId();
  425.             foreach ($typeDocuments as $td) {
  426.                 if (!in_array($td->getId(), $typeDocAffected))
  427.                     $typeDocNotAffected[] = $td->getId();
  428.             }
  429.         }
  430.         return $this->render('Frontend/Vacataire/dossier.html.twig',array("dossier"=>$dossier"servcomps"=>$servcomps,"servcompsAffected"=>$servcompsAffected,"typeDocuments"=>$typeDocuments,"typeVacataires"=>$typeVacataires"typeDocNotAffected"=>$typeDocNotAffected));
  431.     }
  432.     /**
  433.      * @Route("/vacataire/dossier/{id}/upload/doc/{idDoc}", name="frontend_dossier_upload_doc", host="%vacataire_subdomain%", methods={"POST"})
  434.      */
  435.     public function uploadDoc(MailerInterface $mailer$id$idDoc)
  436.     {
  437.         $request Request::createFromGlobals();
  438.         $files $request->files;
  439.         $user $this->get('security.token_storage')->getToken()->getUser();
  440.         $em $this->getDoctrine()->getManager();
  441.         $dossier $em->getRepository(RecDossierVacataire::class)->find($id);
  442.         $typeDoc $em->getRepository(RecTypeDocumentVacataire::class)->find($idDoc);
  443.         $extensions_authorized = array('pdf');
  444.         $mail_noreply $this->container->get('parameter_bag')->get('mail_noreply');
  445.         if($user->getId()==$dossier->getCandidat()->getId()) {
  446.             $uploadedFile $files->get("file");
  447.             $extension $uploadedFile->guessExtension();
  448.             if (!in_array($extension$extensions_authorized)) {
  449.                 $response = new JsonResponse(array("error" => 1"message" => "Type de fichier non autorisé ! <br> Format autorisé : pdf"));
  450.                 return $response;
  451.             }
  452.             if($dossier->isPieceRefuse($idDoc) and trim($dossier->getGestMail())!="")
  453.             {
  454.                 $mail = (new TemplatedEmail())
  455.                     ->from($mail_noreply)
  456.                     ->to($dossier->getGestMail())
  457.                     ->subject('Ajout d\'une nouvelle pièce au dossier')
  458.                     ->htmlTemplate('Courriel/send_new_piece_gest.html.twig')
  459.                     ->context(['dossier'=>$dossier,'serveur'=>$_SERVER['HTTP_HOST']]);
  460.                 try{
  461.                     $mailer->send($mail);
  462.                     $error false;
  463.                 }catch(TransportExceptionInterface $e) {
  464.                     $response $e->getMessage();
  465.                     $error true;
  466.                 }
  467.             }
  468.             if($dossier->isPieceRefuseByACOrCP($idDoc))
  469.             {
  470.                 $destMailsAC=$this->container->get('parameter_bag')->get('mail_rh_agence_comptable');
  471.                 $destMailsCP=$this->container->get('parameter_bag')->get('mail_rh_controle_paye');
  472.                 $destMails array_merge($destMailsAC$destMailsCP);
  473.                 $mail = (new TemplatedEmail())
  474.                     ->from($mail_noreply)
  475.                     ->to($destMails)
  476.                     ->subject('Ajout d\'une nouvelle pièce au dossier après refus')
  477.                     ->htmlTemplate('Courriel/send_new_piece_cpac.html.twig')
  478.                     ->context(['dossier'=>$dossier,'serveur'=>$_SERVER['HTTP_HOST']]);
  479.                 try{
  480.                     $mailer->send($mail);
  481.                     $error false;
  482.                 }catch(TransportExceptionInterface $e) {
  483.                     $response $e->getMessage();
  484.                     $error true;
  485.                 }
  486.             }
  487.             $name $uploadedFile->getClientOriginalName();
  488.             $filename sha1(uniqid(mt_rand(), true));
  489.             $hiddenname"vac_".$filename.'.'.$extension;
  490.             $upload = new RecDocumentVacataire();
  491.             $file $uploadedFile->move($upload->getAbsolutePath(), $hiddenname);
  492.             $dossier->addDocument($upload);
  493.             $upload->setDossier($dossier);
  494.             $upload->setTypeDocument($typeDoc);
  495.             $upload->setName($name);
  496.             $upload->setHiddenName($hiddenname);
  497.             $upload->setValidate(false);
  498.             $em->persist($dossier);
  499.             $em->persist($upload);
  500.             $em->flush();
  501.             $this->addLog($dossier,"info"," Pièce ajouté : ".$upload->getName());
  502.             return new JsonResponse(array("id"=>$upload->getId(),"name"=>$name." (déposé le ".$upload->getDateInit()->format("d-m-Y à H:i").")",'error'=>0));
  503.         }
  504.         else
  505.             return new JsonResponse(array('error'=>'user'));
  506.     }
  507.     /**
  508.      * @Route("/vacataire/dossier/download/doc/{id}", name="frontend_dossier_download_doc", host="%vacataire_subdomain%", methods={"GET"})
  509.      */
  510.     public function downloadDoc($id)
  511.     {
  512.         $em $this->getDoctrine()->getManager();
  513.         $document $em->getRepository(RecDocumentVacataire::class)->find($id);
  514.         $user $this->get('security.token_storage')->getToken()->getUser();
  515.         $dossier $document->getDossier();
  516.         if($document and $dossier && $user->getId()==$dossier->getCandidat()->getId())
  517.             return $this->file($document->getAbsolutePath().'/'.$document->getHiddenName(), $document->getName(), ResponseHeaderBag::DISPOSITION_INLINE);
  518.         else
  519.             return $this->redirectToRoute('frontend_candidat');
  520.     }
  521.     /**
  522.      * @Route("/vacataire/dossier/download/contrat/{id}", name="frontend_dossier_download_contrat", host="%vacataire_subdomain%", methods={"GET"})
  523.      */
  524.     public function downloadContrat($id)
  525.     {
  526.         $em $this->getDoctrine()->getManager();
  527.         $document $em->getRepository(RecContratVacataire::class)->find($id);
  528.         $user $this->get('security.token_storage')->getToken()->getUser();
  529.         $dossier $document->getDossier();
  530.         if($document && $dossier && $user->getId()==$dossier->getCandidat()->getId())
  531.             return $this->file($document->getAbsolutePath().'/'.$document->getHiddenName(), $document->getName(), ResponseHeaderBag::DISPOSITION_INLINE);
  532.         else
  533.             return $this->redirectToRoute('frontend_candidat');
  534.     }
  535.     /**
  536.      * @Route("/vacataire/dossier/download/etat_liquid/{id}", name="frontend_dossier_download_etat_liquid_doc", host="%vacataire_subdomain%", methods={"GET"})
  537.      */
  538.     public function downloadEtatLiquidationDoc($id)
  539.     {
  540.         $em $this->getDoctrine()->getManager();
  541.         $document $em->getRepository(RecEtatLiquidationDocVacataire::class)->find($id);
  542.         $user $this->get('security.token_storage')->getToken()->getUser();
  543.         $dossier $document->getEtatLiquidation()->getDossier();
  544.         if($document && $dossier && $user->getId()==$dossier->getCandidat()->getId())
  545.             return $this->file($document->getAbsolutePath().'/'.$document->getHiddenName(), $document->getName(), ResponseHeaderBag::DISPOSITION_INLINE);
  546.         else
  547.             return $this->redirectToRoute('frontend_candidat');
  548.     }
  549.     /**
  550.      * @Route("/vacataire/dossier/{id}/upload/contrat", name="frontend_dossier_upload_contrat", host="%vacataire_subdomain%", methods={"POST"})
  551.      */
  552.     public function uploadContrat(MailerInterface $mailer$id)
  553.     {
  554.         $request Request::createFromGlobals();
  555.         $files $request->files;
  556.         $user $this->get('security.token_storage')->getToken()->getUser();
  557.         $em $this->getDoctrine()->getManager();
  558.         $dossier $em->getRepository(RecDossierVacataire::class)->find($id);
  559.         $mail_noreply $this->container->get('parameter_bag')->get('mail_noreply');
  560.         $mail_rh_vacataire $this->container->get('parameter_bag')->get('mail_rh_vacataire');
  561.         $initStatutContrat $em->getRepository(RecVacationStatutContrat::class)->find(4);
  562.         $extensions_authorized = array('pdf');
  563.         $result=array();
  564.         if($user->getId()==$dossier->getCandidat()->getId()) {
  565.             $uploadedFile $files->get("file");
  566.             $extension $uploadedFile->guessExtension();
  567.             if (!in_array($extension$extensions_authorized)) {
  568.                 $response = new JsonResponse(array("error" => 1"message" => "Type de fichier non autorisé ! <br> Format autorisé : pdf"));
  569.                 return $response;
  570.             }
  571.             $name $uploadedFile->getClientOriginalName();
  572.             $filename sha1(uniqid(mt_rand(), true));
  573.             $hiddenname"vac_".$filename.'.'.$extension;
  574.             $upload = new RecContratVacataire();
  575.             $file $uploadedFile->move($upload->getAbsolutePath(), $hiddenname);
  576.             $dossier->addContrat($upload);
  577.             $upload->setDossier($dossier);
  578.             $upload->setStatutContrat($initStatutContrat);
  579.             $upload->setName($name);
  580.             $upload->setHiddenName($hiddenname);
  581.             $upload->setPublic(true);
  582.             $em->persist($dossier);
  583.             $em->persist($upload);
  584.             $em->flush();
  585.             foreach ($dossier->getServicesOrComposantes() as $servComp) {
  586.                 $mail = (new TemplatedEmail())
  587.                     ->from($mail_noreply)
  588.                     ->to($mail_rh_vacataire)
  589.                     ->cc(...explode(";"$servComp->getMails()))
  590.                     ->subject('Nouveau contrat signé')
  591.                     ->htmlTemplate('Courriel/mail_contrat_cand.html.twig')
  592.                     ->context(['dossier' => $dossier'serveur' => $_SERVER['HTTP_HOST']]);
  593.                 try {
  594.                     $mailer->send($mail);
  595.                     $error false;
  596.                 } catch (TransportExceptionInterface $e) {
  597.                     $response $e->getMessage();
  598.                     $error true;
  599.                 }
  600.             }
  601.             $this->addLog($dossier,"success"," Contrat ajouté : ".$upload->getName());
  602.             $result[] = array("id"=>$upload->getId(),"name"=>$name." (déposé le ".$upload->getDateInit()->format("d-m-Y à H:i").")",'error'=>0);
  603.         }
  604.         $response = new JsonResponse($result);
  605.         return $response;
  606.     }
  607.     /**
  608.      * @Route("/vacataire/dossier/{id}/upload/etat_liquid", name="frontend_dossier_upload_etat_liquid_doc", host="%vacataire_subdomain%", methods={"POST"})
  609.      */
  610.     public function uploadEtatLiquidationDoc(MailerInterface $mailer$id)
  611.     {
  612.         $request Request::createFromGlobals();
  613.         $files $request->files;
  614.         $user $this->get('security.token_storage')->getToken()->getUser();
  615.         $em $this->getDoctrine()->getManager();
  616.         $etatLiquid $em->getRepository(RecEtatLiquidationVacataire::class)->find($id);
  617.         $initStatutEtatLiquidation $em->getRepository(RecVacationStatutEtatLiquidation::class)->find(4);
  618.         $mail_noreply $this->container->get('parameter_bag')->get('mail_noreply');
  619.         $extensions_authorized = array('pdf');
  620.         $result=array();
  621.         if($user->getId()==$etatLiquid->getDossier()->getCandidat()->getId()) {
  622.             $uploadedFile $files->get("file");
  623.             $extension $uploadedFile->guessExtension();
  624.             if (!in_array($extension$extensions_authorized)) {
  625.                 $response = new JsonResponse(array("error" => 1"message" => "Type de fichier non autorisé ! <br> Format autorisé : pdf"));
  626.                 return $response;
  627.             }
  628.             $name $uploadedFile->getClientOriginalName();
  629.             $filename sha1(uniqid(mt_rand(), true));
  630.             $hiddenname"vac_".$filename.'.'.$extension;
  631.             $upload = new RecEtatLiquidationDocVacataire();
  632.             $file $uploadedFile->move($upload->getAbsolutePath(), $hiddenname);
  633.             $etatLiquid->addDocument($upload);
  634.             $upload->setEtatLiquidation($etatLiquid);
  635.             $upload->setStatutEtatLiquidation($initStatutEtatLiquidation);
  636.             $upload->setName($name);
  637.             $upload->setHiddenName($hiddenname);
  638.             $upload->setPublic(true);
  639.             $em->persist($etatLiquid);
  640.             $em->persist($upload);
  641.             $em->flush();
  642.             $mails explode(";"$etatLiquid->getServComp()->getMails());
  643.             $mail = (new TemplatedEmail())
  644.                 ->from($mail_noreply);
  645.             foreach ($mails as $d)
  646.                 $mail->addTo($d);
  647.             $mail->subject('Nouvel Etat de liquidation signé')
  648.                 ->htmlTemplate('Courriel/mail_etat_liquidation_cand.html.twig')
  649.                 ->context(['dossier' =>$etatLiquid->getDossier(),'mailGest'=>$etatLiquid->getServComp()->getMails(),'serveur'=>$_SERVER['HTTP_HOST']]);
  650.             try{
  651.                 $mailer->send($mail);
  652.                 $error false;
  653.             }catch(TransportExceptionInterface $e) {
  654.                 $response $e->getMessage();
  655.                 $error true;
  656.             }
  657.             $this->addLog($etatLiquid->getDossier(),"success"," Etat de liquidation ajouté : ".$upload->getName());
  658.             $result[] = array("id"=>$upload->getId(),"name"=>$name." (déposé le ".$upload->getDateInit()->format("d-m-Y à H:i").")",'error'=>0,'mailGest'=>$etatLiquid->getServComp()->getMails());
  659.         }
  660.         $response = new JsonResponse($result);
  661.         return $response;
  662.     }
  663.     /**
  664.      * @Route("/vacataire/dossier/remove-contrat/{id}", name="frontend_dossier_remove_contrat", host="%vacataire_subdomain%", methods={"POST"})
  665.      */
  666.     public function removeContrat($id)
  667.     {
  668.         $em $this->getDoctrine()->getManager();
  669.         $contrat $em->getRepository(RecContratVacataire::class)->find($id);
  670.         if (!$contrat) {
  671.             throw $this->createNotFoundException('Unable to find Client entity.');
  672.         }
  673.         $user $this->get('security.token_storage')->getToken()->getUser();
  674.         $dossier $contrat->getDossier();
  675.         if($user->getId()==$dossier->getCandidat()->getId() and !$contrat->getAdmin() and $contrat->getStatutContrat()->getPublic())
  676.         {
  677.             $contrat->removeFile();
  678.             $em->remove($contrat);
  679.             $em->flush();
  680.             $this->addLog($dossier,"alert"," Contrat supprimée : ".$contrat->getName());
  681.         }
  682.         $response = new JsonResponse(array('error'=>0));
  683.         return $response;
  684.     }
  685.     /**
  686.      * @Route("/vacataire/dossier/remove-etat-liquid/{id}", name="frontend_dossier_remove_etat_liquid_doc", host="%vacataire_subdomain%", methods={"POST"})
  687.      */
  688.     public function removeEtatLiquidationDoc($id)
  689.     {
  690.         $em $this->getDoctrine()->getManager();
  691.         $etatLiquidDoc $em->getRepository(RecEtatLiquidationDocVacataire::class)->find($id);
  692.         if (!$etatLiquidDoc) {
  693.             throw $this->createNotFoundException('Unable to find Client entity.');
  694.         }
  695.         $user $this->get('security.token_storage')->getToken()->getUser();
  696.         $dossier $etatLiquidDoc->getEtatLiquidation()->getDossier();
  697.         if($user->getId()==$dossier->getCandidat()->getId() and $etatLiquidDoc->getStatuEtatLiquidation()->getPublic())
  698.         {
  699.             $etatLiquidDoc->removeFile();
  700.             $em->remove($etatLiquidDoc);
  701.             $em->flush();
  702.             $this->addLog($dossier,"alert"," Etat liquidation (document) supprimée : ".$etatLiquidDoc->getName());
  703.         }
  704.         $response = new JsonResponse(array('error'=>0));
  705.         return $response;
  706.     }
  707.     /**
  708.      * @Route("/vacataire/dossier/remove-doc/{id}", name="frontend_dossier_remove_doc", host="%vacataire_subdomain%", methods={"POST"})
  709.      */
  710.     public function removeDoc($id)
  711.     {
  712.         $em $this->getDoctrine()->getManager();
  713.         $document $em->getRepository(RecDocumentVacataire::class)->find($id);
  714.         if (!$document) {
  715.             throw $this->createNotFoundException('Unable to find Client entity.');
  716.         }
  717.         $user $this->get('security.token_storage')->getToken()->getUser();
  718.         $dossier $document->getDossier();
  719.         $this->addLog($dossier,"alert"," Pièce supprimée : ".$document->getName());
  720.         if($dossier && !$dossier->getValidate())
  721.         {
  722.             if($user->getId()==$dossier->getCandidat()->getId())
  723.             {
  724.                 $document->removeFile();
  725.                 $em->remove($document);
  726.                 $em->flush();
  727.             }
  728.         }
  729.         $response = new JsonResponse(array('error'=>0));
  730.         return $response;
  731.     }
  732.     /**
  733.      * @Route("/vacataire/dossier/{id}/add-affectation", name="frontend_dossier_add_affectation", host="%vacataire_subdomain%", methods={"POST"})
  734.      */
  735.     public function addAffectation(MailerInterface $mailer$id)
  736.     {
  737.         $user $this->get('security.token_storage')->getToken()->getUser();
  738.         $em $this->getDoctrine()->getManager();
  739.         $dossier $em->getRepository(RecDossierVacataire::class)->find($id);
  740.         $request Request::createFromGlobals();
  741.         $selected $request->request->get('selected');
  742.         $servComps "";
  743.         $servCompsAffected = array();
  744.         $mail_noreply $this->container->get('parameter_bag')->get('mail_noreply');
  745.         foreach($dossier->getServicesOrComposantes() as $s)
  746.         {
  747.             $servCompsAffected[$s->getId()]=$s;
  748.         }
  749.         if($user->getId()==$dossier->getCandidat()->getId())
  750.         {
  751.             $dossier->cleanServicesOrComposantes();
  752.             if(is_array($selected)) {
  753.                 foreach ($selected as $s) {
  754.                     $servComp $em->getRepository(RecServiceComposanteVacation::class)->find($s);
  755.                     $dossier->addServicesOrComposante($servComp);
  756.                     if(!isset($servCompsAffected[$servComp->getId()]))
  757.                     {
  758.                         $mail = (new TemplatedEmail())
  759.                             ->from($mail_noreply)
  760.                             ->to(...explode(";",$servComp->getMails()))
  761.                             ->subject('Affecation dossier vacataire')
  762.                             ->htmlTemplate('Courriel/send_affectation_gest.html.twig')
  763.                             ->context(['dossier'=>$dossier,'serveur'=>$_SERVER['HTTP_HOST']]);
  764.                         try{
  765.                             $mailer->send($mail);
  766.                             $error false;
  767.                         }catch(TransportExceptionInterface $e) {
  768.                             $response $e->getMessage();
  769.                             $error true;
  770.                         }
  771.                     }
  772.                     $servComps.=$servComp->getName().", ";
  773.                 }
  774.             }
  775.             $em->persist($dossier);
  776.             $em->flush();
  777.         }
  778.         $this->addLog($dossier,"info","Choix de l'affectation : ".$servComps);
  779.         $response = new JsonResponse(array('error'=>0,'servCompsAffected'=>$servCompsAffected));
  780.         return $response;
  781.     }
  782.     /**
  783.      * @Route("/vacataire/dossier/{id}/set/statut/{idType}", name="frontend_vacataire_set_statut", host="%vacataire_subdomain%", methods={"POST"})
  784.      */
  785.     public function setStatut($id,$idType)
  786.     {
  787.         $user $this->get('security.token_storage')->getToken()->getUser();
  788.         $em $this->getDoctrine()->getManager();
  789.         $dossier $em->getRepository(RecDossierVacataire::class)->find($id);
  790.         $type $em->getRepository(RecTypeVacataire::class)->find($idType);
  791.         if($user->getId()==$dossier->getCandidat()->getId())
  792.         {
  793.             $dossier->setTypeVacataire($type);
  794.             $em->persist($dossier);
  795.             $em->flush();
  796.         }
  797.         $typeDocs=array();
  798.         foreach($type->getTypeDocuments() as $td)
  799.         {
  800.             $typeDocs[] = $td->getId();
  801.         }
  802.         $this->addLog($dossier,"info","Choix du statut : ".$type->getName());
  803.         $response = new JsonResponse(array('error'=>0,'typeDocs'=>$typeDocs));
  804.         return $response;
  805.     }
  806.     /**
  807.      * @Route("/vacataire/dossier/{id}/request_in/{status}", name="frontend_dossier_request_in", host="%vacataire_subdomain%", methods={"POST"})
  808.      */
  809.     public function requestIN($id,$status)
  810.     {
  811.         $em $this->getDoctrine()->getManager();
  812.         $user $this->get('security.token_storage')->getToken()->getUser();
  813.         $dossier $em->getRepository(RecDossierVacataire::class)->find($id);
  814.         if($user->getId()==$dossier->getCandidat()->getId()) {
  815.             $dossier->setRequestIN($status);
  816.             $em->persist($dossier);
  817.             $em->flush();
  818.         }
  819.         $response = new JsonResponse(array('status'=>$status));
  820.         return $response;
  821.     }
  822.     /**
  823.      * @Route("/vacataire/validate/{id}", name="frontend_dossier_validate", host="%vacataire_subdomain%", methods={"POST"})
  824.      */
  825.     public function validate(MailerInterface $mailer$id)
  826.     {
  827.         $em $this->getDoctrine()->getManager();
  828.         $user $this->get('security.token_storage')->getToken()->getUser();
  829.         $dossier $em->getRepository(RecDossierVacataire::class)->find($id);
  830.         $mail_noreply $this->container->get('parameter_bag')->get('mail_noreply');
  831.         if($user->getId()==$dossier->getCandidat()->getId())
  832.         {
  833.             $now = new \DateTime('now');
  834.             if($now>=$dossier->getVacation()->getOpenDate() && $now<=$dossier->getVacation()->getCloseDate())
  835.             {
  836.                 $dossier->setValidate(true);
  837.                 $dossier->setDateValidate(new \DateTime('now'));
  838.                 $em->persist($dossier);
  839.                 $em->flush();
  840.                 $this->addLog($dossier,"success","Dossier validé");
  841.                 foreach ($dossier->getServicesOrComposantes() as $servComp)
  842.                 {
  843.                     $mail = (new TemplatedEmail())
  844.                         ->from($mail_noreply)
  845.                         ->to(...explode(";",$servComp->getMails()))
  846.                         ->subject('Validation dossier vacataire')
  847.                         ->htmlTemplate('Courriel/send_validate_gest.html.twig')
  848.                         ->context(['dossier'=>$dossier,'serveur'=>$_SERVER['HTTP_HOST']]);
  849.                     try{
  850.                         $mailer->send($mail);
  851.                         $error false;
  852.                     }catch(TransportExceptionInterface $e) {
  853.                         $response $e->getMessage();
  854.                         $error true;
  855.                     }
  856.                 }
  857.             }
  858.         }
  859.         $response = new JsonResponse(array('error'=>0));
  860.         return $response;
  861.     }
  862.     /**
  863.      * @Route("/vacataire/delete/{id}", name="frontend_vacation_delete", host="%vacataire_subdomain%", methods={"GET"})
  864.      */
  865.     public function delete($id)
  866.     {
  867.         $em $this->getDoctrine()->getManager();
  868.         $candidature $em->getRepository(RecDossierVacataire::class)->find($id);
  869.         if (!$candidature) {
  870.             throw $this->createNotFoundException('Unable to find candidature entity.');
  871.         }
  872.         $user $this->get('security.token_storage')->getToken()->getUser();
  873.         if($candidature)
  874.         {
  875.             if($user->getId()==$candidature->getCandidat()->getId())
  876.             {
  877.                 foreach($candidature->getDocuments() as $document)
  878.                 {
  879.                     $document->removeFile();
  880.                     $em->remove($document);
  881.                 }
  882.                 $em->flush();
  883.                 $em->remove($candidature);
  884.                 $em->flush();
  885.             }
  886.         }
  887.         return $this->redirect($this->generateUrl('frontend_vacataire_view'));
  888.     }
  889.     protected function addLog(\App\Entity\RecDossierVacataire $dossier$status$description)
  890.     {
  891.         $user $this->get('security.token_storage')->getToken()->getUser();
  892.         $em $this->getDoctrine()->getManager();
  893.         $log = new RecLogDossierVacataire();
  894.         $log->setDossier($dossier);
  895.         $log->setUsername($user->getUserName());
  896.         $log->setStatus($status);
  897.         $log->setDescription($description);
  898.         $em->persist($log);
  899.         $em->flush();
  900.         return;
  901.     }
  902.     /**
  903.      * @Route("/vacataire/mod-pwd", name="frontend_vacataire_mod_pwd", host="%vacataire_subdomain%", methods={"POST"})
  904.      */
  905.     public function modifyPwd(EncoderFactoryInterface $encoderFactory)
  906.     {
  907.         $request Request::createFromGlobals();
  908.         $password $request->request->get("password");
  909.         $confirm $request->request->get("confirm");
  910.         $user $this->get('security.token_storage')->getToken()->getUser();
  911.         $em $this->getDoctrine()->getManager();
  912.         $encoder $encoderFactory->getEncoder($user);
  913.         if($password==$confirm)
  914.         {
  915.             $password $encoder->encodePassword($password$user->getSalt());
  916.             $user->setPassword($password);
  917.             $em->persist($user);
  918.             $em->flush();
  919.         }
  920.         $data = array("success"=>1);
  921.         $response = new JsonResponse($data);
  922.         return $response;
  923.     }
  924.     /**
  925.      * @Route("/vacataire/send-msg", name="frontend_vacataire_send_msg", host="%vacataire_subdomain%", methods={"POST"})
  926.      */
  927.     public function sendMsg(MailerInterface $mailer)
  928.     {
  929.         $request Request::createFromGlobals();
  930.         $title $request->request->get("title");
  931.         $message $request->request->get("message");
  932.         $output=false;
  933.         $user $this->get('security.token_storage')->getToken()->getUser();
  934.         $mail_noreply $this->container->get('parameter_bag')->get('mail_noreply');
  935.         $mail_admin $this->container->get('parameter_bag')->get('mail_admin');
  936.         $mail_rh_vacataire $this->container->get('parameter_bag')->get('mail_rh_vacataire');
  937.         $mail = (new TemplatedEmail())
  938.             ->from($mail_noreply)
  939.             ->to($mail_rh_vacataire)
  940.             ->cc($mail_admin)
  941.             ->subject("Nouveau commentaire d'un utilisateur pour l'application de recrutement")
  942.             ->htmlTemplate('Courriel/candidat_msg.html.twig')
  943.             ->context(['user' => $user'title'=>$title'message'=>$message]);
  944.         try{
  945.             $mailer->send($mail);
  946.             $error false;
  947.         }catch(TransportExceptionInterface $e) {
  948.             $response $e->getMessage();
  949.             $error true;
  950.         }
  951.         $data = array("success"=>$output);
  952.         $response = new JsonResponse($data);
  953.         return $response;
  954.     }
  955. }