src/Controller/Pages/NewsController.php line 40

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Pages;
  3. use App\Controller\Objects\HomeFacebookItem;
  4. use App\Controller\Objects\Page;
  5. use App\Controller\Objects\Picture;
  6. use App\Controller\System;
  7. use App\Kernel;
  8. use App\Controller\AbstractKasController;
  9. use App\Controller\AbstractKasModel;
  10. use App\Controller\Database;
  11. use App\Controller\PageInfo;
  12. use Symfony\Bundle\FrameworkBundle\Console\Application;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\Cache\Adapter\MemcachedAdapter;
  15. use Symfony\Component\Console\Input\ArrayInput;
  16. use Symfony\Component\Console\Output\BufferedOutput;
  17. use Symfony\Component\HttpFoundation\RequestStack;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. use Symfony\Component\HttpFoundation\Response;
  20. use Symfony\VarDumper;
  21. use Doctrine\DBAL\ParameterType;
  22. class NewsController extends AbstractKasController
  23. {
  24.     public const ARTICLES_PER_PAGE 4;
  25.     public function __construct(RequestStack $requestStackDatabase $dbPageInfo $pageInfo)
  26.     {
  27.         parent::__construct($requestStack$db$pageInfo);
  28.         $this->request $requestStack->getCurrentRequest();
  29.         $this->model = new NewsModel($db);
  30.     }
  31.     /**
  32.      * @Route("/news/clanek/{link}")
  33.      * @return Response
  34.      * @throws \Facebook\Exceptions\FacebookSDKException
  35.      */
  36.     public function article(string $link ''): Response
  37.     {
  38.         $arr explode('-'$link);
  39.         $id $arr[0];
  40.         //pokud nenalezeno, tak 404
  41.         if ($link == '' || (int)$id===0) return $this->render('/pages/404.html.twig', [
  42.             'pageinfo' => $this->pageInfo
  43.         ]);
  44.         $article $this->model->getArticle($id);
  45.         if ($article->getName() == '') return $this->render('/pages/404.html.twig', [
  46.             'pageinfo' => $this->pageInfo
  47.         ]);
  48.         $img md5('webpage_21').'.news.jpg';
  49.         $folder 'www_webpages';
  50.         $picture = new Picture($folder);
  51.         $picture->setFileName($img);
  52.         $picture->setSeo('news');
  53.         $page = new Page();
  54.         $page->setTitle('NEWS');
  55.         $page->setPicture($picture);
  56.         $model = new HomeModel($this->db);
  57.         $top_events $model->getTopEvents();
  58.         $facebook_feed $model->getFacebookFeed();
  59.         $og_link getenv('APP_URL').$this->pageInfo->getActiveLink();
  60.         return $this->render('/pages/article.html.twig', [
  61.             'pageinfo' => $this->pageInfo,
  62.             'page' => $page,
  63.             'top_events' => $top_events,
  64.             'facebook_feed' => $facebook_feed,
  65.             'article' => $article,
  66.             'og_link' => $og_link,
  67.             'app_url' => getenv('APP_URL')
  68.         ]);
  69.     }
  70.     /**
  71.      * @Route("/news")
  72.      * @Route("/news/{p}")
  73.      * @Route("/news/{p}/{ajax}")
  74.      * @return Response
  75.      * @throws \Facebook\Exceptions\FacebookSDKException
  76.      */
  77.     public function page(int $p 1string $ajax ''): Response
  78.     {
  79.         //$n = $this->pageInfo->getNavbar();
  80.         //dump($n);
  81.         $link $this->request->getRequestUri();
  82.         //$objectinfo = $this->model->getObjectInfo($link);
  83.         $model = new HomeModel($this->db);
  84.         $top_events $model->getTopEvents();
  85.         $facebook_feed $model->getFacebookFeed();
  86.         //pokud nenalezeno, tak 404
  87.         /*if (!$objectinfo->isFound()) return $this->render('/pages/404.html.twig', [
  88.             'pageinfo' => $this->pageInfo
  89.         ]);*/
  90.         $img md5('webpage_21').'.news.jpg';
  91.         $folder 'www_webpages';
  92.         $picture = new Picture($folder);
  93.         $picture->setFileName($img);
  94.         $picture->setSeo('news');
  95.         $page = new Page();
  96.         $page->setTitle('NEWS');
  97.         $page->setPicture($picture);
  98.         $p_count 1;
  99.         $news $this->model->getNews($p$p_count);
  100.         $view = ($ajax=='ajax')?'/partials/news_ajax.html.twig':'/pages/news.html.twig';
  101.         return $this->render($view, [
  102.             'pageinfo' => $this->pageInfo,
  103.             'page' => $page,
  104.             'top_events' => $top_events,
  105.             'facebook_feed' => $facebook_feed,
  106.             'news' => $news,
  107.             'p' => $p,
  108.             'p_count' => $p_count
  109.         ]);
  110.     }
  111. }
  112. ?>