<?php
namespace App\Controller;
use App\Entity\Image;
use App\Entity\TextEs;
use App\Entity\TextFr;
use App\Entity\TextPt;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
#[Route('/{_locale<%app.supported_locales%>}/epyp', name: 'app-epyp-')]
class EpypController extends AbstractController
{
#[Route('/', name: 'index')]
public function index(Request $request, EntityManagerInterface $entityManager): Response
{
$local = $request->getLocale(); // get la locale
$datasImages = $entityManager->getRepository(Image::class)->findBy(['page' => 'epyp']);
$images = [];
foreach ($datasImages as $img) {
$images[$img->getName()] = $img;
}
switch ($local) {
case "fr":
$datas = $entityManager->getRepository(TextFr::class)->findBy(['page' => 'epyp']);
break;
case "es":
$datas = $entityManager->getRepository(TextEs::class)->findBy(['page' => 'epyp']);
break;
case "pt":
$datas = $entityManager->getRepository(TextPt::class)->findBy(['page' => 'epyp']);
break;
default:
$datas = null;
break;
}
$texts = [];
foreach ($datas as $text) {
$texts[$text->getName()] = $text;
}
return $this->render('epyp/' . $local . '/index.html.twig',[
'texts' => $texts,
'images' => $images
]);
}
}