vendor/score/cms/src/Controller/Article/PublicController.php line 24

Open in your IDE?
  1. <?php
  2. namespace  Score\CmsBundle\Controller\Article;
  3. use Score\CmsBundle\Entity\Article;
  4. use Score\BaseBundle\Services\Pager;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Score\CmsBundle\Services\StatManager;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. /**
  12.  * @Route("/clanky")
  13.  */
  14. class PublicController extends AbstractController
  15. {
  16.     /**
  17.      * @Route("/", name="score_public_articles_list", methods={"GET"})
  18.      */
  19.     public function listAction(Request $request,EntityManagerInterface $entityManager,Pager $pager): Response
  20.     {
  21.         $repo $entityManager->getRepository(Article::class);
  22.         $page $request->get('p'1);
  23.         $pageSize $request->get('size'6);
  24.         $articles $repo->findArticlesByPage(array('page' => $page'pageSize' => $pageSize),['visible' => true]);
  25.         $articleList array_chunk($articles['list'],3);
  26.         $pager->setUrl($request->getUri());
  27.         $pager->setItemsPerPage($pageSize);
  28.         $pager->setCount($articles['total']);
  29.         $pager->setPage($page);
  30.         $pager->getPages();
  31.        
  32.         return $this->render('@ScoreCms/Public/default/article_list.html.twig', [
  33.             'articleList' => $articleList,
  34.             'pager' => $pager,
  35.         ]);
  36.     }
  37.     /**
  38.      * @Route("/{slug}", name="score_public_articles_detail", methods={"GET"})
  39.      */
  40.     public function detailAction(EntityManagerInterface $entityManager,$slug null): Response
  41.     {
  42.         $repo $entityManager->getRepository(Article::class);
  43.         $article $repo->findOneBy(['slug' => $slug]);
  44.         $responseCode 200;
  45.         if(null == $article)
  46.         {
  47.                $article = new Article();
  48.                $article->setName('404');
  49.                $article->setBody('Tento článok sa tu nenachádza');
  50.                $responseCode 404;
  51.         }
  52.         $topArticles $repo->findSidebarArticles($article);
  53.         return new Response($this->renderView('@ScoreCms/Public/default/article_detail.html.twig', [
  54.             'article' => $article,
  55.             'articles' => $topArticles,
  56.         ]), $responseCode);
  57.         
  58.       
  59.     }
  60. }