<?php
namespace App\CmsController;
use App\Api\Helper\SeoHelper;
use App\Api\Helper\ContentHelper;
use App\Api\ApiClient;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\Request;
class PageController extends AbstractController
{
/**
* @Route("/{_locale}/notre-agence", name="la_team")
*/
public function team($slug ="notre-agence",
Request $request,
ApiClient $apiClient,
TranslatorInterface $translator,
SeoHelper $seoHelper,
ContentHelper $contentHelper)
{
$debug = $this->getParameter('kernel.debug');
$entity = 'content';
$locale = $request->getLocale();
/* slug anglais */
$englishSlug = [
"our-agency" => "notre-agence"
];
if( in_array($slug, array_keys($englishSlug))){
$slug = $englishSlug[$slug];
}
try {
$seo = $seoHelper->getSeoBySlug($entity, $slug,$request->getLocale());
} catch (ClientException $e) {
if ($debug) {
$viewPath = "api/error/notfound.html.twig";
return $this->render($viewPath, array("message" => sprintf("Erreur API : %s", $this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
}
}
try {
$content = $contentHelper->getOneBySlug($slug);
} catch (ClientException $e) {
if ($debug) {
$viewPath = "api/error/notfound.html.twig";
return $this->render($viewPath, array("message" => sprintf("Erreur API : %s", $this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
}
}
if (empty($content)) {
throw new NotFoundHttpException();
}
return $this->render('cms/page/la_team.html.twig', [
'seo' => $seo,
'slug' => $slug
]);
}
/**
* @Route("/{_locale}/nos-engagements-responsables", name="greenAttitude")
*/
public function greenAttitude($slug ="nos-engagements-responsables", Request $request,ApiClient $apiClient, TranslatorInterface $translator)
{
return $this->render('cms/page/nos-engagements-responsables.html.twig', [
]);
}
/**
* @Route("/{_locale}/notre-equipe", name="notre_equipe")
*/
public function Equipe($slug ="notre-equipe", Request $request,ApiClient $apiClient, TranslatorInterface $translator)
{
/* return $this->render('cms/page/team.html.twig', [
]); */
return $this->render('cms/page/team_v2.html.twig', []);
}
/**
* @Route("/{_locale}/{slug}", name="cms_page_show")
*/
public function show($slug,
Request $request,
ApiClient $apiClient,
TranslatorInterface $translator,
ContentHelper $contentHelper,
SeoHelper $seoHelper)
{
$debug = $this->getParameter('kernel.debug');
$entity = 'content';
$locale = $request->getLocale();
/* slug anglais */
$englishSlug = [
"our-agency" => "notre-agence",
"our-staff" => "notre-equipe",
"insurance"=>"assurances",
"terms-of-sale"=>"conditions-de-vente",
"frequently-asked-questions"=>"foire-aux-questions"
];
if( in_array($slug, array_keys($englishSlug))){
$slug = $englishSlug[$slug];
}
try {
$seo = $seoHelper->getSeoBySlug($entity, $slug,$request->getLocale());
} catch (ClientException $e) {
if ($debug) {
$viewPath = "api/error/notfound.html.twig";
return $this->render($viewPath, array("message" => sprintf("Erreur API : %s", $this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
}
}
try {
$content = $contentHelper->getOneBySlug($slug);
} catch (ClientException $e) {
if ($debug) {
$viewPath = "api/error/notfound.html.twig";
return $this->render($viewPath, array("message" => sprintf("Erreur API : %s", $this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
}
}
if (empty($content)) {
throw new NotFoundHttpException();
}
return $this->render('cms/page/show.html.twig', [
'seo' => $seo,
'slug' => $slug
]);
}
}