vendor/boldr/jobs-bundle/src/Controller/JobOfferController.php line 27

Open in your IDE?
  1. <?php
  2. namespace Boldr\Cms\JobsBundle\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Component\HttpFoundation\{ RequestResponse };
  6. use Boldr\Cms\CmsBundle\Permalink\{ PermalinkableInterfacePermalinkResolverInterfacePermalinkGeneratorInterfacePermalinkHandlerInterface };
  7. use Boldr\Cms\JobsBundle\Entity\JobOffer;
  8. use Boldr\Cms\JobsBundle\Presenter\JobOfferPresenterInterface;
  9. class JobOfferController extends AbstractController implements PermalinkResolverInterfacePermalinkGeneratorInterfacePermalinkHandlerInterface
  10. {
  11.     public static function getSubscribedServices(): array
  12.     {
  13.         return array_merge(parent::getSubscribedServices(), [
  14.             JobOfferPresenterInterface::class
  15.         ]);
  16.     }
  17.     public function handlePermalink(PermalinkableInterface $permalinkableRequest $request): Response
  18.     {
  19.         $jobOfferView $this->container->get(JobOfferPresenterInterface::class)->createJobOfferView($permalinkablefalse$request->getLocale());
  20.         return $this->render('@BoldrJobs/job-offer.html.twig', [
  21.             'jobOffer' => $jobOfferView,
  22.             'assets' => $jobOfferView->getAssets()
  23.         ]);
  24.     }
  25.     public function resolvePermalink(string $permalinkstring $locale): ?PermalinkableInterface
  26.     {
  27.         $jobOfferRepository $this->getDoctrine()->getRepository(JobOffer::class);
  28.         $jobOffer $jobOfferRepository->createQueryBuilder('j')
  29.             ->leftJoin('j.translations''t')
  30.             ->where('t.locale = ?1 AND t.permalink = ?2 AND j.enabled = true')
  31.             ->setParameter(1$locale)
  32.             ->setParameter(2$permalink)
  33.             ->getQuery()
  34.             ->setMaxResults(1)
  35.             ->getOneOrNullResult();
  36.         return $jobOffer;
  37.     }
  38.     public function generatePermalink(PermalinkableInterface $permalinkablestring $locale): string
  39.     {
  40.         if (!($permalinkable instanceof JobOffer))
  41.             throw new \Exception();
  42.         return $permalinkable->getTranslations()->get($locale)->getPermalink();
  43.     }
  44. }