<?php
namespace App\Controller\ThemesWebsite\Cvs\Application;
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\Services\Core\RequestData;
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;
class CvController extends AbstractController
{
private $rd;
private $em;
public function __construct(RequestData $rd,
EntityManagerInterface $em
) {
$this->rd = $rd;
$this->em = $em;
}
/**
* CV non anonyme
* @param Request $request
* @param $slug
* @return Response
* @throws \Exception
*/
public function classic(Request $request, $slug): Response
{
$candidate = $this->em->getRepository(Candidates::class)->findOneBy(['slug' => $slug]);
if($candidate == null) {
return $this->render('themesWebsite/cvs/application/cv/offline.html.twig',[
'slug' => $slug,
'candidate' => $candidate
]);
}
if($candidate->getOnlineClassic() !== true) {
return $this->render('themesWebsite/cvs/application/cv/offline.html.twig',[
'slug' => $slug,
'candidate' => $candidate
]);
}
$services = $this->em->getRepository(CandidatesHasServices::class)->findBy(['candidate' => $candidate->getId()],['title' => 'ASC']);
$skills = $this->em->getRepository(CandidatesHasSkills::class)->findBy(['candidate' => $candidate->getId()],['title' => 'ASC']);
$projects = $this->em->getRepository(CandidatesHasProjects::class)->findBy(['candidate' => $candidate->getId()],['title' => 'ASC']);
$experiences = $this->em->getRepository(CandidatesHasExperiences::class)->findBy(['candidate' => $candidate->getId()],['start' => 'DESC']);
$views = (int)$candidate->getViews();
$candidate->setViews($views+1);
$this->em->persist($candidate);
$this->em->flush();
return $this->render('themesWebsite/cvs/application/cv/classic.html.twig',[
'slug' => $slug,
'candidate' => $candidate,
'services' => $services,
'skills' => $skills,
'projects' => $projects,
'experiences' => $experiences
]);
}
/**
* CV anonyme
* @param Request $request
* @param $slug
* @return Response
* @throws \Exception
*/
public function anonyme(Request $request, $slug): Response
{
$candidate = $this->em->getRepository(Candidates::class)->findOneBy(['slugAnonyme' => $slug]);
if($candidate == null) {
return $this->render('themesWebsite/cvs/application/cv/offline.html.twig',[
'slug' => $slug,
'candidate' => $candidate
]);
}
if($candidate->getOnline() !== true) {
return $this->render('themesWebsite/cvs/application/cv/offline.html.twig',[
'slug' => $slug,
'candidate' => $candidate
]);
}
$services = $this->em->getRepository(CandidatesHasServices::class)->findBy(['candidate' => $candidate->getId()],['title' => 'ASC']);
$skills = $this->em->getRepository(CandidatesHasSkills::class)->findBy(['candidate' => $candidate->getId()],['title' => 'ASC']);
$projects = $this->em->getRepository(CandidatesHasProjects::class)->findBy(['candidate' => $candidate->getId()],['title' => 'ASC']);
$experiences = $this->em->getRepository(CandidatesHasExperiences::class)->findBy(['candidate' => $candidate->getId()],['start' => 'DESC']);
$views = (int)$candidate->getViewsAnonyme();
$candidate->setViewsAnonyme($views+1);
$this->em->persist($candidate);
$this->em->flush();
return $this->render('themesWebsite/cvs/application/cv/anonyme.html.twig',[
'slug' => $slug,
'candidate' => $candidate,
'services' => $services,
'skills' => $skills,
'projects' => $projects,
'experiences' => $experiences
]);
}
}