<?php
// src/Controller/LuckyController.php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use FOS\RestBundle\Request\ParamFetcherInterface;
use FOS\RestBundle\Controller\Annotations\QueryParam;
use Symfony\Component\HttpFoundation\Cookie;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\CmsQuestion;
use App\Entity\CmsQuestionCategory;
class FaqController extends AbstractController
{
/**
/**
* @Route({
* "en": "/faq",
* "es": "/preguntas-frecuentes",
* "de": "/haufig-gestellte-fragen",
* "fr": "/questions-frequemment-posees",
* "it": "/domande-frequenti",
* "pt": "/perguntas-frequentes",
* "cn": "/faq_cn",
* "cn2": "/faq_cn2",
* }, name="faq")
* @QueryParam(name="embedded", requirements="true|false", default="false", description="Embedded.")
* @QueryParam(name="country", requirements="es|ar", default=null, nullable=true, strict=false, description="Country.")
*/
public function index(Request $request, ParamFetcherInterface $paramFetcher)
{
$embedded = $paramFetcher->get('embedded') == 'true';
$country = $paramFetcher->get('country');
$repo = $this->getDoctrine()->getRepository(CmsQuestion::class);
$repoCategories = $this->getDoctrine()->getRepository(CmsQuestionCategory::class);
$categories = $repoCategories->findByAllSorted($request->getLocale());
foreach($categories as &$category){
$questions = $repo->findByAllSorted($category, $request->getLocale());
$category->setTranslatedQuestions($questions);
}
$res = $this->render('jelly/faq/index.html.twig', [
"embedded" => $embedded,
"categories" => $categories,
]);
if($country) {
$cookie = new Cookie(
"country", // Cookie name
$country, // Cookie content
(new \DateTime('now'))->modify("+365 day"), // Expiration date
);
$res->headers->setCookie($cookie);
}
return $res;
}
/**
* @Route({
* "en": "/compatible-devices",
* "es": "/dispositivos-compatibles",
* "de": "/kompatible-gerate",
* "fr": "/appareils-compatibles",
* "it": "/dispositivi-compatibili",
* "pt": "/dispositivos-compativeis",
* "cn": "/compatible-devices_cn",
* "cn2": "/compatible-devices_cn2",
* }, name="compatible_devices")
*/
public function compatibleDevices(Request $request)
{
$repo = $this->getDoctrine()->getRepository(CmsQuestion::class);
$question = $repo->findOneBy(['isCompatibleDevices' => true]);
$question->setTranslatableLocale($request->getLocale());
$this->getDoctrine()->getManager()->refresh($question);
return $this->render('jelly/faq/compatible_devices.html.twig', [
"question" => $question,
]);
}
}