<?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\FrontRelictPackRepository;
use Symfony\Component\Intl\Locales;
/**
* PageController
*
* @author Daniel Balowski <d.balowski@openform.pl> (_creator)
* @copyright 2019 Openform
* @since 07.2019
*/
class RelictPackController extends BaseController
{
protected $routeLocalizer;
private $em;
private $relictPackRepo;
private $pageRepo;
public function __construct(RequestStack $request, RouteLocalizer $routeLocalizer, EntityManagerInterface $em)
{
parent::__construct($request, $routeLocalizer, $em);
$this->em = $em;
$this->routeLocalizer = $routeLocalizer;
$this->relictPackRepo = $this->em->getRepository('Openform:RelictPack')->getFrontRepository();
$this->pageRepo = $this->em->getRepository('Openform:Page')->getFrontRepository();
}
public function itemAction(Request $request, string $slug)
{
$locale = $request->getLocale();
$repo = $this->em->getRepository('Openform:RelictPack')->getFrontRepository();
$entity = $repo->getVisibleBySlug($slug, $locale);
if (!$entity) {
throw new NotFoundHttpException();
}
$rootParent = \App\Package\Openform\Entity\RelictPack::getRootParent($entity);
$request->attributes->set('makSlug', $rootParent->getMakSlug($locale));
return $this->render('@openform_front_templates/RelictPack/item.html.twig', [
'entity' => $entity,
'parentPage' => $entity->getParent(),
'rootParent' => $rootParent
]);
}
public function relictItemAction(Request $request, string $slug)
{
$locale = $request->getLocale();
$repo = $this->em->getRepository('Openform:Relict')->getFrontRepository();
$entity = $repo->getVisibleBySlug($slug, $locale);
if (!$entity) {
throw new NotFoundHttpException();
}
$rootParent = \App\Package\Openform\Entity\RelictPack::getRootParent($entity->getRelictPack());
$request->attributes->set('makSlug', $rootParent->getMakSlug($locale));
return $this->render('@openform_front_templates/RelictPack/relict_item.html.twig', [
'entity' => $entity,
'parentPage' => $entity->getRelictPack(),
'rootParent' => $rootParent
]);
}
}