<?php
namespace App\Controller;
use App\Entity\User;
use Maris\CmsBundle\Entity\Post;
use Maris\CmsBundle\Helper\PostMetaHelper;
use Maris\CmsBundle\Repository\ModuleRepository;
use Maris\CmsBundle\Repository\PostMetaRepository;
use Maris\CmsBundle\Repository\PostRepository;
use Maris\CmsBundle\Service\FileService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
class DefaultController extends AbstractController
{
private PostRepository $post;
private PostMetaHelper $postMetaHelper;
private PostMetaRepository $postMeta;
private ModuleRepository $module;
private FileService $fileService;
private array $pageHeaders;
private array $menuBottom;
private $passwordEncoder;
/**
* DefaultController constructor.
* @param PostRepository $post
* @param PostMetaHelper $postMetaHelper;
* @param PostMetaRepository $postMeta
* @param ModuleRepository $module
* @param FileService $fileService
*/
public function __construct(PostRepository $post, PostMetaRepository $postMeta, PostMetaHelper $postMetaHelper, ModuleRepository $module, FileService $fileService,UserPasswordEncoderInterface $passwordEncoder)
{
$this->passwordEncoder = $passwordEncoder;
$this->post = $post;
$this->postMetaHelper = $postMetaHelper;
$this->postMeta = $postMeta;
$this->module = $module;
$this->fileService = $fileService;
$pagehead = array('pagetitle' => '','description' => '','keywords' =>'');
$ph = $this->post ->findBy(['id' => '1']);
$ph =current($ph);
$pagehead['mainLogo'] = $this -> fileService -> getFileByPostAndFieldName($ph, 'mpPartners', 'true');
$k = key($pagehead['mainLogo']);
$pagehead['mainLogo'] = current($pagehead['mainLogo']);
$pagehead['mainLogos'] = $this -> fileService -> getFileByPostAndFieldName($ph, 'mpPartners');
$galret = array();
foreach ($pagehead['mainLogos'] as $key => $g) {
if($key != $k) {
$galret[] = $g;
}
}
$pagehead['mainLogos'] = $galret;
$ph1 = $this->postMeta->findby(['post' => '1']);
foreach ($ph1 as $p) $pagehead[$p->getFieldName()] = $p->getContent();
$menuTop = 0;
if($pagehead['mtShowFcb'] == 'Tak' && !empty($pagehead['mtFcbLink']) && $pagehead['mtFcbLink'] != '') {
$menuTop = 1;
}
if($pagehead['mtShowInsta'] == 'Tak' && !empty($pagehead['mtInstaLink']) && $pagehead['mtInstaLink'] != '') {
$menuTop = 1;
}
if($pagehead['mtShowYT'] == 'Tak' && !empty($pagehead['mtYTLink']) && $pagehead['mtYTLink'] != '') {
$menuTop = 1;
}
$pagehead['menuTopVisible'] = $menuTop;
$this -> pageHeaders = $pagehead;
$this->siteURL = $_ENV['SITE_URL'];
$trescModule = $this -> module ->find(['id' => '2']);
$this -> menuBottom = $this -> post -> findBy(['module' => $trescModule, 'status' => 'A'],['position' => 'DESC']);
}
#[Route('/', name: 'root')]
public function index(): Response
{
$sliderModule = $this->module->find(['id' => '3']);
$slider = $this -> post -> findBy(['module' => $sliderModule, 'status' => 'A'],['position' => 'DESC']);
$sliderRet = array();
foreach ($slider as $s) {
$tmp['post'] = $s;
$tmp['meta'] = $this -> postMetaHelper -> parsePost($s);
$tmp['slide'] = $this -> fileService -> getFileByPostAndFieldName($s, 'slideImage', true);
$tmp['slide'] = current($tmp['slide']);
$sliderRet[] = $tmp;
unset($tmp);
}
$newsModule = $this->module->findBy(['id' => '4']);
$news = $this -> post -> findBy(['module' => $newsModule, 'status'=>'A'],['position'=>'DESC'],4);
$newsRetMain = '';
$newsRet = array();
foreach ($news as $key => $n) {
$tmp['post'] = $n;
$tmp['meta'] = $this -> postMetaHelper -> parsePost($n);
$tmp['galeriaMain'] = $this -> fileService->getFileByPostAndFieldName($n, 'galery', true);
$tmp['galeriaMain'] = current($tmp['galeriaMain']);
$tmp['galeria'] = $this -> fileService -> getFileByPostAndFieldName($n, 'galery');
if ($key === array_key_first($news)) {
$newsRetMain = $tmp;
} else {
$newsRet[] = $tmp;
}
unset($tmp);
}
return $this -> render('site/index.html.twig',[
'pagehead' => $this -> pageHeaders,
'siteURL' => $this -> siteURL,
'menuBottom' => $this -> menuBottom,
'slider' => $sliderRet,
'newsMain' => $newsRetMain,
'news' => $newsRet
]);
}
#[Route('/read/{slug}', name: 'post')]
public function singlepost(?Post $post, Request $request): Response
{
$meta = $this->postMetaHelper->parsePost($post);
$mp = $this->fileService->getFileByPostAndFieldName($post, 'galery', true);
$k = key($mp);
$mp = current($mp);
$galery = $this->fileService->getFileByPostAndFieldName($post, 'galery');
$galret = array();
foreach ($galery as $key => $g) {
if($key != $k) {
$galret[] = $g;
}
}
$galret = (!empty($galret) && $galret !='') ? $galret : '';
return $this->render('site/singlepost.html.twig', [
'pagehead' => $this -> pageHeaders,
'siteURL' => $this -> siteURL,
'menuBottom' => $this -> menuBottom,
'mainphoto' => $mp,
'galery' => $galret,
'meta' => $meta,
'post' => $post
]);
}
#[Route('/news/{slug}', name: 'news')]
public function singlenews(?Post $post, Request $request): Response
{
$meta = $this->postMetaHelper->parsePost($post);
$mp = $this->fileService->getFileByPostAndFieldName($post, 'galery', true);
$k = key($mp);
$mp = current($mp);
$galery = $this->fileService->getFileByPostAndFieldName($post, 'galery');
$galret = array();
foreach ($galery as $key => $g) {
if($key != $k) {
$galret[] = $g;
}
}
$galret = (!empty($galret) && $galret !='') ? $galret : '';
return $this->render('site/singlenews.html.twig', [
'pagehead' => $this -> pageHeaders,
'siteURL' => $this -> siteURL,
'menuBottom' => $this -> menuBottom,
'mainphoto' => $mp,
'galery' => $galret,
'meta' => $meta,
'post' => $post
]);
}
}