src/Controller/HomepageController.php line 113

  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Articles;
  4. use App\Entity\Message;
  5. use App\Form\MessageType;
  6. use App\Repository\ArticlesRepository;
  7. use App\Repository\DownloadableRepository;
  8. use App\Repository\MenuRepository;
  9. use App\Repository\MessageRepository;
  10. use App\Repository\PageContentRepository;
  11. use App\Repository\PhotoGalleryRepository;
  12. use App\Service\ArticlesService;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. class HomepageController extends AbstractController
  18. {
  19.     public function __construct(
  20.         public readonly ArticlesRepository $articlesRepository,
  21.         public readonly MenuRepository $menuRepository,
  22.         public readonly DownloadableRepository $downloadableRepository,
  23.         public readonly PageContentRepository $pageContentRepository,
  24.         public readonly PhotoGalleryRepository $photoGalleryRepository,
  25.     )
  26.     {
  27.     }
  28.     #[Route(path'/'name'homepage')]
  29.     public function index(Request $requestMessageRepository $messageRepository):Response
  30.     {
  31.         $message = new Message();
  32.         $form $this->createForm(MessageType::class, $message);
  33.         $aboutUs $this->pageContentRepository->findOneBy(['headline' => 'Úvod']);
  34.         $articles $this->articlesRepository->findBy(['active' => true],['createdAt' => 'DESC'],6);
  35.         $form->handleRequest($request);
  36.         if ($form->isSubmitted() && $form->isValid()) {
  37.             $messageRepository->save($messagetrue);
  38.             return $this->redirectToRoute('homepage', [], Response::HTTP_SEE_OTHER);
  39.         }
  40.         return $this->render('frontend/index.html.twig',[
  41.             'form' => $form,
  42.             'articles' => $articles,
  43.             'aboutUs' => $aboutUs,
  44.         ]);
  45.     }
  46.     #[Route(path'/menu'name'frontend-menu')]
  47.     public function menu():Response
  48.     {
  49.         $menu $this->menuRepository->getByDate(new \DateTime());
  50.         return $this->render('frontend/menu.html.twig',[
  51.             'menu' => $menu,
  52.         ]);
  53.     }
  54.     #[Route(path'/forParents'name'forParents')]
  55.     public function kids():Response
  56.     {
  57.         $forParents $this->pageContentRepository->findOneBy(['headline' => 'Co děti potřebují']);
  58.         return $this->render('frontend/forParents.html.twig',[
  59.             'forParents' => $forParents,
  60.         ]);
  61.     }
  62.     #[Route(path'/daySchedule'name'daySchedule')]
  63.     public function day():Response
  64.     {
  65.         $forParents $this->pageContentRepository->findOneBy(['headline' => 'Organizace dne']);
  66.         return $this->render('frontend/forParents-day.html.twig',[
  67.             'forParents' => $forParents,
  68.         ]);
  69.     }
  70.     #[Route(path'/homeEducation'name'homeEducation')]
  71.     public function homeEducation():Response
  72.     {
  73.         $forParents $this->pageContentRepository->findOneBy(['headline' => 'Domácí vzdělávání']);
  74.         return $this->render('frontend/forParents-home.html.twig',[
  75.             'forParents' => $forParents,
  76.         ]);
  77.     }
  78.     #[Route(path'/download'name'download')]
  79.     public function download():Response
  80.     {
  81.         $files $this->downloadableRepository->findBy(['isActive' => true,'isRegistration' => false|null]);
  82.         $filesRegistration $this->downloadableRepository->findBy(['isActive' => true'isRegistration' => true]);
  83.         return $this->render('frontend/download.html.twig',[
  84.             'files' => $files,
  85.             'filesRegistration' => $filesRegistration
  86.         ]);
  87.     }
  88.     #[Route(path'/news'name'news')]
  89.     public function news():Response
  90.     {
  91.         $articles $this->articlesRepository->findBy(['active' => true]);
  92.         return $this->render('frontend/news.html.twig',[
  93.             'articles' => $articles,
  94.         ]);
  95.     }
  96.     #[Route(path'/news/{article}'name'new')]
  97.     public function new(Articles $article):Response
  98.     {
  99.         return $this->render('frontend/news-detail.html.twig',[
  100.             'article' => $article,
  101.         ]);
  102.     }
  103.     #[Route(path'/gallery'name'gallery')]
  104.     public function gallery():Response
  105.     {
  106.         $gallery $this->photoGalleryRepository->findBy(['isActive' => true]);
  107.         return $this->render('frontend/gallery.html.twig',[
  108.             'gallery' => $gallery
  109.         ]);
  110.     }
  111.     #[Route(path'/classes'name'classes')]
  112.     public function classes():Response
  113.     {
  114.         $classes $this->pageContentRepository->findOneBy(['headline' => 'Třídy']);
  115.         return $this->render('frontend/classes.html.twig',[
  116.             'classes' => $classes
  117.         ]);
  118.     }
  119.     #[Route(path'/aboutUs'name'about_us')]
  120.     public function aboutUs():Response
  121.     {
  122.         $aboutUs $this->pageContentRepository->findOneBy(['headline' => 'O nás']);
  123.         return $this->render('frontend/aboutUs.html.twig',[
  124.             'aboutUs' => $aboutUs
  125.         ]);
  126.     }
  127. }