src/Controller/NoticiesController.php line 67

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\General;
  4. use App\Entity\Noticies;
  5. use App\Entity\Sidebar;
  6. use App\Entity\Sponsors;
  7. use App\Entity\Usuari;
  8. use App\Util\Util;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
  12. use Symfony\Component\HttpFoundation\RequestStack;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  16. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  17. use Symfony\Component\Mailer\MailerInterface;
  18. use Symfony\Component\Security\Core\SecurityContext;
  19. use Symfony\Contracts\Translation\TranslatorInterface;
  20. class NoticiesController extends AbstractController
  21. {
  22.     protected $enSidebar;
  23.     protected $enGeneral;
  24.     protected $enSponsors;
  25.     private $em;
  26.     private $objUtil;
  27.     private $requestStack;
  28.     private $session;
  29.     private $translator;
  30.     private $params;
  31.     private $correuController;
  32.     private $mailer;
  33.     private $sPathUploads;
  34.     public function __construct(EntityManagerInterface $em,RequestStack $requestStack,TranslatorInterface $translatorContainerBagInterface $paramsCorreuController $correuController,MailerInterface $mailer)
  35.     {
  36.         $this->em $em;
  37.         $this->objUtil = new Util($this->em);
  38.         $this->requestStack $requestStack;
  39.         $this->session $this->requestStack->getSession();
  40.         $this->translator $translator;
  41.         $this->params $params;
  42.         $this->correuController $correuController;
  43.         $this->mailer $mailer;
  44.         $this->sPathUploads dirname(__FILE__) . "/../../public/uploads/";
  45.         $this->enSidebar $this->em->getRepository(Sidebar::class)->findBy(
  46.             array(   'general' => 1)
  47.         );
  48.         /////////////////////////
  49.         // Recoger dades generals
  50.         /////////////////////////
  51.         $this->enGeneral $this->em->getRepository(General::class)->findAll();
  52.         ///////////
  53.         // Sponsors
  54.         ///////////
  55.         $this->enSponsors $this->em->getRepository(Sponsors::class)->findBy(
  56.             array( 'visible'   => 1),
  57.             array('ordre' => 'ASC')
  58.         );
  59.     }
  60.     public function indexAction(Request $peticion$apartat='')
  61.     {
  62.         $aRequest $peticion->request;
  63.         
  64.         if ($apartat == '')
  65.         {
  66.            $apartat $peticion->attributes->get('_apartat');
  67.            //////////////////////////////////////////////////////
  68.            // Si no es passa cap apartat el definim com a noticia
  69.            //////////////////////////////////////////////////////
  70.            if ($apartat == ''$apartat 'N';
  71.         }
  72.         $sTitol '';
  73.         switch($apartat)
  74.         {
  75.             case 'N':
  76.                 $sTitol $this->translator->trans("Noticies");
  77.                 break;
  78.             case 'P':
  79.                 $sTitol $this->translator->trans("Premsa");
  80.                 break;
  81.         }
  82.         
  83.         $aArray = array();
  84.         
  85.         if ($aRequest->get('apartat'))
  86.         {
  87.             $aArray = array('apartat' => $aRequest->get('apartat'));
  88.         } else if ($apartat != ''){
  89.             $aArray = array('apartat' => $apartat);
  90.         }
  91.         
  92.         $enNoticies $this->em->getRepository(Noticies::class)->findBy(
  93.             $aArray,
  94.             array(
  95.                 'ordre' => 'ASC',
  96.                 'id'    => 'DESC')
  97.         );
  98.         
  99.         return $this->render('noticies.html.twig', array(
  100.             'titol'         => $sTitol,
  101.             'enNoticies'    => $enNoticies,
  102.             'enSidebar'     => isset($this->enSidebar[0])?$this->enSidebar[0]:array(),
  103.             'enGeneral'     => $this->enGeneral,
  104.             'enSponsors'    => $this->enSponsors
  105.         ));
  106.     }    
  107. }