src/CmsController/PageController.php line 141

Open in your IDE?
  1. <?php
  2. namespace App\CmsController;
  3. use App\Api\Helper\SeoHelper
  4. use App\Api\Helper\ContentHelper;
  5. use App\Api\ApiClient
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Contracts\Translation\TranslatorInterface;
  9. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  10. use Symfony\Component\HttpFoundation\Request;
  11. class PageController extends AbstractController
  12. {
  13.     /**
  14.      * @Route("/{_locale}/notre-agence", name="la_team")
  15.      */
  16.     public function team($slug ="notre-agence",
  17.      Request $request,
  18.      ApiClient $apiClient,
  19.      TranslatorInterface $translator,
  20.      SeoHelper $seoHelper,
  21.      ContentHelper $contentHelper)
  22.     {   
  23.         $debug $this->getParameter('kernel.debug');
  24.         $entity 'content';        
  25.         $locale $request->getLocale();
  26.       
  27.         /* slug anglais */  
  28.         $englishSlug = [
  29.             "our-agency" => "notre-agence"
  30.         ];   
  31.         
  32.         if( in_array($slugarray_keys($englishSlug))){
  33.             $slug =  $englishSlug[$slug];
  34.         }
  35.        
  36.         try {
  37.             $seo $seoHelper->getSeoBySlug($entity$slug,$request->getLocale());
  38.             
  39.         } catch (ClientException $e) {
  40.             if ($debug) {
  41.                 $viewPath "api/error/notfound.html.twig";
  42.                 return $this->render($viewPath, array("message" => sprintf("Erreur API : %s"$this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  43.             }
  44.         }
  45.         try {
  46.             $content $contentHelper->getOneBySlug($slug);
  47.         } catch (ClientException $e) {
  48.             if ($debug) {
  49.                 $viewPath "api/error/notfound.html.twig";
  50.                 return $this->render($viewPath, array("message" => sprintf("Erreur API : %s"$this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  51.             }
  52.         }
  53.         
  54.         if (empty($content)) {
  55.             throw new NotFoundHttpException();
  56.         }
  57.         
  58.         return $this->render('cms/page/la_team.html.twig', [
  59.             'seo'       => $seo,
  60.             'slug'      => $slug
  61.         ]);
  62.     }
  63.     /**
  64.      * @Route("/{_locale}/nos-engagements-responsables", name="greenAttitude")
  65.      */
  66.     public function greenAttitude($slug ="nos-engagements-responsables"Request $request,ApiClient $apiClientTranslatorInterface $translator)
  67.     {   
  68.        
  69.         return $this->render('cms/page/nos-engagements-responsables.html.twig', [
  70.         ]);
  71.     }
  72.     /**
  73.      * @Route("/{_locale}/notre-equipe", name="notre_equipe")
  74.      */
  75.     public function Equipe($slug ="notre-equipe"Request $request,ApiClient $apiClientTranslatorInterface $translator)
  76.     {   
  77.        
  78.         
  79.         /* return $this->render('cms/page/team.html.twig', [
  80.             
  81.         ]); */
  82.         return $this->render('cms/page/team_v2.html.twig', []);
  83.     }
  84.     /**
  85.      * @Route("/{_locale}/{slug}", name="cms_page_show")
  86.      */
  87.     public function show($slug,
  88.      Request $request,
  89.      ApiClient $apiClient,
  90.      TranslatorInterface $translator,
  91.      ContentHelper $contentHelper,
  92.      SeoHelper $seoHelper)
  93.     {   
  94.         $debug $this->getParameter('kernel.debug');
  95.         $entity 'content';        
  96.         $locale $request->getLocale();
  97.       
  98.         /* slug anglais */  
  99.         $englishSlug = [
  100.             "our-agency" => "notre-agence",
  101.             "our-staff" => "notre-equipe",
  102.             "insurance"=>"assurances",
  103.             "terms-of-sale"=>"conditions-de-vente",
  104.             "frequently-asked-questions"=>"foire-aux-questions"
  105.         ];   
  106.         
  107.         if( in_array($slugarray_keys($englishSlug))){
  108.             $slug =  $englishSlug[$slug];
  109.         }
  110.        
  111.         try {
  112.             $seo $seoHelper->getSeoBySlug($entity$slug,$request->getLocale());
  113.             
  114.         } catch (ClientException $e) {
  115.             if ($debug) {
  116.                 $viewPath "api/error/notfound.html.twig";
  117.                 return $this->render($viewPath, array("message" => sprintf("Erreur API : %s"$this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  118.             }
  119.         }
  120.         try {
  121.             $content $contentHelper->getOneBySlug($slug);
  122.         } catch (ClientException $e) {
  123.             if ($debug) {
  124.                 $viewPath "api/error/notfound.html.twig";
  125.                 return $this->render($viewPath, array("message" => sprintf("Erreur API : %s"$this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  126.             }
  127.         }
  128.         
  129.         if (empty($content)) {
  130.             throw new NotFoundHttpException();
  131.         }
  132.         
  133.         return $this->render('cms/page/show.html.twig', [
  134.             'seo'       => $seo,
  135.             'slug'      => $slug
  136.         ]);
  137.     }
  138.     
  139. }