<?php
namespace App\Controller\Pages;
use App\Controller\Objects\HomeFacebookItem;
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\BinaryFileResponse;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\VarDumper;
use Doctrine\DBAL\ParameterType;
class ObjectController extends AbstractKasController
{
public function __construct(RequestStack $requestStack, Database $db, PageInfo $pageInfo)
{
parent::__construct($requestStack, $db, $pageInfo);
$this->request = $requestStack->getCurrentRequest();
$this->model = new ObjectModel($db);
}
/**
* @Route("/vbazenu")
* @return \HttpResponse
* @throws \ErrorException
* @throws \Psr\Cache\InvalidArgumentException
* @throws \Symfony\Component\Cache\Exception\CacheException
*/
public function vbazenu():Response {
$client = MemcachedAdapter::createConnection(getenv('MC_SRV'));
$cache = new MemcachedAdapter($client, 'vbazenu', 0);
$item = $cache->getItem('cache_vbazenu');
if (!$item->isHit()) {
/*$aqualink = 'http://78.111.121.60:2001/SystemConnector/GetZoneInfo';
$ch = curl_init();
$optArray = array(
CURLOPT_URL => $aqualink,
CURLOPT_RETURNTRANSFER => true
);
curl_setopt_array($ch, $optArray);
$result = curl_exec($ch);
$json = json_decode($result, true);
$count = (int)$json[0]['PeopleCount'];*/
$count = rand(0, 50);
$item
->set($count)
->expiresAfter(60); // in seconds
$cache->save($item);
} else {
$count = $item->get();
}
return new Response($count);
}
/**
* @Route("/zimni-stadion-rocknet-arena/fotogalerie")
* @Route("/fotbalovy-stadion/fotogalerie")
* @Route("/aquasvet/fotogalerie")
* @Route("/kino-svet/fotogalerie")
* @Route("/mestske-divadlo/fotogalerie")
* @Route("/mestska-sportovni-hala/fotogalerie")
* @Route("/atleticky-stadion/fotogalerie")
* @Route("/in-line-draha/fotogalerie")
* @Route("/sportovni-areal-tomase-ze-stitneho/fotogalerie")
* @Route("/letni-kino/fotogalerie")
* @Route("/hriste/fotogalerie")
* @Route("/zimni-stadion-treninkova-hala/fotogalerie")
* @return Response
* @throws \Facebook\Exceptions\FacebookSDKException
*/
public function fotogalerie(): Response
{
//$n = $this->pageInfo->getNavbar();
//dump($n);
$link = $this->request->getRequestUri();
$link = str_replace('/fotogalerie', '', $link);
$objectinfo = $this->model->getObjectInfo($link);
//pokud nenalezeno, tak 404
if (!$objectinfo->isFound()) return $this->render('/pages/404.html.twig', [
'pageinfo' => $this->pageInfo
]);
$model = new HomeModel($this->db);
$top_events = $model->getTopEvents(); //dump($top_events);
$facebook_feed = $model->getFacebookFeed();
return $this->render('/pages/gallery.html.twig', [
'pageinfo' => $this->pageInfo,
'objectinfo' => $objectinfo,
'top_events' => $top_events,
'facebook_feed' => $facebook_feed
]);
}
/**
* @Route("/zimni-stadion-rocknet-arena")
* @Route("/fotbalovy-stadion")
* @Route("/aquasvet")
* @Route("/kino-svet")
* @Route("/mestske-divadlo")
* @Route("/mestska-sportovni-hala")
* @Route("/atleticky-stadion")
* @Route("/in-line-draha")
* @Route("/sportovni-areal-tomase-ze-stitneho")
* @Route("/letni-kino")
* @Route("/hriste")
* @Route("/zimni-stadion-treninkova-hala")
* @Route("/zarizeni/zimni-stadion-rocknet-arena")
* @Route("/zarizeni/fotbalovy-stadion")
* @Route("/zarizeni/aquasvet")
* @Route("/zarizeni/kino-svet")
* @Route("/zarizeni/mestske-divadlo")
* @Route("/zarizeni/mestska-sportovni-hala")
* @Route("/zarizeni/atleticky-stadion")
* @Route("/zarizeni/in-line-draha")
* @Route("/zarizeni/sportovni-areal-tomase-ze-stitneho")
* @Route("/zarizeni/letni-kino")
* @Route("/zarizeni/hriste")
* @Route("/zarizeni/zimni-stadion-treninkova-hala")
* @return Response
* @throws \Facebook\Exceptions\FacebookSDKException
*/
public function object(): Response
{
//$n = $this->pageInfo->getNavbar();
//dump($n);
$link = $this->request->getRequestUri();
if (str_starts_with($link, '/zarizeni')) {
$link = str_replace('/zarizeni/', '/', $link);
}
$objectinfo = $this->model->getObjectInfo($link);
//pokud nenalezeno, tak 404
if (!$objectinfo->isFound()) return $this->render('/pages/404.html.twig', [
'pageinfo' => $this->pageInfo
]);
$html = $objectinfo->getHtml(); //files/www_html
$html2 = $objectinfo->getHtml2();
/*if ($html=='' && $html2=='') $twig = '/pages/object2.html.twig';
else*/ $twig = '/pages/object.html.twig';
return $this->render($twig, [
'pageinfo' => $this->pageInfo,
'objectinfo' => $objectinfo,
'html' => $html,
'html2' => $html2
]);
}
/**
* @Route("/soubor-{id64}")
* @return Response
* @throws \Facebook\Exceptions\FacebookSDKException
*/
public function download($id64): Response
{
$id = base64_decode($id64);
$id = substr($id, 4, -4);
if ((int)$id==0) return $this->render('/pages/404.html.twig', [
'pageinfo' => $this->pageInfo
]);
$filename = $folder = '';
$this->model->getFileInfo($id, $filename, $folder);
if ($filename == '' || $folder == '') {
return $this->render('/pages/404.html.twig', [
'pageinfo' => $this->pageInfo
]);
}
$file_path = getenv('APP_DIR').'private/data/files/www_objects/'.$folder.'/'.$filename;
if (!file_exists($file_path)) {
return $this->render('/pages/404.html.twig', [
'pageinfo' => $this->pageInfo
]);
}
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file_path));
ob_clean();
flush();
readfile($file_path);
exit();
}
}
?>