<?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 HomeController extends AbstractController {
public function __construct() {
// echo 'We can use __contruct<br />';
}
// /**
// * @Route("{_locale}/", name="home", defaults={"_locale" = "ca"}, requirements={"_locale" = "en|ca|es"})
// * @Route("/", defaults={"_locale" = "ca"}, name="home", requirements={"_locale" = "en|ca|es"})
// */
/**
* @Route(
* {
* "es" : "/es",
* "ca" : "/",
* "en" : "/en",
* }, name="home",
* requirements={
* "_locale": "es|ca|en",
* "_format" : "html"
* }
* )
*/
public function index(Request $request, TextHelper $textHelper, UrlHelper $urlHelper) {
$oneSection = $this->getDoctrine()->getRepository(Section::Class)->findOneBy(['code' => 'home']);
$text = ($textHelper->getBySection($oneSection)) ? $textHelper->getBySection($oneSection) : [];
$eventAddFiles = [];
$records = $this->getDoctrine()->getRepository(News::class)->findBy(['active' => 1], ['sort' => 'ASC'], 4);
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/home/home.html.twig', ['events' => $eventAddFiles, 'text' => $text, 'oneSection' => $oneSection]);
}
}