src/Package/Openform/Front/Controller/AntiqueSuitController.php line 63

Open in your IDE?
  1. <?php
  2. namespace App\Package\Openform\Front\Controller;
  3. use Doctrine\ORM\EntityManager;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Symfony\Component\HttpFoundation\RequestStack;
  9. use App\Package\Openform\Front\Controller\BaseController;
  10. use App\Package\Toolkit\RouteLocalizer\RouteLocalizer;
  11. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  12. use App\Package\Openform\RepositoryFront\FrontAntiqueSuitRepository;
  13. use Symfony\Component\Intl\Locales;
  14. /**
  15.  * PageController
  16.  *
  17.  * @author     Daniel Balowski <d.balowski@openform.pl> (_creator)
  18.  * @copyright  2019 Openform
  19.  * @since      07.2019
  20.  */
  21. class AntiqueSuitController extends BaseController
  22. {
  23.     protected $routeLocalizer
  24.     private $em
  25.     private $antiqueSuitRepo
  26.     private $pageRepo
  27.     public function __construct(RequestStack $requestRouteLocalizer $routeLocalizerEntityManagerInterface $em)
  28.     {
  29.         parent::__construct($request$routeLocalizer$em);
  30.         
  31.         $this->em $em;
  32.         $this->routeLocalizer $routeLocalizer;
  33.         $this->antiqueSuitRepo $this->em->getRepository('Openform:AntiqueSuit')->getFrontRepository();
  34.         $this->pageRepo $this->em->getRepository('Openform:Page')->getFrontRepository();
  35.     }    
  36.     public function itemAction(Request $requeststring $slug)
  37.     {
  38.         $locale $request->getLocale();
  39.         $repo $this->em->getRepository('Openform:AntiqueSuit')->getFrontRepository();
  40.         $entity $repo->getVisibleBySlug($slug$locale);
  41.         if (!$entity) {
  42.             throw new NotFoundHttpException();
  43.         }
  44.         
  45.         $rootParent \App\Package\Openform\Entity\AntiqueSuit::getRootParent($entity);
  46.         $request->attributes->set('makSlug'$rootParent->getMakSlug($locale));
  47.         
  48.         return $this->render('@openform_front_templates/AntiqueSuit/item.html.twig', [
  49.             'entity' => $entity,
  50.             'parentPage' => $entity->getParent(),
  51.             'rootParent' => $rootParent
  52.         ]);
  53.     }
  54.     
  55.     public function antiqueItemAction(Request $requeststring $slug)
  56.     {
  57.         $locale $request->getLocale();
  58.         $repo $this->em->getRepository('Openform:Antique')->getFrontRepository();
  59.         $entity $repo->getVisibleBySlug($slug$locale);
  60.         if (!$entity) {
  61.             throw new NotFoundHttpException();
  62.         }
  63.         $rootParent \App\Package\Openform\Entity\AntiqueSuit::getRootParent($entity->getAntiqueSuit());
  64.         $request->attributes->set('makSlug'$rootParent->getMakSlug($locale));
  65.         
  66.         return $this->render('@openform_front_templates/AntiqueSuit/antique_item.html.twig', [
  67.             'entity' => $entity,
  68.             'parentPage' => $entity->getAntiqueSuit(),
  69.             'rootParent' => $rootParent
  70.         ]);
  71.     }
  72.     
  73.     protected function generateLangLinksAntiqueSuit$entity)
  74.     {
  75.         $repo $this->em->getRepository('Openform:AntiqueSuitTranslation');
  76.         
  77.         $translations $repo->findBy(['translatableId' => $entity->getId()]);
  78.         $langLinks = [];
  79.         foreach ($translations as $transItem){
  80.             if (strlen($transItem->getSlug()) > 0) {
  81.                 
  82.                 
  83.                 $url $this->routeLocalizer->generate('antique_suit_item', ['slug' => $transItem->getSlug()], $transItem->getLang());
  84.                 
  85.                 $langLinks[$transItem->getLang()] = $url;
  86.             }
  87.         }
  88.         return $langLinks;        
  89.     }
  90.     protected function generateLangLinksAntique$entity)
  91.     {
  92.         $repo $this->em->getRepository('Openform:AntiqueTranslation');
  93.         
  94.         $translations $repo->findBy(['translatableId' => $entity->getId()]);
  95.         $langLinks = [];
  96.         foreach ($translations as $transItem){
  97.             if (strlen($transItem->getSlug()) > 0) {
  98.                 
  99.                 
  100.                 $url $this->routeLocalizer->generate('antique_item', ['slug' => $transItem->getSlug()], $transItem->getLang());
  101.                 
  102.                 $langLinks[$transItem->getLang()] = $url;
  103.             }
  104.         }
  105.         return $langLinks;        
  106.     }
  107. }