src/Controller/FrontController.php line 183

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Achievement;
  4. use App\Entity\Category;
  5. use App\Entity\Contact;
  6. use App\Entity\Expertise;
  7. use App\Entity\Homepage;
  8. use App\Entity\LandingPage;
  9. use App\Entity\Post;
  10. use App\Entity\Presentation;
  11. use App\Entity\Product;
  12. use App\Form\ContactType;
  13. use App\Repository\AchievementRepository;
  14. use App\Repository\CategoryRepository;
  15. use App\Repository\ExpertiseRepository;
  16. use App\Repository\HomepageRepository;
  17. use App\Repository\LandingPageRepository;
  18. use App\Repository\PostRepository;
  19. use App\Repository\PresentationRepository;
  20. use App\Repository\ProductRepository;
  21. use Doctrine\ORM\EntityManagerInterface;
  22. use Doctrine\Persistence\ManagerRegistry;
  23. use Pagerfanta\Doctrine\ORM\QueryAdapter;
  24. use Pagerfanta\Pagerfanta;
  25. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  26. use Symfony\Component\HttpFoundation\Request;
  27. use Symfony\Component\HttpFoundation\Response;
  28. use Symfony\Component\Routing\Annotation\Route;
  29. class FrontController extends AbstractController
  30. {
  31.     /** @var ManagerRegistry */
  32.     private $em;
  33.     public function __construct(ManagerRegistry $em)
  34.     {
  35.         $this->em $em;
  36.     }
  37.     /**
  38.      * @Route("/", name="app_homepage")
  39.      */
  40.     public function index(HomepageRepository $homepageRepositoryPostRepository $postRepositoryLandingPageRepository $landingPageRepository): Response
  41.     {
  42.         $page $homepageRepository->findUnique();
  43.         $posts $postRepository->findPromotedOrRecentPosts(2);
  44.         $landingPages $landingPageRepository->findBy(['displayHomepage' => true]);
  45.         return $this->render('front/index.html.twig', array(
  46.             'page' => $page,
  47.             'posts' => $posts,
  48.             "landingPages" => $landingPages
  49.         ));
  50.     }
  51.     
  52.     /**
  53.      * @Route("/realisation-pelletier/{slug}", name="app_achievement_show")
  54.      */
  55.     public function showAchievement(Request $requestAchievement $achievement): Response
  56.     {
  57.         return $this->render('front/Achievement/show.html.twig', array('page' => $achievement));
  58.     }
  59.     
  60.     /**
  61.      * @Route("/realisations-pelletier/{page}", name="app_achievement_list", requirements={"page"="\d+"}, defaults={"page": 1})
  62.      */
  63.     public function listAchievements(Request $request$page): Response
  64.     {
  65.         /** @var AchievementRepository $repo */
  66.         $repo $this->em->getRepository(Achievement::class);
  67.         $achievements = new Pagerfanta(new QueryAdapter($repo->createQueryBuilder('e')->addOrderBy('e.position''ASC')->addOrderBy('e.updatedAt''DESC')));
  68.         $achievements->setMaxPerPage(13);
  69.         $achievements->setCurrentPage($page);
  70.         return $this->render('front/Achievement/list.html.twig', array('achievements' => $achievements));
  71.     }
  72.     
  73.     /**
  74.      * @Route("/categorie/{slug}", name="app_category_show")
  75.      */
  76.     public function showCategory(Request $requestCategory $categoryPostRepository $postRepository): Response
  77.     {
  78.         $posts $postRepository->findBy([], ['date' => 'DESC'], 2);
  79.         return $this->render('front/Category/show.html.twig', array(
  80.             'page' => $category,
  81.             'posts' => $posts,
  82.         ));
  83.     }
  84.     
  85.     /**
  86.      * @Route("/categorie/{page}", name="app_category_list", requirements={"page"="\d+"}, defaults={"page": 1})
  87.      */
  88.     public function listCategorys(Request $request$page): Response
  89.     {
  90.         /** @var CategoryRepository $repo */
  91.         $repo $this->em->getRepository(Category::class);
  92.         $categorys = new Pagerfanta(new QueryAdapter($repo->createQueryBuilder('e')->orderBy('e.date''DESC')));
  93.         $categorys->setMaxPerPage(6);
  94.         $categorys->setCurrentPage($page);
  95.         return $this->render('front/Category/list.html.twig', array('categorys' => $categorys));
  96.     }
  97.     
  98.     /**
  99.      * @Route("/actualite/detail/{slug}", name="app_post_show")
  100.      */
  101.     public function showPost(Request $requestPost $post): Response
  102.     {
  103.         return $this->render('front/Post/show.html.twig', array('page' => $post));
  104.     }
  105.     
  106.     /**
  107.      * @Route("/actualite/{page}", name="app_post_list", requirements={"page"="\d+"}, defaults={"page": 1})
  108.      */
  109.     public function listPosts(Request $request$page): Response
  110.     {
  111.         /** @var PostRepository $repo */
  112.         $repo $this->em->getRepository(Post::class);
  113.         $posts = new Pagerfanta(new QueryAdapter($repo->createQueryBuilder('e')));
  114.         $posts->setMaxPerPage(6);
  115.         $posts->setCurrentPage($page);
  116.         return $this->render('front/Post/list.html.twig', array('posts' => $posts));
  117.     }
  118.     
  119.     /**
  120.      * @Route("/produit/{slug}", name="app_product_show")
  121.      */
  122.     public function showProduct(Request $requestProduct $product): Response
  123.     {
  124.         return $this->render('front/Product/show.html.twig', array('page' => $product));
  125.     }
  126.     
  127.     /**
  128.      * @Route("/produits/{page}", name="app_product_list", requirements={"page"="\d+"}, defaults={"page": 1})
  129.      */
  130.     public function listProducts(Request $request$page): Response
  131.     {
  132.         /** @var ProductRepository $repo */
  133.         $repo $this->em->getRepository(Product::class);
  134.         $products = new Pagerfanta(new QueryAdapter($repo->createQueryBuilder('e')));
  135.         $products->setMaxPerPage(6);
  136.         $products->setCurrentPage($page);
  137.         return $this->render('front/Product/list.html.twig', array('products' => $products));
  138.     }
  139.     
  140.     /**
  141.      * @Route("/pelletier-enseignes", name="app_presentation_index")
  142.      */
  143.     public function presentation(Request $request): Response
  144.     {
  145.         /** @var PresentationRepository $repo */
  146.         $repo $this->em->getRepository(Presentation::class);
  147.         $page $repo->findUnique();
  148.         return $this->render('front/Presentation/index.html.twig', array('page' => $page));
  149.     }
  150.     
  151.     /**
  152.      * @Route("/fabrication-enseignes", name="app_expertise_index")
  153.      */
  154.     public function expertise(Request $request): Response
  155.     {
  156.         /** @var ExpertiseRepository $repo */
  157.         $repo $this->em->getRepository(Expertise::class);
  158.         $page $repo->findUnique();
  159.         return $this->render('front/Expertise/index.html.twig', array('page' => $page));
  160.     }
  161.     
  162.     /**
  163.      * @Route("/page/{slug}", name="app_landing_page_show")
  164.      */
  165.     public function showLandingPage(Request $requestLandingPage $landingPage): Response
  166.     {
  167.         return $this->render('front/LandingPage/show.html.twig', array('page' => $landingPage));
  168.     }
  169.     
  170.     /**
  171.      * @Route("/pages/{page}", name="app_landing_page_list", requirements={"page"="\d+"}, defaults={"page": 1})
  172.      */
  173.     public function listLandingPages(Request $request$page): Response
  174.     {
  175.         /** @var LandingPageRepository $repo */
  176.         $repo $this->em->getRepository(LandingPage::class);
  177.         $landingPages = new Pagerfanta(new QueryAdapter($repo->createQueryBuilder('e')));
  178.         $landingPages->setMaxPerPage(6);
  179.         $landingPages->setCurrentPage($page);
  180.         return $this->render('front/LandingPage/list.html.twig', array('landingPages' => $landingPages));
  181.     }
  182.     /**
  183.      * @Route("/contact", name="app_contact_show")
  184.      */
  185.     public function showContact(Request $requestEntityManagerInterface $em): Response
  186.     {
  187.         $contact = new Contact;
  188.         $form $this->createForm(ContactType::class, $contact);
  189.         $form->handleRequest($request);
  190.         
  191.         if ($form->isSubmitted() && $form->isValid()) {
  192.             $contact->setCreatedAt(new \DateTime());
  193.             $em->persist($contact);
  194.             $em->flush();
  195.             $this->addFlash('success''Merci nous avons reçu votre demande. Nous vous répondrons dans les plus brefs délais.');
  196.         }
  197.         return $this->render('front/Contact/show.html.twig', array(
  198.             'form' => $form->createView(),
  199.         ));
  200.     }
  201. }