<?php
namespace App\Controller\ThemesWebsite\Cvs\GestionCandidates;
use App\Entity\Core\Mails;
use App\Entity\Cvs\Candidates;
use App\Entity\Cvs\CandidatesHasExperiences;
use App\Entity\Cvs\CandidatesHasProjects;
use App\Entity\Cvs\CandidatesHasServices;
use App\Entity\Cvs\CandidatesHasSkills;
use App\Entity\Cvs\CandidatesHasTitles;
use App\Entity\Cvs\History;
use App\Entity\Cvs\Invitations;
use App\Form\Cvs\CandidatesSearchForm;
use App\Form\Cvs\CandidatesSettingsForm;
use App\Form\Cvs\CandidatesStep1Form;
use App\Form\Cvs\CandidatesStep2Form;
use App\Form\Cvs\ExperiencesForm;
use App\Form\Cvs\ProjectsForm;
use App\Form\Cvs\ServicesForm;
use App\Form\Cvs\SkillsForm;
use App\Services\Core\Core;
use App\Services\Core\RequestData;
use App\Services\Core\Users;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
* Générateur de CV
*/
class GenerateController extends AbstractController
{
private $rd;
private $em;
private $ms;
public function __construct(RequestData $rd,
EntityManagerInterface $em,
\App\Services\Mails $ms
){
$this->rd = $rd;
$this->em = $em;
$this->ms = $ms;
}
/**
* Mes informations
* @param Request $request
* @return Response
*/
public function coordinates(Request $request): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
$candidate = new Candidates();
$candidate->setName($user->getName());
$candidate->setLastname($user->getLastname());
$candidate->setEmail($user->getEmail());
$candidate->setFirst(true);
$this->em->persist($candidate);
$this->em->flush();
$user->setCandidate($candidate);
$this->em->persist($user);
$this->em->flush();
}
$form = $this->createForm(CandidatesStep1Form::class, $candidate);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $request->request->all();
$data = $data['candidates_step1_form'];
$infoAddress = $this->rd->searchAddress($data['address']);
$infoAddress = $infoAddress[0];
$points = $this->rd->getPoints($data['address']);
$candidate->setAddress($infoAddress['streetAddress']);
$candidate->setZipcode($infoAddress['postcode']);
$candidate->setCity($infoAddress['city']);
$candidate->setCountry($infoAddress['country']);
$candidate->setPointX($points[0]);
$candidate->setPointY($points[1]);
$this->em->persist($candidate);
$this->em->flush();
$user->setName($candidate->getName());
$user->setLastname($candidate->getLastname());
$this->em->persist($user);
$this->em->flush();
$session->getFlashBag()->add('success', 'Mise à jour des informations');
return $this->redirectToRoute('cvs_gestion_candidates_generate_informations');
}
$queryAddress = $candidate->getAddress().", ".$candidate->getZipcode().", ".$candidate->getCity().", ".$candidate->getCountry();
return $this->render('themesWebsite/cvs/gestion/candidates/generate/coordinates/fiche.html.twig',[
'form' => $form->createView(),
'queryAddress' => $queryAddress
]);
}
/**
* Ma recherche
* @param Request $request
* @return Response
* @throws \Exception
*/
public function informations(Request $request): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
Throw new \Exception("Aucun CV");
}
$form = $this->createForm(CandidatesStep2Form::class, $candidate);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $request->request->all();
$this->em->persist($candidate);
$this->em->flush();
$session->getFlashBag()->add('success', 'Mise à jour des informations');
if($data['submit'] == "0") {
return $this->redirectToRoute('cvs_gestion_candidates_generate_coordinates');
}
return $this->redirectToRoute('cvs_gestion_candidates_generate_search');
}
return $this->render('themesWebsite/cvs/gestion/candidates/generate/informations/fiche.html.twig',[
'form' => $form->createView()
]);
}
/**
* Ma recherche
* @param Request $request
* @return Response
* @throws \Exception
*/
public function search(Request $request): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
Throw new \Exception("Aucun CV");
}
$titles = $this->em->getRepository(CandidatesHasTitles::class)->findBy(['candidate' => $candidate],['title' => 'ASC']);
$cht = new CandidatesHasTitles();
$cht->setCandidate($candidate);
$form = $this->createForm(CandidatesSearchForm::class, $cht);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->em->persist($cht);
$this->em->flush();
$session->getFlashBag()->add('success', 'Mise à jour des informations');
return $this->redirectToRoute('cvs_gestion_candidates_generate_search');
}
return $this->render('themesWebsite/cvs/gestion/candidates/generate/search/list.html.twig',[
'form' => $form->createView(),
'titles' => $titles
]);
}
/**
* Modifier un titre
* @param Request $request
* @param CandidatesHasTitles $title
* @return Response
* @throws \Exception
*/
public function titlesEdit(Request $request, CandidatesHasTitles $title): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
Throw new \Exception("Aucun CV");
}
if($title->getCandidate() != $candidate) {
Throw new \Exception("Mauvaise fiche");
}
$form = $this->createForm(CandidatesSearchForm::class, $title);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->em->persist($title);
$this->em->flush();
$session->getFlashBag()->add('success', 'Mise à jour des informations');
return $this->redirectToRoute('cvs_gestion_candidates_generate_search');
}
return $this->render('themesWebsite/cvs/gestion/candidates/generate/search/edit.html.twig',[
'form' => $form->createView(),
'title' => $title
]);
}
/**
* Confirmer la suppression d'un titre
* @param Request $request
* @param CandidatesHasTitles $title
* @return Response
* @throws \Exception
*/
public function titlesRemove(Request $request, CandidatesHasTitles $title): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
Throw new \Exception("Aucun CV");
}
if($title->getCandidate() != $candidate) {
Throw new \Exception("Mauvaise fiche");
}
return $this->render('themesWebsite/cvs/gestion/candidates/generate/search/remove.html.twig',[
'title' => $title
]);
}
/**
* Supprimer un titre
* @param Request $request
* @param CandidatesHasTitles $title
* @return Response
* @throws \Exception
*/
public function titlesDelete(Request $request, CandidatesHasTitles $title): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
Throw new \Exception("Aucun CV");
}
if($title->getCandidate() != $candidate) {
Throw new \Exception("Mauvaise fiche");
}
$this->em->remove($title);
$this->em->flush();
$session->getFlashBag()->add('success', 'Mise à jour des informations');
return $this->redirectToRoute('cvs_gestion_candidates_generate_search');
}
/**
* Mes services
* @param Request $request
* @return Response
* @throws \Exception
*/
public function services(Request $request): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
Throw new \Exception("Aucun CV");
}
$service = new CandidatesHasServices();
$service->setCandidate($candidate);
$service->setOnline(true);
$form = $this->createForm(ServicesForm::class, $service);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->em->persist($service);
$this->em->flush();
$session->getFlashBag()->add('success', 'Mise à jour des informations');
return $this->redirectToRoute('cvs_gestion_candidates_generate_services');
}
$services = $this->em->getRepository(CandidatesHasServices::class)->findBy(['candidate' => $candidate]);
return $this->render('themesWebsite/cvs/gestion/candidates/generate/services/list.html.twig',[
'form' => $form->createView(),
'services' => $services
]);
}
/**
* Modifier un service
* @param Request $request
* @param CandidatesHasExperiences $experience
* @return Response
* @throws \Exception
*/
public function servicesEdit(Request $request, CandidatesHasServices $service): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
Throw new \Exception("Aucun CV");
}
if($service->getCandidate() != $candidate) {
Throw new \Exception("Mauvaise fiche");
}
$form = $this->createForm(ServicesForm::class, $service);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->em->persist($service);
$this->em->flush();
$session->getFlashBag()->add('success', 'Mise à jour des informations');
return $this->redirectToRoute('cvs_gestion_candidates_generate_services');
}
return $this->render('themesWebsite/cvs/gestion/candidates/generate/services/edit.html.twig',[
'form' => $form->createView(),
'service' => $service
]);
}
/**
* Confirmer la suppresison d'un service
* @param Request $request
* @param CandidatesHasExperiences $experience
* @return Response
* @throws \Exception
*/
public function servicesRemove(Request $request, CandidatesHasServices $service): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
Throw new \Exception("Aucun CV");
}
if($service->getCandidate() != $candidate) {
Throw new \Exception("Mauvaise fiche");
}
return $this->render('themesWebsite/cvs/gestion/candidates/generate/services/remove.html.twig',[
'service' => $service
]);
}
/**
* Supprimer un service
* @param Request $request
* @param CandidatesHasExperiences $experience
* @return Response
* @throws \Exception
*/
public function servicesDelete(Request $request, CandidatesHasServices $service): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
Throw new \Exception("Aucun CV");
}
if($service->getCandidate() != $candidate) {
Throw new \Exception("Mauvaise fiche");
}
$this->em->remove($service);
$this->em->flush();
$session->getFlashBag()->add('success', 'Mise à jour des informations');
return $this->redirectToRoute('cvs_gestion_candidates_generate_services');
}
/**
* Mes expériences
* @param Request $request
* @return Response
* @throws \Exception
*/
public function step3(Request $request): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
Throw new \Exception("Aucun CV");
}
$services = $this->em->getRepository(CandidatesHasServices::class)->findBy(['candidate' => $candidate]);
/*
if($services == null) {
return $this->redirectToRoute('cvs_gestion_candidates_generate_services');
}*/
$exp = new CandidatesHasExperiences();
$exp->setCandidate($candidate);
$exp->setOnline(true);
$form = $this->createForm(ExperiencesForm::class, $exp);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->em->persist($exp);
$this->em->flush();
$session->getFlashBag()->add('success', 'Mise à jour des informations');
return $this->redirectToRoute('cvs_gestion_candidates_generate_step3');
}
$experiences = $this->em->getRepository(CandidatesHasExperiences::class)->findBy(['candidate' => $candidate],['start' => 'DESC']);
return $this->render('themesWebsite/cvs/gestion/candidates/generate/step3.html.twig',[
'form' => $form->createView(),
'experiences' => $experiences
]);
}
/**
* Modifier une expérience
* @param Request $request
* @param CandidatesHasExperiences $experience
* @return Response
* @throws \Exception
*/
public function step3Edit(Request $request, CandidatesHasExperiences $experience): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
Throw new \Exception("Aucun CV");
}
if($experience->getCandidate() != $candidate) {
Throw new \Exception("Mauvaise fiche");
}
$form = $this->createForm(ExperiencesForm::class, $experience);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->em->persist($experience);
$this->em->flush();
$session->getFlashBag()->add('success', 'Mise à jour des informations');
return $this->redirectToRoute('cvs_gestion_candidates_generate_step3');
}
return $this->render('themesWebsite/cvs/gestion/candidates/generate/step3_edit.html.twig',[
'form' => $form->createView(),
'experience' => $experience
]);
}
/**
* Confirmer la suppression d'une expérience
* @param Request $request
* @param CandidatesHasExperiences $experience
* @return Response
* @throws \Exception
*/
public function step3Remove(Request $request, CandidatesHasExperiences $experience): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
Throw new \Exception("Aucun CV");
}
if($experience->getCandidate() != $candidate) {
Throw new \Exception("Mauvaise fiche");
}
return $this->render('themesWebsite/cvs/gestion/candidates/generate/step3_remove.html.twig',[
'experience' => $experience
]);
}
/**
* Supprimer une expérience
* @param Request $request
* @param CandidatesHasExperiences $experience
* @return Response
* @throws \Exception
*/
public function step3Delete(Request $request, CandidatesHasExperiences $experience): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
Throw new \Exception("Aucun CV");
}
if($experience->getCandidate() != $candidate) {
Throw new \Exception("Mauvaise fiche");
}
$this->em->remove($experience);
$this->em->flush();
$session->getFlashBag()->add('success', 'Mise à jour des informations');
return $this->redirectToRoute('cvs_gestion_candidates_generate_step3');
}
/**
* Projets
* @param Request $request
* @return Response
* @throws \Exception
*/
public function step4(Request $request): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
Throw new \Exception("Aucun CV");
}
$experiences = $this->em->getRepository(CandidatesHasExperiences::class)->findBy(['candidate' => $candidate]);
/*
if($experiences == null) {
return $this->redirectToRoute('cvs_gestion_candidates_generate_step3');
}
*/
$project = new CandidatesHasProjects();
$project->setCandidate($candidate);
$project->setOnline(false);
$form = $this->createForm(ProjectsForm::class, $project);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->em->persist($project);
$this->em->flush();
$session->getFlashBag()->add('success', 'Mise à jour des informations');
return $this->redirectToRoute('cvs_gestion_candidates_generate_step4');
}
$projects = $this->em->getRepository(CandidatesHasProjects::class)->findBy(['candidate' => $candidate]);
return $this->render('themesWebsite/cvs/gestion/candidates/generate/step4.html.twig',[
'form' => $form->createView(),
'projects' => $projects
]);
}
/**
* Modifier une expérience
* @param Request $request
* @param CandidatesHasExperiences $experience
* @return Response
* @throws \Exception
*/
public function step4Edit(Request $request, CandidatesHasProjects $project): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
Throw new \Exception("Aucun CV");
}
if($project->getCandidate() != $candidate) {
Throw new \Exception("Mauvaise fiche");
}
$form = $this->createForm(ProjectsForm::class, $project);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->em->persist($project);
$this->em->flush();
$session->getFlashBag()->add('success', 'Mise à jour des informations');
return $this->redirectToRoute('cvs_gestion_candidates_generate_step4');
}
return $this->render('themesWebsite/cvs/gestion/candidates/generate/step4_edit.html.twig',[
'form' => $form->createView(),
'project' => $project
]);
}
/**
* Confirmer la suppresison d'une expérience
* @param Request $request
* @param CandidatesHasExperiences $experience
* @return Response
* @throws \Exception
*/
public function step4Remove(Request $request, CandidatesHasProjects $project): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
Throw new \Exception("Aucun CV");
}
if($project->getCandidate() != $candidate) {
Throw new \Exception("Mauvaise fiche");
}
return $this->render('themesWebsite/cvs/gestion/candidates/generate/step3_remove.html.twig',[
'project' => $project
]);
}
/**
* Supprimer une expérience
* @param Request $request
* @param CandidatesHasExperiences $experience
* @return Response
* @throws \Exception
*/
public function step4Delete(Request $request, CandidatesHasProjects $project): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
Throw new \Exception("Aucun CV");
}
if($project->getCandidate() != $candidate) {
Throw new \Exception("Mauvaise fiche");
}
$this->em->remove($project);
$this->em->flush();
$session->getFlashBag()->add('success', 'Mise à jour des informations');
return $this->redirectToRoute('cvs_gestion_candidates_generate_step4');
}
/**
* Mes compétences
* @param Request $request
* @return Response
* @throws \Exception
*/
public function skills(Request $request): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
Throw new \Exception("Aucun CV");
}
$skill = new CandidatesHasSkills();
$skill->setCandidate($candidate);
$skill->setFav(false);
$form = $this->createForm(SkillsForm::class, $skill);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->em->persist($skill);
$this->em->flush();
$session->getFlashBag()->add('success', 'Mise à jour des informations');
return $this->redirectToRoute('cvs_gestion_candidates_generate_skills');
}
$skills = $this->em->getRepository(CandidatesHasSkills::class)->findBy(['candidate' => $candidate]);
return $this->render('themesWebsite/cvs/gestion/candidates/generate/skills/list.html.twig',[
'form' => $form->createView(),
'skills' => $skills
]);
}
/**
* Supprimer une compétence
* @param Request $request
* @param CandidatesHasExperiences $experience
* @return Response
* @throws \Exception
*/
public function skillsEdit(Request $request, CandidatesHasSkills $skill): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
Throw new \Exception("Aucun CV");
}
if($skill->getCandidate() != $candidate) {
Throw new \Exception("Mauvaise fiche");
}
$form = $this->createForm(SkillsForm::class, $skill);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->em->persist($skill);
$this->em->flush();
$session->getFlashBag()->add('success', 'Mise à jour des informations');
return $this->redirectToRoute('cvs_gestion_candidates_generate_skills');
}
return $this->render('themesWebsite/cvs/gestion/candidates/generate/skills/edit.html.twig',[
'form' => $form->createView(),
'skill' => $skill
]);
}
/**
* Supprimer une compétence
* @param Request $request
* @param CandidatesHasExperiences $experience
* @return Response
* @throws \Exception
*/
public function skillsRemove(Request $request, CandidatesHasSkills $skill): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
Throw new \Exception("Aucun CV");
}
if($skill->getCandidate() != $candidate) {
Throw new \Exception("Mauvaise fiche");
}
return $this->render('themesWebsite/cvs/gestion/candidates/generate/skills/remove.html.twig',[
'skill' => $skill
]);
}
/**
* Supprimer une compétence
* @param Request $request
* @param CandidatesHasExperiences $experience
* @return Response
* @throws \Exception
*/
public function skillsDelete(Request $request, CandidatesHasSkills $skill): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
Throw new \Exception("Aucun CV");
}
if($skill->getCandidate() != $candidate) {
Throw new \Exception("Mauvaise fiche");
}
$this->em->remove($skill);
$this->em->flush();
$session->getFlashBag()->add('success', 'Mise à jour des informations');
return $this->redirectToRoute('cvs_gestion_candidates_generate_skills');
}
/**
* Réglages
* @param Request $request
* @return Response
* @throws \Exception
*/
public function step5(Request $request): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
Throw new \Exception("Aucun CV");
}
$projects = $this->em->getRepository(CandidatesHasProjects::class)->findBy(['candidate' => $candidate]);
/*
if($projects == null) {
return $this->redirectToRoute('cvs_gestion_candidates_generate_skills');
}*/
$form = $this->createForm(CandidatesSettingsForm::class, $candidate);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $request->request->all();
$this->em->persist($candidate);
$this->em->flush();
$session->getFlashBag()->add('success', 'Mise à jour des informations');
if($data['submit'] == "0") {
return $this->redirectToRoute('cvs_gestion_candidates_generate_step4');
}
return $this->redirectToRoute('cvs_gestion_candidates_generate_validation');
}
$projects = $this->em->getRepository(CandidatesHasProjects::class)->findBy(['candidate' => $candidate]);
return $this->render('themesWebsite/cvs/gestion/candidates/generate/step5.html.twig',[
'form' => $form->createView(),
'projects' => $projects
]);
}
/**
* Valider le profil + valider l'invitation de l'inscription..
* @param Request $request
* @return Response
* @throws \Exception
*/
public function validation(Request $request, Users $us): Response
{
$session = $request->getSession();
$session->set("navbar-section","dashboard");
$session->set("sidebar-section","generate");
$user = $this->getUser();
if($user == null) {
Throw new \Exception("Aucun utilisateur");
}
$candidate = $user->getCandidate();
if($candidate == null) {
Throw new \Exception("Aucun CV");
}
if(empty($candidate->getSlug())) {
$slug = $us->getUniqueCvSlug(10);
$candidate->setSlug($slug);
}
if(empty($candidate->getSlugAnonyme())) {
$slug = $us->getUniqueCvAnonymeSlug(10);
$candidate->setSlugAnonyme($slug);
}
if(empty($candidate->getInvitationCode())) {
$code = $us->getUniqueCvInvitationCode(15);
$candidate->setInvitationCode($code);
}
if(empty($candidate->getInvitationCodeAnonyme())) {
$code = $us->getUniqueCvInvitationCodeAnonyme(15);
$candidate->setInvitationcodeAnonyme($code);
}
$candidate->setFirst(false);
$this->em->persist($candidate);
$this->em->flush();
$shareInvitation = $user->getShare();
if($shareInvitation !== null) {
$agencyTarget = $shareInvitation->getAgencyTarget();
$userTarget = $shareInvitation->getUserTarget();
$invitation = $this->em->getRepository(Invitations::class)->findOneBy(['user' => $user]);
if($invitation === null) {
$invitation = new Invitations();
$invitation->setEmail(null);
$invitation->setAgency(null);
$invitation->setUser($user); // Candidat.
$invitation->setAgencyTarget($agencyTarget); // Entreprise.
$invitation->setUserTarget($userTarget); // Entreprise utilisateur.
$invitation->setUserView(true);
$invitation->setAgencyView(false);
$this->em->persist($invitation);
$this->em->flush();
if($userTarget !== null) {
$history = $this->em->getRepository(History::class)->findOneBy(['user' => $user, 'userTarget' => $userTarget, 'anonyme' => true]);
if($history === null) {
$history = new History();
$history->setAnonyme(true);
$history->setAccepted(false);
$history->setRefused(false);
$history->setUser($user);
$history->setUserTarget($userTarget);
$history->setAgencyTarget($agencyTarget);
$this->em->persist($history);
$this->em->flush();
}
// Envoyer un mail !
$this->sendEmailAnonyme($userTarget->getEmail(),$candidate->getSlugAnonyme());
}
}
}
return $this->redirectToRoute('cvs_gestion_candidates_dashboard');
}
/**
* Envoyer un CV anonyme d'une invitation directement.
* @param $emailTarget
* @param $slugAnonyme
* @return true|null
*/
private function sendEmailAnonyme($emailTarget,$slugAnonyme)
{
$templateMail = $this->em->getRepository(Mails::class)->findOneBy(['name' => "new_cv_anonyme"]);
if($templateMail == null) {
return null;
}
$subject = $templateMail->getTitle();
$description = $templateMail->getDescription();
$pathCV = (string)$this->generateUrl('cvs_application_cv_anonyme', ['slug' => $slugAnonyme], UrlGeneratorInterface::ABSOLUTE_URL);
$searchHTML = ['%EMAIL%','%PATH_CV%','%SLUG%'];
$replaceHTML = [$emailTarget,$pathCV,$slugAnonyme];
$cleanSubject = str_replace($searchHTML, $replaceHTML, $subject);
$cleanDescription = str_replace($searchHTML, $replaceHTML, $description);
$this->ms->register($cleanSubject,$cleanDescription,null,$emailTarget,null,null);
return true;
}
}