src/Controller/IndexController.php line 54

  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Web;
  4. use App\Form\Front\ContactType;
  5. use App\Service\WebService;
  6. use App\Service\CategoriesService;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use App\Entity\Categorie;
  9. use App\Entity\Book;
  10. use Doctrine\ORM\EntityManagerInterface;
  11. use Symfony\Component\HttpFoundation\JsonResponse;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. class IndexController extends AbstractController
  15. {
  16.     /**
  17.      * @var EntityManagerInterface
  18.      */
  19.     private $em;
  20.     /**
  21.      * @var WebService
  22.      */
  23.     private $webFunctions;
  24.     /**
  25.      * @var CategoriesService
  26.      */
  27.     private $categoriesFunctions;
  28.     /**
  29.      * IndexController constructor.
  30.      * @param EntityManagerInterface $em
  31.      * @param WebService $webFunctions
  32.      */
  33.     public function __construct(EntityManagerInterface $emWebService $webFunctionsCategoriesService $catService)
  34.     {
  35.         $this->em $em;
  36.         $this->webFunctions $webFunctions;
  37.         $this->catService $catService;
  38.     }
  39.     /**
  40.      * Undocumented function
  41.      *
  42.      * @return Response
  43.      */
  44.     #Route("/", name="indexPage")
  45.     public function index()
  46.     {
  47.         $book $this->em->getRepository(Book::class)->findBy(array('published' => true), array('createdAt'=>'DESC'));
  48.         $webElements $this->webFunctions->reorderWebElements($this->em->getRepository(Web::class)->findBy(array('published' => true), array('position' => 'ASC')));
  49.         $categories $this->em->getRepository(Categorie::class)->findAll();
  50.         $formContact $this->createForm(ContactType::class)->createView();
  51.         return $this->render("front/default/index.html.twig", array('categories' => $categories'book' => $book'web' => $webElements'formContact' => $formContact));
  52.     }
  53.     /**
  54.      *
  55.      * @param Request $request
  56.      * @return Response
  57.      */
  58.     #Route("/web/detail", name="detail_web")
  59.     public function detailWeb(Request $request): Response
  60.     {
  61.         /** Web $web */
  62.         if(null !== $request->query->get('id')){
  63.             $id $request->query->get('id');
  64.         }else{
  65.             $id $request->request->get('id');
  66.         }
  67.         $web $this->em->getRepository(Web::class)->findOneBy(['id' => $id]);
  68.         return new Response(
  69.             $this->renderView("front/details/detailWeb.html.twig", array('web' => $web)),
  70.             200,
  71.             array('Access-Control-Allow-Origin'=> '*')
  72.         );
  73.     }
  74.     /**
  75.      *
  76.      * @param Request $request
  77.      * @return Response
  78.      */
  79.     #[Route('/book/detail'name'detail_book')]
  80.     public function detailBook(Request $request): Response
  81.     {
  82.         if(null !== $request->query->get('id')){
  83.             $id $request->query->get('id');
  84.         }else{
  85.             $id $request->request->get('id');
  86.         }
  87.         /** Book $book */
  88.         $book $this->em->getRepository(Book::class)->findOneBy(['id' => $id]);
  89.         return $this->render("front/details/detailBook.html.twig", array('book' => $book));
  90.     }
  91. }