src/Controller/Front/BlogController.php line 45

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Entity\{ArticleArticleCategory};
  4. use App\Service\AccessClientService;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Knp\Component\Pager\PaginatorInterface;
  11. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  12. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  13. class BlogController extends AbstractController
  14. {
  15.     /**
  16.      * @Route("/blog", name="app_front_blog")
  17.      */
  18.     public function articles(AccessClientService $accessClientServiceRequest $requestEntityManagerInterface $entityManagerPaginatorInterface $paginator): Response
  19.     {
  20.         $accessClientService->handleAccessControl();
  21.         $categories $entityManager->getRepository(ArticleCategory::class)->findBy([], ['id' => 'DESC']);
  22.         $lastArticles $entityManager->getRepository(Article::class)->findBy(['status' => true], ['id' => 'DESC'], 100);
  23.         $query $entityManager->getRepository(Article::class)->findBy(['status' => true], ['id' => 'DESC']);
  24.         $pagination $paginator->paginate(
  25.             $query,
  26.             $request->query->getInt('page'1),
  27.             12
  28.         ); 
  29.         return $this->render('front/blog/articles.html.twig', [
  30.             'categories' => $categories,
  31.             'lastArticles' => $lastArticles,
  32.             'articles' => $pagination
  33.         ]);
  34.     }
  35.     /**
  36.      * @Route("/blog/{slug}", name="app_front_blog_by_category")
  37.      */
  38.     public function by_category(ArticleCategory $categoryRequest $requestEntityManagerInterface $entityManagerPaginatorInterface $paginator)
  39.     {
  40.         $categories $entityManager->getRepository(ArticleCategory::class)->findBy([], ['id' => 'DESC']);
  41.         
  42.         $query $entityManager->getRepository(Article::class)->getArticlesByCategory($category);
  43.         $pagination $paginator->paginate(
  44.             $query,
  45.             $request->query->getInt('page'1),
  46.             12
  47.         ); 
  48.         
  49.         return $this->render('front/blog/by_category.html.twig', [
  50.             'category' => $category,
  51.             'categories' => $categories,
  52.             'articles' => $pagination
  53.         ]);
  54.     }
  55.     /**
  56.      * @Route("/blog/{cat_slug}/{slug}", name="app_front_blog_read")
  57.      */
  58.     public function read($cat_slugArticle $articleEntityManagerInterface $entityManager)
  59.     {
  60.         if($article->getCategory()->getSlug() != $cat_slug)
  61.             throw new NotFoundHttpException('Cette catégorie est introuvable !');
  62.         $categories $entityManager->getRepository(ArticleCategory::class)->findBy([], ['id' => 'DESC']);
  63.         $lastArticles $entityManager->getRepository(Article::class)->getLastArticles($article->getId(), $article->getCategory(), 10);
  64.         return $this->render('front/blog/read.html.twig', [
  65.             'article' => $article,
  66.             'categories' => $categories,
  67.             'lastArticles' => $lastArticles
  68.         ]);
  69.     }
  70. }