<?php
namespace App\Controller\Frontend;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Doctrine\ORM\EntityManagerInterface;
use App\Service\TextHelper;
use App\Service\UrlHelper;
use App\Entity\News;
use App\Entity\File;
use App\Entity\Section;
class EventsController extends AbstractController {
public function __construct() {
// echo 'We can use __contruct<br />';
}
/**
* @Route(
* {
* "es" : "{_locale}/eventos/agenda",
* "ca" : "{_locale}/esdeveniments/agenda",
* "en" : "{_locale}/events/schedule",
* }, name="events",
* requirements={
* "_locale": "es|ca|en",
* "_format" : "html"
* }
* )
*/
public function index(Request $request, TextHelper $textHelper, UrlHelper $urlHelper) {
$oneSection = $this->getDoctrine()->getRepository(Section::Class)->findOneBy(['code' => 'events']);
$text = ($textHelper->getBySection($oneSection)) ? $textHelper->getBySection($oneSection) : [];
$eventAddFiles = [];
$records = $this->getDoctrine()->getRepository(News::class)->findBy(['active' => 1], ['sort' => 'ASC']);
if ($records) {
foreach ($records as $key => $record) {
$image = $this->getDoctrine()->getRepository(File::class)->findOneBy(array('itemId' => $record->getId(), 'section' => 'news', 'type' => 'mainImage'), ['sort' => 'ASC']);
$eventAddFiles[$key]['mainImage'] = ($image) ? $urlHelper->createImageUrl('news', $record->getId(), 'resized', $image->getId(), 'backendGallery', $image->getExtension()) : null;
$eventAddFiles[$key]['record'] = $record;
}
}
return $this->render('Frontend/events/events.html.twig', ['events' => $eventAddFiles, 'text' => $text, 'oneSection' => $oneSection]);
}
/**
* @Route(
* {
* "es" : "{_locale}/eventos",
* "ca" : "{_locale}/esdeveniments",
* "en" : "{_locale}/events",
* }, name="eventosorganiza",
* requirements={
* "_locale": "es|ca|en",
* "_format" : "html"
* }
* )
*/
public function eventosorganiza(Request $request, TextHelper $textHelper) {
$oneSection = $this->getDoctrine()->getRepository(Section::Class)->findOneBy(['code' => 'eventosorganiza']);
$text = ($textHelper->getBySection($oneSection)) ? $textHelper->getBySection($oneSection) : [];
return $this->render('Frontend/events/eventsorganiza.html.twig', ['text' => $text, 'oneSection' => $oneSection]);
}
}