src/Controller/HomepageController.php line 113
<?php
namespace App\Controller;
use App\Entity\Articles;
use App\Entity\Message;
use App\Form\MessageType;
use App\Repository\ArticlesRepository;
use App\Repository\DownloadableRepository;
use App\Repository\MenuRepository;
use App\Repository\MessageRepository;
use App\Repository\PageContentRepository;
use App\Repository\PhotoGalleryRepository;
use App\Service\ArticlesService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class HomepageController extends AbstractController
{
public function __construct(
public readonly ArticlesRepository $articlesRepository,
public readonly MenuRepository $menuRepository,
public readonly DownloadableRepository $downloadableRepository,
public readonly PageContentRepository $pageContentRepository,
public readonly PhotoGalleryRepository $photoGalleryRepository,
)
{
}
#[Route(path: '/', name: 'homepage')]
public function index(Request $request, MessageRepository $messageRepository):Response
{
$message = new Message();
$form = $this->createForm(MessageType::class, $message);
$aboutUs = $this->pageContentRepository->findOneBy(['headline' => 'Úvod']);
$articles = $this->articlesRepository->findBy(['active' => true],['createdAt' => 'DESC'],6);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$messageRepository->save($message, true);
return $this->redirectToRoute('homepage', [], Response::HTTP_SEE_OTHER);
}
return $this->render('frontend/index.html.twig',[
'form' => $form,
'articles' => $articles,
'aboutUs' => $aboutUs,
]);
}
#[Route(path: '/menu', name: 'frontend-menu')]
public function menu():Response
{
$menu = $this->menuRepository->getByDate(new \DateTime());
return $this->render('frontend/menu.html.twig',[
'menu' => $menu,
]);
}
#[Route(path: '/forParents', name: 'forParents')]
public function kids():Response
{
$forParents = $this->pageContentRepository->findOneBy(['headline' => 'Co děti potřebují']);
return $this->render('frontend/forParents.html.twig',[
'forParents' => $forParents,
]);
}
#[Route(path: '/daySchedule', name: 'daySchedule')]
public function day():Response
{
$forParents = $this->pageContentRepository->findOneBy(['headline' => 'Organizace dne']);
return $this->render('frontend/forParents-day.html.twig',[
'forParents' => $forParents,
]);
}
#[Route(path: '/homeEducation', name: 'homeEducation')]
public function homeEducation():Response
{
$forParents = $this->pageContentRepository->findOneBy(['headline' => 'Domácí vzdělávání']);
return $this->render('frontend/forParents-home.html.twig',[
'forParents' => $forParents,
]);
}
#[Route(path: '/download', name: 'download')]
public function download():Response
{
$files = $this->downloadableRepository->findBy(['isActive' => true,'isRegistration' => false|null]);
$filesRegistration = $this->downloadableRepository->findBy(['isActive' => true, 'isRegistration' => true]);
return $this->render('frontend/download.html.twig',[
'files' => $files,
'filesRegistration' => $filesRegistration
]);
}
#[Route(path: '/news', name: 'news')]
public function news():Response
{
$articles = $this->articlesRepository->findBy(['active' => true]);
return $this->render('frontend/news.html.twig',[
'articles' => $articles,
]);
}
#[Route(path: '/news/{article}', name: 'new')]
public function new(Articles $article):Response
{
return $this->render('frontend/news-detail.html.twig',[
'article' => $article,
]);
}
#[Route(path: '/gallery', name: 'gallery')]
public function gallery():Response
{
$gallery = $this->photoGalleryRepository->findBy(['isActive' => true]);
return $this->render('frontend/gallery.html.twig',[
'gallery' => $gallery
]);
}
#[Route(path: '/classes', name: 'classes')]
public function classes():Response
{
$classes = $this->pageContentRepository->findOneBy(['headline' => 'Třídy']);
return $this->render('frontend/classes.html.twig',[
'classes' => $classes
]);
}
#[Route(path: '/aboutUs', name: 'about_us')]
public function aboutUs():Response
{
$aboutUs = $this->pageContentRepository->findOneBy(['headline' => 'O nás']);
return $this->render('frontend/aboutUs.html.twig',[
'aboutUs' => $aboutUs
]);
}
}