<?php
namespace App\Controller;
use App\Form\NewsletterSubscriptionType;
use App\Model\Faq;
use App\Service\APIKiwi;
use Exception;
use JMS\Serializer\SerializerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
class DefaultController extends APIController
{
/**
* @Route("/", name="kiwi_homepage")
* @param Request $request
* @param APIKiwi $APIKiwi
* @param TranslatorInterface $translator
* @param SerializerInterface $serializer
* @return Response
* @throws Exception
*/
public function homepage(Request $request, APIKiwi $APIKiwi, TranslatorInterface $translator,
SerializerInterface $serializer)
{
$form = $this->createForm(NewsletterSubscriptionType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
$APIKiwi->postPublicKiwi([
'path' => '/public/newsletter-subscription',
'data' => [
'email' => $data['email'],
]
]);
$this->addFlash('success', $translator->trans('default.newsletter.success'));
}
$user = $this->getUser();
return $this->render('default/homepage.html.twig', [
'user' => $user,
'newsletterForm' => $form->createView(),
]);
}
/**
* @Route("/modalite", name="kiwi_modality")
*/
public function modality()
{
return $this->render('default/modality.html.twig', [
'user' => $this->getUser(),
]);
}
/**
* @Route("/mentions-legales", name="kiwi_mentions_legales")
*/
public function mentionsLegales()
{
return $this->render('default/mentions-legales.html.twig', [
'user' => $this->getUser(),
]);
}
/**
* @Route("/cgu", name="kiwi_cgu")
*/
public function cgu()
{
return $this->render('default/cgu.html.twig', [
'user' => $this->getUser(),
]);
}
/**
* @Route("/donnees-personnelles", name="kiwi_donnees_perso")
*/
public function donneesPerso()
{
return $this->render('default/donnees-perso.html.twig', [
'user' => $this->getUser(),
]);
}
/**
* @Route("/cookies", name="kiwi_cookies")
*/
public function cookies()
{
return $this->render('default/cookies.html.twig', [
'user' => $this->getUser(),
]);
}
/**
* @Route("/faq", name="kiwi_faq")
*/
public function faq(APIKiwi $APIKiwi)
{
$response = $APIKiwi->getPublicKiwi('faqs');
return $this->render('default/faq.html.twig', [
'faqs' => $this->batchDeserialize(json_decode($response->getContent(), true)['hydra:member'], Faq::class, 'get_faqs'),
]);
}
/**
* @Route("/contenus-exclusifs", name="kiwi_cmslist")
*/
public function cmslist()
{
return $this->render('default/cmslist.html.twig', [
'user' => $this->getUser(),
]);
}
/**
* @Route("/contenus-exclusifs/article1", name="kiwi_cmslist_article1")
*/
public function article1()
{
return $this->render('default/articles/article1.html.twig', [
'user' => $this->getUser(),
]);
}
/**
* @Route("/contenus-exclusifs/article2", name="kiwi_cmslist_article2")
*/
public function article2()
{
return $this->render('default/articles/article2.html.twig', [
'user' => $this->getUser(),
]);
}
/**
* @Route("/contenus-exclusifs/article3", name="kiwi_cmslist_article3")
*/
public function article3()
{
return $this->render('default/articles/article3.html.twig', [
'user' => $this->getUser(),
]);
}
/**
* @Route("/contenus-exclusifs/article4", name="kiwi_cmslist_article4")
*/
public function article4()
{
return $this->render('default/articles/article4.html.twig', [
'user' => $this->getUser(),
]);
}
}