<?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\FrontExhibitionRepository;
use Symfony\Component\Intl\Locales;
/**
* PageController
*
* @author Daniel Balowski <d.balowski@openform.pl> (_creator)
* @copyright 2019 Openform
* @since 07.2019
*/
class CollectionsController extends BaseController
{
protected $routeLocalizer;
private $em;
public function __construct(RequestStack $request, RouteLocalizer $routeLocalizer, EntityManagerInterface $em)
{
parent::__construct($request, $routeLocalizer, $em);
$this->em = $em;
$this->routeLocalizer = $routeLocalizer;
}
public function indexAction(Request $request)
{
$locale = $request->getLocale();
$entity = $this->getPageByIdName('page_collections', $locale);
if (!$entity) {
throw new NotFoundHttpException();
}
return $this->render('@openform_front_templates/Collections/index.html.twig', [
'entity' => $entity,
]);
}
protected function generateLangLinksCollections( $entity)
{
$repo = $this->em->getRepository('Openform:PageTranslation');
$translations = $repo->findBy(['translatableId' => $entity->getId()]);
$langLinks = [];
foreach ($translations as $transItem){
if (strlen($transItem->getSlug()) > 0) {
$url = $this->routeLocalizer->generate($entity->getIdname(), [], $transItem->getLang());
$langLinks[$transItem->getLang()] = $url;
}
}
return $langLinks;
}
}