<?php
namespace App\Controller\Pages;
use App\Controller\Objects\HomeFacebookItem;
use App\Controller\Objects\Picture;
use App\Kernel;
use App\Controller\AbstractKasController;
use App\Controller\AbstractKasModel;
use App\Controller\Database;
use App\Controller\PageInfo;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Cache\Adapter\MemcachedAdapter;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\VarDumper;
use Doctrine\DBAL\ParameterType;
class PageController extends AbstractKasController
{
public function __construct(RequestStack $requestStack, Database $db, PageInfo $pageInfo)
{
parent::__construct($requestStack, $db, $pageInfo);
$this->request = $requestStack->getCurrentRequest();
$this->model = new PageModel($db);
}
/**
* @Route("/gdpr")
* @Route("/kariera")
* @Route("/poskytovani-informaci")
* @Route("/pro-media")
* @Route("/pronajem")
* @Route("/verejne-souteze")
* @Route("/verejne-zakazky")
* @Route("/tiskove-zpravy")
* @Route("/ochrana-oznamovatelu")
* @return Response
* @throws \Facebook\Exceptions\FacebookSDKException
*/
public function page(): Response
{
//$n = $this->pageInfo->getNavbar();
//dump($n);
$link = $this->request->getRequestUri();
$arr = explode('?', $link);
$link = $arr[0];
//$objectinfo = $this->model->getObjectInfo($link);
$model = new HomeModel($this->db);
$top_events = $model->getTopEvents();
$facebook_feed = $model->getFacebookFeed();
//pokud nenalezeno, tak 404
/*if (!$objectinfo->isFound()) return $this->render('/pages/404.html.twig', [
'pageinfo' => $this->pageInfo
]);*/
$page = $this->model->getPageInfo($link);
$filename = str_replace('/', '', $link.'.html');
$filename = str_replace('-', '_', $filename);
$html = $this->getHTML($filename);
return $this->render('/pages/page.html.twig', [
'pageinfo' => $this->pageInfo,
'page' => $page,
'top_events' => $top_events,
'facebook_feed' => $facebook_feed,
'html' => $html
]);
}
/**
* @Route("/archiv")
* @return Response
* @throws \Facebook\Exceptions\FacebookSDKException
*/
public function archiv(): Response
{
//$n = $this->pageInfo->getNavbar();
//dump($n);
$link = $this->request->getRequestUri();
//$objectinfo = $this->model->getObjectInfo($link);
$model = new HomeModel($this->db);
$top_events = $model->getTopEvents();
$facebook_feed = $model->getFacebookFeed();
//pokud nenalezeno, tak 404
/*if (!$objectinfo->isFound()) return $this->render('/pages/404.html.twig', [
'pageinfo' => $this->pageInfo
]);*/
$page = $this->model->getPageInfo($link);
$filename = str_replace('/', '', $link.'.html');
$filename = str_replace('-', '_', $filename);
$html = $this->getHTML($filename);
return $this->render('/pages/archive.html.twig', [
'pageinfo' => $this->pageInfo,
'page' => $page,
'top_events' => $top_events,
'facebook_feed' => $facebook_feed,
'html' => $html
]);
}
private function getHTML(string $filename): string {
$file = getenv('APP_DIR').'private/data/files/www_html/'.$filename;
if (file_exists($file)) {
return file_get_contents($file);
}
return '';
}
/**
* @Route("/vyhledat", methods={"GET"})
* @return Response
* @throws \Facebook\Exceptions\FacebookSDKException
*/
public function search(): Response
{
//$n = $this->pageInfo->getNavbar();
//dump($n);
$q = trim($this->request->query->get('q', ''));
$model = new HomeModel($this->db);
$top_events = $model->getTopEvents();
$facebook_feed = $model->getFacebookFeed();
//pokud nenalezeno, tak 404
/*if (!$objectinfo->isFound()) return $this->render('/pages/404.html.twig', [
'pageinfo' => $this->pageInfo
]);*/
$page = $this->model->getPageInfo('/poskytovani-informaci');
$page->setTitle('Vyhledávání');
$data = $this->model->search($q);
return $this->render('/pages/search.html.twig', [
'q' => $q,
'data' => $data,
'pageinfo' => $this->pageInfo,
'page' => $page,
'top_events' => $top_events,
'facebook_feed' => $facebook_feed
]);
}
}
?>