<?phpnamespace App\Controller\ThemesWebsite\Whileresume\GestionCandidates;use App\Entity\Core\Notifications;use App\Entity\Cvs\Candidates;use App\Form\Cvs\CandidatesSettingsForm;use App\Form\Cvs\CandidatesStep0Form;use App\Form\Cvs\CandidatesStep1Form;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;use Symfony\Component\HttpFoundation\BinaryFileResponse;use Symfony\Component\HttpFoundation\ResponseHeaderBag;use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;use Vich\UploaderBundle\Storage\StorageInterface;use Symfony\Component\Form\Extension\Core\Type\CheckboxType;use Symfony\Component\Form\Extension\Core\Type\HiddenType;/** * Générateur de CV */class GenerateController extends AbstractController{ private $rd; private $em; private $ms; private $storage; public function __construct(RequestData $rd, EntityManagerInterface $em, \App\Services\Mails $ms, StorageInterface $storage ) { $this->rd = $rd; $this->em = $em; $this->ms = $ms; $this->storage = $storage; } /** * Visualisation du PDF. * @param Request $request * @return BinaryFileResponse * @throws \Exception */ public function previewPdf(Request $request) { $session = $request->getSession(); $session->set("navbar-section", "dashboard"); $session->set("sidebar-section", "dashboard"); $user = $this->getUser(); if ($user == null) { throw new \Exception("Aucun utilisateur"); } $candidate = $user->getCandidate(); $filePath = $this->storage->resolvePath($candidate, 'imageFile'); if (!$filePath || !file_exists($filePath)) { throw $this->createNotFoundException('Fichier PDF introuvable sur le serveur'); } $response = new BinaryFileResponse($filePath); // INLINE pour affichage dans le navigateur/iframe $response->setContentDisposition( ResponseHeaderBag::DISPOSITION_INLINE ); // Headers nécessaires $response->headers->set('Content-Type', 'application/pdf'); $response->headers->set('X-Frame-Options', 'SAMEORIGIN'); return $response; } /** * Première étape. * @param Request $request * @return Response * @throws \Exception */ public function first(Request $request, Users $us): Response { $session = $request->getSession(); $session->set("navbar-section", "dashboard"); $session->set("sidebar-section", "generate"); $locale = $request->getLocale(); $user = $this->getUser(); if ($user == null) { throw new \Exception("Aucun utilisateur"); } $candidate = $user->getCandidate(); if ($candidate == null) { $candidate = new Candidates(); $candidate->setSalary(true); $candidate->setFrench(true); $candidate->setEnglish(true); $candidate->setEmail($user->getEmail()); $candidate->setFirst(true); $this->em->persist($candidate); $this->em->flush(); $user->setCandidate($candidate); $this->em->persist($user); $this->em->flush(); } 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); } $form = $this->createForm(CandidatesStep0Form::class, $candidate); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $data = $request->request->all(); $data = $data['candidates_step0_form']; $user->setName($data['name']); $user->setLastname($data['lastname']); $this->em->persist($user); $this->em->flush(); $newFileUploaded = $candidate->getImageFile() !== null; if ($newFileUploaded) { $pathPython = $_ENV["PYTHON_PATH"]; $pathPythonScript = $_ENV["PYTHON_SCRIPT_PATH"]; $candidate->setAnalyse(false); $this->em->persist($candidate); $this->em->flush(); $cvID = $candidate->getId(); $command = escapeshellcmd($pathPython . " " . $pathPythonScript . " " . $cvID); shell_exec($command . " > /dev/null 2>/dev/null &"); if ($locale != "en") { return $this->redirectToRoute('locale_cvs_gestion_candidates_generate_analyse', ['_locale' => $locale]); } return $this->redirectToRoute('cvs_gestion_candidates_generate_analyse'); } else { if ($locale != "en") { return $this->redirectToRoute('locale_cvs_gestion_candidates_generate_about', ['_locale' => $locale]); } return $this->redirectToRoute('cvs_gestion_candidates_generate_about'); } } return $this->render('application/whileresume/gestion/candidates/generate/first.html.twig', [ 'form' => $form->createView(), 'candidate' => $candidate, ]); } /** * Analyse en cours. * @param Request $request * @return Response * @throws \Exception */ public function analyse(Request $request): Response { $session = $request->getSession(); $session->set("navbar-section", "dashboard"); $session->set("sidebar-section", "generate"); $locale = $request->getLocale(); $user = $this->getUser(); if ($user == null) { throw new \Exception("Aucun utilisateur"); } $candidate = $user->getCandidate(); return $this->render('application/whileresume/gestion/candidates/generate/analyse.html.twig', [ 'candidate' => $candidate ]); } /** * Retourne si c'est en cours d'analyse. * @param Request $request * @return Response */ public function analyseWaiting(Request $request): Response { $session = $request->getSession(); $user = $this->getUser(); if ($user == null) { return new JsonResponse(false); } $candidate = $user->getCandidate(); if ($candidate->getAnalyse() == null) { return new JsonResponse(false); } if ($candidate->getAnalyse() == true) { return new JsonResponse(true); } return new JsonResponse(false); } /** * Informations sur le CV * @param Request $request * @return Response * @throws \Exception */ public function about(Request $request): Response { $session = $request->getSession(); $session->set("navbar-section", "dashboard"); $session->set("sidebar-section", "generate"); $locale = $request->getLocale(); $user = $this->getUser(); if ($user == null) { throw new \Exception("Aucun utilisateur"); } $candidate = $user->getCandidate(); if($candidate->getDefaultLocale() != "fr" and $candidate->getDefaultLocale() != "en") { $candidate->setDefault(true); } else { $candidate->setDefault(false); } if($candidate->getDefaultLocale() == "fr") { $candidate->setFrench(true); } if($candidate->getDefaultLocale() == "en") { $candidate->setEnglish(true); } $this->em->persist($candidate); $this->em->flush(); $form = $this->createForm(CandidatesStep1Form::class, $candidate); if($candidate->getDefaultLocale() == "fr") { $form->add('french', HiddenType::class); } if($candidate->getDefaultLocale() == "fr") { $form->add('french', HiddenType::class); } else { $form->add('french', CheckboxType::class, [ 'required' => false, 'error_bubbling' => true, 'label' => 'FR', 'attr' => ['class' => ''], 'label_attr' => ['class' => 'form-label'] ]); } if($candidate->getDefaultLocale() == "en") { $form->add('english', HiddenType::class); } else { $form->add('english', CheckboxType::class, [ 'required' => false, 'error_bubbling' => true, 'label' => 'EN', 'attr' => ['class' => ''], 'label_attr' => ['class' => 'form-label'] ]); } $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $data = $request->request->all(); $candidate->setPointX(null); $candidate->setPointY(null); $this->em->persist($candidate); $this->em->flush(); $session->getFlashBag()->add('success', 'Mise à jour des informations'); if ($data['submit'] == "0") { if ($locale != "en") { return $this->redirectToRoute('locale_cvs_gestion_candidates_generate_first', ['_locale' => $locale]); } return $this->redirectToRoute('cvs_gestion_candidates_generate_first'); } if ($locale != "en") { return $this->redirectToRoute('locale_cvs_gestion_candidates_generate_publish', ['_locale' => $locale]); } return $this->redirectToRoute('cvs_gestion_candidates_generate_publish'); } return $this->render('application/whileresume/gestion/candidates/generate/about.html.twig', [ 'form' => $form->createView(), 'candidate' => $candidate ]); } /** * Publier le CV * @param Request $request * @return Response * @throws \Exception */ public function publish(Request $request): Response { $session = $request->getSession(); $session->set("navbar-section", "dashboard"); $session->set("sidebar-section", "generate"); $user = $this->getUser(); $locale = $request->getLocale(); if ($user == null) { throw new \Exception("Aucun utilisateur"); } $candidate = $user->getCandidate(); if ($candidate == null) { throw new \Exception("Aucun CV"); } $form = $this->createForm(CandidatesSettingsForm::class, $candidate); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $data = $request->request->all(); if ($data['submit'] == "0") { if ($locale != "en") { $session->getFlashBag()->add('success', 'Mise à jour du CV'); return $this->redirectToRoute('locale_cvs_gestion_candidates_generate_about', ['_locale' => $locale]); } $session->getFlashBag()->add('success', 'Resume updated'); return $this->redirectToRoute('cvs_gestion_candidates_generate_about'); } $candidate->setOnline(true); $candidate->setAvailability("open"); $this->em->persist($candidate); $this->em->flush(); $user->setFirst(false); $this->em->persist($user); $this->em->flush(); $notification = new Notifications(); $notification->setViewed(false); $notification->setOnlyAdmin(false); $notification->setType("default"); if ($locale == "fr") { $notification->setDescription("Publication de votre CV"); } else { $notification->setDescription("Resume published"); } $notification->setUser($user); $this->em->persist($notification); $this->em->flush(); if ($locale != "en") { $session->getFlashBag()->add('success', 'CV publié'); return $this->redirectToRoute('locale_cvs_gestion_candidates_dashboard', ['_locale' => $locale]); } $session->getFlashBag()->add('success', 'Resume published'); return $this->redirectToRoute('cvs_gestion_candidates_dashboard'); } return $this->render('application/whileresume/gestion/candidates/generate/publish.html.twig', [ 'form' => $form->createView(), 'candidate' => $candidate ]); }}