src/Controller/FrontEnd/PageCmsController.php line 73

Open in your IDE?
  1. <?php
  2. namespace App\Controller\FrontEnd;
  3. use App\Entity\Post;
  4. use App\Entity\UrlPost;
  5. use App\Entity\Category;
  6. use App\Service\RenderBloc;
  7. use Spatie\SchemaOrg\Graph;
  8. use App\Service\CodeService;
  9. use App\Service\MetaService;
  10. use Spatie\SchemaOrg\Schema;
  11. use Doctrine\ORM\EntityManagerInterface;
  12. use App\ModuleHandler\ModuleHandlerManager;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. use Leogout\Bundle\SeoBundle\Seo\Og\OgSeoGenerator;
  16. use Symfony\Component\String\Slugger\SluggerInterface;
  17. use Leogout\Bundle\SeoBundle\Seo\Basic\BasicSeoGenerator;
  18. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  19. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  20. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  21. class PageCmsController extends AbstractController
  22. {
  23. private $moduleHandlerManager;
  24. private $em;
  25. public function __construct(ModuleHandlerManager $moduleHandlerManager,
  26. EntityManagerInterface $em)
  27. {
  28. $this->moduleHandlerManager = $moduleHandlerManager;
  29. $this->em = $em;
  30. }
  31. // /**
  32. // * @Route("/{_locale}/{slug}", name="page", requirements={"slug"=".+","_locale"="fr|en|de|es|cn|it"}, defaults={"_locale"="fr"}, priority=-1)
  33. // */
  34. /**
  35. * @Route("/{slug}", name="page", requirements={"slug"=".+"}, priority=-1)
  36. */
  37. public function index(Request $request,$slug)
  38. {
  39. $_locale = $request->getLocale();
  40. $slugs = explode('/', $slug);
  41. if(count($slugs) > 1){
  42. $slug = end($slugs);
  43. }
  44. // if ($slug == 'blog') {
  45. // $result = $this->moduleHandlerManager->handle('NosActualite', $slug);
  46. // return $this->render($result['template'], $result['data']);
  47. // }
  48. if ($slug == 'search') {
  49. $result = $this->moduleHandlerManager->handle('PageSearch', $slug);
  50. return $this->render($result['template'], $result['data']);
  51. }
  52. if ($slug == 'nos-archives') {
  53. $result = $this->moduleHandlerManager->handle('NosArchives', $slug);
  54. return $this->render($result['template'], $result['data']);
  55. }
  56. $slug_info = $this->em->getRepository(UrlPost::class)->findUrlBySlug($slug);
  57. if(!$slug_info){
  58. throw new NotFoundHttpException('Sorry not existing!');
  59. }
  60. // verification lang slug and then switched
  61. $slug_lang = $this->em->getRepository(UrlPost::class)->SwitchLangRoute($slug);
  62. if($slug_lang != null && $_locale != $slug_lang){
  63. $request->getSession()->set('_locale', $slug_lang);
  64. $request->setLocale($slug_lang);
  65. }
  66. if($slug_info->getType() === "Post"){
  67. $result = $this->moduleHandlerManager->handle('PageCms', $slug);
  68. $render = $this->render($result['template'], $result['data']);
  69. }elseif($slug_info->getType() === "Categorie" || $slug_info->getType() === "Sous-categorie" || $slug_info->getType() === 'Sous-sous-categorie'){
  70. $result = $this->moduleHandlerManager->handle('PageCategorie', $slug);
  71. $render = $this->render($result['template'], $result['data']);
  72. }elseif($slug_info->getType() === "Partenaire"){
  73. $result = $this->moduleHandlerManager->handle('PagePartner', $slug);
  74. $render = $this->render($result['template'], $result['data']);
  75. }elseif($slug_info->getType() === "Expression"){
  76. $result = $this->moduleHandlerManager->handle('PageExpression', $slug);
  77. $render = $this->render($result['template'], $result['data']);
  78. }else{
  79. throw new NotFoundHttpException('Sorry not existing!');
  80. }
  81. return $render;
  82. }
  83. }