src/Controller/FaqController.php line 41

Open in your IDE?
  1. <?php
  2. // src/Controller/LuckyController.php
  3. namespace App\Controller;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Contracts\Translation\TranslatorInterface;
  9. use Symfony\Component\Validator\Validator\ValidatorInterface;
  10. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  11. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  12. use FOS\RestBundle\Request\ParamFetcherInterface;
  13. use FOS\RestBundle\Controller\Annotations\QueryParam;
  14. use Symfony\Component\HttpFoundation\Cookie;
  15. use Doctrine\ORM\EntityManagerInterface;
  16. use App\Entity\CmsQuestion;
  17. use App\Entity\CmsQuestionCategory;
  18. class FaqController extends AbstractController
  19. {
  20.     /**
  21.     /**
  22.     * @Route({
  23.      *     "en": "/faq",
  24.      *     "es": "/preguntas-frecuentes",
  25.      *     "de": "/haufig-gestellte-fragen",
  26.      *     "fr": "/questions-frequemment-posees",
  27.      *     "it": "/domande-frequenti",
  28.      *     "pt": "/perguntas-frequentes",
  29.      *     "cn": "/faq_cn",
  30.      *     "cn2": "/faq_cn2",
  31.      * }, name="faq")
  32.     * @QueryParam(name="embedded", requirements="true|false", default="false", description="Embedded.")
  33.     * @QueryParam(name="country", requirements="es|ar", default=null, nullable=true, strict=false, description="Country.")
  34.      */    
  35.     public function index(Request $requestParamFetcherInterface $paramFetcher)
  36.     {
  37.         
  38.         $embedded $paramFetcher->get('embedded') == 'true';
  39.         $country $paramFetcher->get('country');
  40.         $repo $this->getDoctrine()->getRepository(CmsQuestion::class);
  41.         $repoCategories $this->getDoctrine()->getRepository(CmsQuestionCategory::class);
  42.         $categories $repoCategories->findByAllSorted($request->getLocale());
  43.         foreach($categories as &$category){
  44.             $questions $repo->findByAllSorted($category$request->getLocale());    
  45.             $category->setTranslatedQuestions($questions);
  46.         }
  47.         
  48.         $res $this->render('jelly/faq/index.html.twig', [
  49.             "embedded" => $embedded,            
  50.             "categories" => $categories,
  51.         ]);
  52.         if($country) {
  53.              $cookie = new Cookie(
  54.                       "country",                      // Cookie name
  55.                       $country,                                       // Cookie content
  56.                       (new \DateTime('now'))->modify("+365 day"), // Expiration date
  57.                   );
  58.              $res->headers->setCookie($cookie);
  59.         }
  60.         return $res;
  61.     }
  62.     /**
  63.     * @Route({
  64.      *     "en": "/compatible-devices",
  65.      *     "es": "/dispositivos-compatibles",
  66.      *     "de": "/kompatible-gerate",
  67.      *     "fr": "/appareils-compatibles",
  68.      *     "it": "/dispositivi-compatibili",
  69.      *     "pt": "/dispositivos-compativeis",
  70.      *     "cn": "/compatible-devices_cn",
  71.      *     "cn2": "/compatible-devices_cn2",
  72.      * }, name="compatible_devices")
  73.      */    
  74.     public function compatibleDevices(Request $request)
  75.     {
  76.     
  77.         $repo $this->getDoctrine()->getRepository(CmsQuestion::class);
  78.         $question $repo->findOneBy(['isCompatibleDevices' => true]);
  79.         $question->setTranslatableLocale($request->getLocale());
  80.         $this->getDoctrine()->getManager()->refresh($question);
  81.         return $this->render('jelly/faq/compatible_devices.html.twig', [
  82.             "question" => $question,
  83.         ]);
  84.     }
  85. }