<?php
namespace App\Controller\Pages;
use App\Controller\Objects\HomeFacebookItem;
use App\Controller\Objects\Page;
use App\Controller\Objects\Picture;
use App\Controller\System;
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 NewsController extends AbstractKasController
{
public const ARTICLES_PER_PAGE = 4;
public function __construct(RequestStack $requestStack, Database $db, PageInfo $pageInfo)
{
parent::__construct($requestStack, $db, $pageInfo);
$this->request = $requestStack->getCurrentRequest();
$this->model = new NewsModel($db);
}
/**
* @Route("/news/clanek/{link}")
* @return Response
* @throws \Facebook\Exceptions\FacebookSDKException
*/
public function article(string $link = ''): Response
{
$arr = explode('-', $link);
$id = $arr[0];
//pokud nenalezeno, tak 404
if ($link == '' || (int)$id===0) return $this->render('/pages/404.html.twig', [
'pageinfo' => $this->pageInfo
]);
$article = $this->model->getArticle($id);
if ($article->getName() == '') return $this->render('/pages/404.html.twig', [
'pageinfo' => $this->pageInfo
]);
$img = md5('webpage_21').'.news.jpg';
$folder = 'www_webpages';
$picture = new Picture($folder);
$picture->setFileName($img);
$picture->setSeo('news');
$page = new Page();
$page->setTitle('NEWS');
$page->setPicture($picture);
$model = new HomeModel($this->db);
$top_events = $model->getTopEvents();
$facebook_feed = $model->getFacebookFeed();
$og_link = getenv('APP_URL').$this->pageInfo->getActiveLink();
return $this->render('/pages/article.html.twig', [
'pageinfo' => $this->pageInfo,
'page' => $page,
'top_events' => $top_events,
'facebook_feed' => $facebook_feed,
'article' => $article,
'og_link' => $og_link,
'app_url' => getenv('APP_URL')
]);
}
/**
* @Route("/news")
* @Route("/news/{p}")
* @Route("/news/{p}/{ajax}")
* @return Response
* @throws \Facebook\Exceptions\FacebookSDKException
*/
public function page(int $p = 1, string $ajax = ''): 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
]);*/
$img = md5('webpage_21').'.news.jpg';
$folder = 'www_webpages';
$picture = new Picture($folder);
$picture->setFileName($img);
$picture->setSeo('news');
$page = new Page();
$page->setTitle('NEWS');
$page->setPicture($picture);
$p_count = 1;
$news = $this->model->getNews($p, $p_count);
$view = ($ajax=='ajax')?'/partials/news_ajax.html.twig':'/pages/news.html.twig';
return $this->render($view, [
'pageinfo' => $this->pageInfo,
'page' => $page,
'top_events' => $top_events,
'facebook_feed' => $facebook_feed,
'news' => $news,
'p' => $p,
'p_count' => $p_count
]);
}
}
?>