src/Controller/ThemesWebsite/Whileresume/Application/JobsController.php line 123

Open in your IDE?
  1. <?php
  2. namespace App\Controller\ThemesWebsite\Whileresume\Application;
  3. use App\Entity\Core\Users;
  4. use App\Entity\Cvs\Candidates;
  5. use App\Entity\Cvs\CandidatesHasExperiences;
  6. use App\Entity\Cvs\CandidatesHasProjects;
  7. use App\Entity\Cvs\CandidatesHasServices;
  8. use App\Entity\Cvs\CandidatesHasSkills;
  9. use App\Entity\Cvs\Jobs;
  10. use App\Entity\Cvs\JobsHasLikes;
  11. use App\Form\Core\UsersType;
  12. use App\Form\Cvs\JobsForm;
  13. use App\Form\Cvs\JobsFrForm;
  14. use App\Services\Core\RequestData;
  15. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
  16. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  17. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  18. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  19. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\HttpFoundation\Response;
  22. use Symfony\Component\Routing\Annotation\Route;
  23. use Symfony\Component\HttpFoundation\Cookie;
  24. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  25. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  26. use Doctrine\ORM\EntityManagerInterface;
  27. class JobsController extends AbstractController
  28. {
  29.     private $rd;
  30.     private $em;
  31.     public function __construct(RequestData $rd,
  32.                                 EntityManagerInterface $em
  33.     ) {
  34.         $this->rd $rd;
  35.         $this->em $em;
  36.     }
  37.     public function new(Request $request): Response
  38.     {
  39.         $locale $request->getLocale();
  40.         $user $this->getUser();
  41.         $jobClass JobsForm::class;
  42.         if($locale == "fr") {
  43.             $jobClass JobsFrForm::class;
  44.         }
  45.         $job = new Jobs();
  46.         $form $this->createForm($jobClass$job);
  47.         $form->handleRequest($request);
  48.         if ($form->isSubmitted() && $form->isValid()) {
  49.             $job->setSlug("0");
  50.             $job->setLocale($locale);
  51.             $job->setValidation(false);
  52.             $job->setVerification(false);
  53.             $job->setOnline(false);
  54.             $job->setEnterprise(null);
  55.             $job->setUser($user);
  56.             $this->em->persist($job);
  57.             $this->em->flush();
  58.             if($job->getSlug() != "0") {
  59.                 $job->setSlug($this->generateSlug($job->getId()));
  60.                 $this->em->persist($job);
  61.                 $this->em->flush();
  62.             }
  63.             if($locale !== "en") {
  64.                 return $this->redirectToRoute('locale_cvs_application_job_new_confirm',['_locale' => $locale]);
  65.             }
  66.             return $this->redirectToRoute('cvs_application_job_new_confirm');
  67.         }
  68.         return $this->render('application/whileresume/application/jobs/new_'.$locale.'.html.twig',[
  69.             'form' => $form->createView(),
  70.         ]);
  71.     }
  72.     private function generateSlug(int $id): string
  73.     {
  74.         $letters 'abcdefghijklmnopqrstuvwxyz';
  75.         $random '';
  76.         for ($i 0$i 6$i++) {
  77.             $random .= $letters[random_int(025)];
  78.         }
  79.         return $random '-' $id;
  80.     }
  81.     public function show(Request $request$slug): Response
  82.     {
  83.         $locale $request->getLocale();
  84.         $job $this->em->getRepository(Jobs::class)->findOneBy(['locale' => $locale'slug' => $slug'online' => true'validation' => true]);
  85.         if($job === null) {
  86.             throw $this->createNotFoundException('Page non trouvée');
  87.         }
  88.         $othersJobs null;
  89.         if($job->getEnterprise() != null) {
  90.             $othersJobs $this->em->getRepository(Jobs::class)->findBy(['enterprise' => $job->getEnterprise(), 'online' => true]);
  91.         }
  92.         // Offres similaires basées sur catégorie, compétences, ville, titre
  93.         $similarJobs $this->em->getRepository(Jobs::class)->findSimilarJobs($job5);
  94.         $count 0;
  95.         if($job->getViews() != null) {
  96.             $count $job->getViews() + 1;
  97.         }
  98.         $job->setViews($count);
  99.         $this->em->persist($job);
  100.         $this->em->flush();
  101.         return $this->render('application/whileresume/application/jobs/show_'.$locale.'.html.twig',[
  102.             'slug' => $slug,
  103.             'job' =>  $job,
  104.             'othersJobs' => $othersJobs,
  105.             'similarJobs' => $similarJobs
  106.         ]);
  107.     }
  108.     public function likeJob(Request $request$slug): Response
  109.     {
  110.         $locale $request->getLocale();
  111.         $user $this->getUser();
  112.         if($user == null) {
  113.             if($locale != "en") {
  114.                 return $this->redirectToRoute('locale_cvs_gestion_candidates_dashboard',['_locale' => $locale]);
  115.             }
  116.             return $this->redirectToRoute('cvs_gestion_candidates_dashboard');
  117.         }
  118.         $candidate  $user->getCandidate();
  119.         $job $this->em->getRepository(Jobs::class)->findOneBy(['slug' => $slug]);
  120.         $jhl $this->em->getRepository(JobsHasLikes::class)->findOneBy(['candidate' => $candidate'job' => $job]);
  121.         if($jhl == null) {
  122.             $jhl = new JobsHasLikes();
  123.             $jhl->setJob($job);
  124.             $jhl->setCandidate($candidate);
  125.             $jhl->setCreatedAt(new \DateTime("now"));
  126.             $jhl->setUpdatedAt(new \DateTime("now"));
  127.             $this->em->persist($jhl);
  128.             $this->em->flush();
  129.         }
  130.         if($locale != "en") {
  131.             return $this->redirectToRoute('locale_cvs_gestion_candidates_dashboard',['_locale' => $locale]);
  132.         }
  133.         return $this->redirectToRoute('cvs_gestion_candidates_dashboard');
  134.     }
  135. }