src/Controller/Pages/PageController.php line 45

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Pages;
  3. use App\Controller\Objects\HomeFacebookItem;
  4. use App\Controller\Objects\Picture;
  5. use App\Kernel;
  6. use App\Controller\AbstractKasController;
  7. use App\Controller\AbstractKasModel;
  8. use App\Controller\Database;
  9. use App\Controller\PageInfo;
  10. use Symfony\Bundle\FrameworkBundle\Console\Application;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\Cache\Adapter\MemcachedAdapter;
  13. use Symfony\Component\Console\Input\ArrayInput;
  14. use Symfony\Component\Console\Output\BufferedOutput;
  15. use Symfony\Component\HttpFoundation\RequestStack;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\VarDumper;
  19. use Doctrine\DBAL\ParameterType;
  20. class PageController extends AbstractKasController
  21. {
  22.     public function __construct(RequestStack $requestStackDatabase $dbPageInfo $pageInfo)
  23.     {
  24.         parent::__construct($requestStack$db$pageInfo);
  25.         $this->request $requestStack->getCurrentRequest();
  26.         $this->model = new PageModel($db);
  27.     }
  28.     /**
  29.      * @Route("/gdpr")
  30.      * @Route("/kariera")
  31.      * @Route("/poskytovani-informaci")
  32.      * @Route("/pro-media")
  33.      * @Route("/pronajem")
  34.      * @Route("/verejne-souteze")
  35.      * @Route("/verejne-zakazky")
  36.      * @Route("/tiskove-zpravy")
  37.      * @Route("/ochrana-oznamovatelu")
  38.      * @return Response
  39.      * @throws \Facebook\Exceptions\FacebookSDKException
  40.      */
  41.     public function page(): Response
  42.     {
  43.         //$n = $this->pageInfo->getNavbar();
  44.         //dump($n);
  45.         $link $this->request->getRequestUri();
  46.         $arr explode('?'$link);
  47.         $link $arr[0];
  48.         //$objectinfo = $this->model->getObjectInfo($link);
  49.         $model = new HomeModel($this->db);
  50.         $top_events $model->getTopEvents();
  51.         $facebook_feed $model->getFacebookFeed();
  52.         //pokud nenalezeno, tak 404
  53.         /*if (!$objectinfo->isFound()) return $this->render('/pages/404.html.twig', [
  54.             'pageinfo' => $this->pageInfo
  55.         ]);*/
  56.         $page $this->model->getPageInfo($link);
  57.         $filename str_replace('/'''$link.'.html');
  58.         $filename str_replace('-''_'$filename);
  59.         $html $this->getHTML($filename);
  60.         return $this->render('/pages/page.html.twig', [
  61.             'pageinfo' => $this->pageInfo,
  62.             'page' => $page,
  63.             'top_events' => $top_events,
  64.             'facebook_feed' => $facebook_feed,
  65.             'html' => $html
  66.         ]);
  67.     }
  68.     /**
  69.      * @Route("/archiv")
  70.      * @return Response
  71.      * @throws \Facebook\Exceptions\FacebookSDKException
  72.      */
  73.     public function archiv(): Response
  74.     {
  75.         //$n = $this->pageInfo->getNavbar();
  76.         //dump($n);
  77.         $link $this->request->getRequestUri();
  78.         //$objectinfo = $this->model->getObjectInfo($link);
  79.         $model = new HomeModel($this->db);
  80.         $top_events $model->getTopEvents();
  81.         $facebook_feed $model->getFacebookFeed();
  82.         //pokud nenalezeno, tak 404
  83.         /*if (!$objectinfo->isFound()) return $this->render('/pages/404.html.twig', [
  84.             'pageinfo' => $this->pageInfo
  85.         ]);*/
  86.         $page $this->model->getPageInfo($link);
  87.         $filename str_replace('/'''$link.'.html');
  88.         $filename str_replace('-''_'$filename);
  89.         $html $this->getHTML($filename);
  90.         return $this->render('/pages/archive.html.twig', [
  91.             'pageinfo' => $this->pageInfo,
  92.             'page' => $page,
  93.             'top_events' => $top_events,
  94.             'facebook_feed' => $facebook_feed,
  95.             'html' => $html
  96.         ]);
  97.     }
  98.     private function getHTML(string $filename): string {
  99.         $file getenv('APP_DIR').'private/data/files/www_html/'.$filename;
  100.         if (file_exists($file)) {
  101.             return file_get_contents($file);
  102.         }
  103.         return '';
  104.     }
  105.     /**
  106.      * @Route("/vyhledat", methods={"GET"})
  107.      * @return Response
  108.      * @throws \Facebook\Exceptions\FacebookSDKException
  109.      */
  110.     public function search(): Response
  111.     {
  112.         //$n = $this->pageInfo->getNavbar();
  113.         //dump($n);
  114.         $q trim($this->request->query->get('q'''));
  115.         $model = new HomeModel($this->db);
  116.         $top_events $model->getTopEvents();
  117.         $facebook_feed $model->getFacebookFeed();
  118.         //pokud nenalezeno, tak 404
  119.         /*if (!$objectinfo->isFound()) return $this->render('/pages/404.html.twig', [
  120.             'pageinfo' => $this->pageInfo
  121.         ]);*/
  122.         $page $this->model->getPageInfo('/poskytovani-informaci');
  123.         $page->setTitle('Vyhledávání');
  124.         $data $this->model->search($q);
  125.         return $this->render('/pages/search.html.twig', [
  126.             'q' => $q,
  127.             'data' => $data,
  128.             'pageinfo' => $this->pageInfo,
  129.             'page' => $page,
  130.             'top_events' => $top_events,
  131.             'facebook_feed' => $facebook_feed
  132.         ]);
  133.     }
  134. }
  135. ?>