<?php
namespace App\Controller;
use App\Entity\General;
use App\Entity\Sidebar;
use App\Entity\Sponsors;
use App\Entity\Usuari;
use App\Entity\Pagina;
use App\Util\Util;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Contracts\Translation\TranslatorInterface;
class PaginaController extends AbstractController
{
protected $enSidebar;
protected $enGeneral;
protected $enSponsors;
private $em;
private $objUtil;
private $requestStack;
private $session;
private $translator;
private $params;
private $correuController;
private $mailer;
private $sPathUploads;
public function __construct(EntityManagerInterface $em,RequestStack $requestStack,TranslatorInterface $translator, ContainerBagInterface $params, CorreuController $correuController,MailerInterface $mailer)
{
$this->em = $em;
$this->objUtil = new Util($this->em);
$this->requestStack = $requestStack;
$this->session = $this->requestStack->getSession();
$this->translator = $translator;
$this->params = $params;
$this->correuController = $correuController;
$this->mailer = $mailer;
$this->sPathUploads = dirname(__FILE__) . "/../../public/uploads/";
$this->enSidebar = $this->em->getRepository(Sidebar::class)->findBy(
array( 'general' => 1)
);
/////////////////////////
// Recoger dades generals
/////////////////////////
$this->enGeneral = $this->em->getRepository(General::class)->findAll();
///////////
// Sponsors
///////////
$this->enSponsors = $this->em->getRepository(Sponsors::class)->findBy(
array( 'visible' => 1),
array('ordre' => 'ASC')
);
}
public function indexAction(Request $peticion)
{
$session = $peticion->getSession();
$session->start();
$repository = $this->em->getRepository(Pagina::class);
$pagina = $repository->getPaginaSlug($peticion->attributes->get('_slug'), $peticion->attributes->get('_locale'));
$aMetatags = array();
$aMetatags['title'] = $pagina->{'getTitle' . ucfirst($peticion->attributes->get('_locale'))}();
$aMetatags['description'] = $pagina->{'getDescription' . ucfirst($peticion->attributes->get('_locale'))}();
$aMetatags['keywords'] = $pagina->{'getKeywords' . ucfirst($peticion->attributes->get('_locale'))}();
$enPaginaSlug = $repository->findOneBy(array("slug_" . $peticion->attributes->get('_locale') => $peticion->attributes->get('_slug')));
$blDarrera_hora = false;
if (method_exists('getBlocs', $pagina))
{
foreach ($pagina->getBlocs() as $key => $val)
{
//dump ($val->getTipus()->getTipus() );
//echo '-' . $val->getTipus()->getSlug() . '<br>';
if ($val->getTipus()->getSlug() == 'darrera_hora')
{
$blDarrera_hora = true;
}
}
}
/*
$objDarreraHora = array();
if ($blDarrera_hora)
{
$aSort = array("data" => "DESC");
$aParam = array();
$objDarreraHora = $this->em->getRepository(DarreraHora::class)->findBy($aParam,$aSort,5);
//echo '<pre>';
//print_r ($objDarreraHora);
//echo '</pre>';
}
$fotos = array();
if (method_exists('getGaleries',$pagina))
{
if (!is_null($pagina->getGaleries()))
{
$aParam = array('galeries' => $pagina->getGaleries());
$fotos = $this->em->getRepository(Fotos::class)->findBy($aParam);
}
}
*/
return $this->render('paginas.html.twig', array(
'pagina' => $pagina,
'esHome' => 0,
//'fotos' => $fotos,
//'objDarreraHora'=> $objDarreraHora,
'entMenu' => $enPaginaSlug,
'enGeneral' => $this->enGeneral,
'enSponsors' => $this->enSponsors,
'fotos' => array(),
'metatags' => $aMetatags
));
}
public function menuListAction($isMobileVersion=false)
{
$repository = $this->em->getRepository(Pagina::class);
$list = $repository->getSecciones();
return $this->render('menuList.html.twig', array(
"isMobileVersion" => $isMobileVersion,
"list" => $list
));
}
}