<?php
namespace App\Package\Openform\Front\Controller;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RequestStack;
use App\Package\Openform\Front\Controller\BaseController;
use App\Package\Toolkit\RouteLocalizer\RouteLocalizer;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use App\Package\Openform\RepositoryFront\FrontAntiqueSuitRepository;
use Symfony\Component\Intl\Locales;
/**
* PageController
*
* @author Daniel Balowski <d.balowski@openform.pl> (_creator)
* @copyright 2019 Openform
* @since 07.2019
*/
class AntiqueSuitController extends BaseController
{
protected $routeLocalizer;
private $em;
private $antiqueSuitRepo;
private $pageRepo;
public function __construct(RequestStack $request, RouteLocalizer $routeLocalizer, EntityManagerInterface $em)
{
parent::__construct($request, $routeLocalizer, $em);
$this->em = $em;
$this->routeLocalizer = $routeLocalizer;
$this->antiqueSuitRepo = $this->em->getRepository('Openform:AntiqueSuit')->getFrontRepository();
$this->pageRepo = $this->em->getRepository('Openform:Page')->getFrontRepository();
}
public function itemAction(Request $request, string $slug)
{
$locale = $request->getLocale();
$repo = $this->em->getRepository('Openform:AntiqueSuit')->getFrontRepository();
$entity = $repo->getVisibleBySlug($slug, $locale);
if (!$entity) {
throw new NotFoundHttpException();
}
$rootParent = \App\Package\Openform\Entity\AntiqueSuit::getRootParent($entity);
$request->attributes->set('makSlug', $rootParent->getMakSlug($locale));
return $this->render('@openform_front_templates/AntiqueSuit/item.html.twig', [
'entity' => $entity,
'parentPage' => $entity->getParent(),
'rootParent' => $rootParent
]);
}
public function antiqueItemAction(Request $request, string $slug)
{
$locale = $request->getLocale();
$repo = $this->em->getRepository('Openform:Antique')->getFrontRepository();
$entity = $repo->getVisibleBySlug($slug, $locale);
if (!$entity) {
throw new NotFoundHttpException();
}
$rootParent = \App\Package\Openform\Entity\AntiqueSuit::getRootParent($entity->getAntiqueSuit());
$request->attributes->set('makSlug', $rootParent->getMakSlug($locale));
return $this->render('@openform_front_templates/AntiqueSuit/antique_item.html.twig', [
'entity' => $entity,
'parentPage' => $entity->getAntiqueSuit(),
'rootParent' => $rootParent
]);
}
protected function generateLangLinksAntiqueSuit( $entity)
{
$repo = $this->em->getRepository('Openform:AntiqueSuitTranslation');
$translations = $repo->findBy(['translatableId' => $entity->getId()]);
$langLinks = [];
foreach ($translations as $transItem){
if (strlen($transItem->getSlug()) > 0) {
$url = $this->routeLocalizer->generate('antique_suit_item', ['slug' => $transItem->getSlug()], $transItem->getLang());
$langLinks[$transItem->getLang()] = $url;
}
}
return $langLinks;
}
protected function generateLangLinksAntique( $entity)
{
$repo = $this->em->getRepository('Openform:AntiqueTranslation');
$translations = $repo->findBy(['translatableId' => $entity->getId()]);
$langLinks = [];
foreach ($translations as $transItem){
if (strlen($transItem->getSlug()) > 0) {
$url = $this->routeLocalizer->generate('antique_item', ['slug' => $transItem->getSlug()], $transItem->getLang());
$langLinks[$transItem->getLang()] = $url;
}
}
return $langLinks;
}
}