src/Controller/ArticleController.php line 39

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Article;
  4. use App\Entity\CategoryArticle;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Knp\Component\Pager\PaginatorInterface;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\VarDumper\VarDumper;
  11. /**
  12.  * Default controller.
  13.  *
  14.  * @Route("", requirements={"_locale" = "en|fr"})
  15.  */
  16. class ArticleController extends AbstractController
  17. {
  18.     /**
  19.      * @Route("/article", methods={"GET", "POST"}, name="article_list", options={"sitemap": true, "priority": 0.7, "changefreq": "monthly"})
  20.      *
  21.      */
  22.     public function indexAction(Request $requestEntityManagerInterface $em)
  23.     {
  24.         $filter null;
  25.         if($request->getMethod() == "POST"){
  26.             $filter $request->get('search_blog');
  27.         }
  28.         $articleRepo $em->getRepository(Article::class);
  29.         $categories $em->getRepository(CategoryArticle::class)->findBy(['deletedAt'=>null], ['sort'=>'ASC']);
  30.         $pagination $articleRepo->getArticlesList($filter);
  31.         return $this->render('app/article/list.html.twig', array(
  32.             'pagination' => $pagination,
  33.             'categories' => $categories,
  34.             'search' => $filter,
  35.         ));
  36.     }
  37.     
  38.     /**
  39.      * @Route("/article/{id}/{slug}", methods={"GET"}, name="article_show",  options={"sitemap": true, "priority": 0.7, "changefreq": "yearly"})
  40.      * 
  41.      */
  42.     public function showAction(Article $articleEntityManagerInterface $em$slug)
  43.     {
  44.         if (!$article) {
  45.             return $this->redirectToRoute('homepage');
  46.         }
  47.         if ($slug != $article->translate()->getSlug()) {
  48.             return $this->redirectToRoute("article_show", ['id' => $article->getId(), 'slug' => $article->translate()->getSlug()]);
  49.         }
  50.         if(!$this->isGranted('ROLE_ADMIN') && !$article->isActive()){
  51.             return $this->redirectToRoute('article_list');
  52.         }
  53.         $articles $em->getRepository('App:Article')->getOthers($article);
  54.         return $this->render('app/article/show.html.twig', array(
  55.             'article' => $article,
  56.             'articles' => $articles
  57.         ));
  58.     }
  59. }