src/Controller/Frontend/DefaultController.php line 87

  1. <?php
  2. namespace App\Controller\Frontend;
  3. use App\Entity\Content\News;
  4. use App\Entity\Content\StaticPage;
  5. use App\Entity\Forms\Support;
  6. use App\Entity\Geo\District;
  7. use App\Entity\Organisation\Organisation;
  8. use App\Forms\Types\Forms\SupportType;
  9. use App\Service\Olympiads\Provider;
  10. use Doctrine\ORM\EntityManagerInterface;
  11. use Knp\Component\Pager\PaginatorInterface;
  12. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
  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. use Vich\UploaderBundle\Handler\DownloadHandler;
  18. class DefaultController extends AbstractController
  19. {
  20.     /**
  21.      * @var EntityManagerInterface
  22.      */
  23.     private $em;
  24.     public function __construct(EntityManagerInterface $em)
  25.     {
  26.         $this->em $em;
  27.     }
  28.     /**
  29.      * @ Route("/", name="main")
  30.      * @ Route("/main", name="real_main")
  31.      *
  32.      */
  33.     public function index(PaginatorInterface $paginatorProvider $provider)
  34.     {
  35.         $news_params $this->getParameter('news');
  36.         $olympiads_params $this->getParameter('olympiads');
  37.         $news $this->em->getRepository(News::class)->findNews($news_params['main_page_news']);
  38.         $events $this->em->getRepository(News::class)->findEventsMainPage($news_params['main_page_events']);
  39.         $olympCategories $provider->findMainPage();
  40.         $olympCount $provider->findMainPageTotal();
  41.         $olympTypes $provider->findMainPageLevels();
  42. //        dump($olympTypes);
  43.         $orgCategories $this->em->getRepository(\App\Entity\Organisation\University\Category::class)->findMainPage(Organisation::TYPE_VUZ);
  44.         $vuzCount $this->em->getRepository(Organisation::class)->findMainPageTotal(Organisation::TYPE_VUZ);
  45. //        dump($orgCategories);
  46.         $districts $this->em->getRepository(District::class)->findMainPage();
  47. //        $olympiads = $paginator->paginate($this->em->getRepository(Olympiad::class)->mainListQb(),1,$olympiads_params['main_page_count']);
  48. //        dump($news);
  49.         return $this->render(
  50.             'default/index.html.twig',
  51.             [
  52.                 'news' => $news,
  53.                 'events' => $events,
  54.                 'olympCategories' => $olympCategories,
  55.                 'orgCategories' => $orgCategories,
  56.                 'vuzCount' => $vuzCount,
  57.                 'districts' => $districts,
  58.                 'olympTypes' => $olympTypes,
  59.                 'olympCount' => $olympCount,
  60.             ]
  61.         );
  62.     }
  63.     #[Route(path'/file/{id}/{filename}'name'content_file')]
  64.     #[Cache(expires'+30 days', public: truelastModified'file.getCreatedAt()'etag"'st_image' ~ file.getId() ~ file.getCreatedAt().getTimestamp()")]
  65.     public function content_file(\App\Entity\Common\File $file$filenameDownloadHandler $downloadHandler): Response
  66.     {
  67.         if ($file->isPublic() === false) {
  68.             throw $this->createAccessDeniedException();
  69.         }
  70. //        return new Response();
  71.         try {
  72.             $resp $downloadHandler->downloadObject(
  73.                 $file,
  74.                 'file',
  75.                 null,
  76.                 true,
  77.                 false
  78.             );
  79.         } catch (\Vich\UploaderBundle\Exception\NoFileFoundException) {
  80.             throw $this->createNotFoundException();
  81.         }
  82.         $resp->headers->set('content-type', [$file->getData()->getMimeType()]);
  83.         return $resp;
  84.     }
  85.     /**
  86.      * @param StaticPage $page
  87.      * @return \Symfony\Component\HttpFoundation\Response
  88.      */
  89.     #[Route(path'/s/{url}'name'static-page')]
  90.     public function staticPageAction(StaticPage $page): Response
  91.     {
  92.         /* $page = $this->getDoctrine()->getRepository(StaticPage::class)->findOneBy(['url' => $url]);
  93. */
  94.         if ($page->isInternal()) {
  95.             throw $this->createNotFoundException();
  96.             //return $this->redirect('/'.$url);
  97.         }
  98.         return $this->render(
  99.             'static/static.html.twig',
  100.             [
  101.                 'page' => $page,
  102.             ]
  103.         );
  104.     }
  105.     #[Route(name'support_page'path'/support')]
  106.     public function support(Request $requestEntityManagerInterface $em)
  107.     {
  108.         $page $em->getRepository(StaticPage::class)->findOneBy(
  109.             [
  110.                 'url' => 'support',
  111.             ]
  112.         );
  113.         $data = new Support();
  114.         $data->setUser($this->getUser());
  115.         $form $this->createForm(SupportType::class, $data);
  116.         $form->handleRequest($request);
  117.         if ($form->isSubmitted() && $form->isValid()) {
  118.             $em->persist($data);
  119.             $em->flush();
  120. //            $this->addFlash('success', 'flash.support_message_send');
  121.         }
  122.         return $this->render(
  123.             'default/support.html.twig',
  124.             [
  125.                 'page' => $page,
  126.                 'form_submitted' => $form->isSubmitted() && $form->isValid(),
  127.                 'form' => $form->createView(),
  128.             ]
  129.         );
  130.     }
  131.     /**
  132.      * @return \Symfony\Component\HttpFoundation\Response
  133.      *
  134.      */
  135.     #[Route(path'association'name'association_page')]
  136.     public function association(EntityManagerInterface $em)
  137.     {
  138.         $page $em->getRepository(StaticPage::class)->findOneBy(
  139.             [
  140.                 'url' => 'association',
  141.             ]
  142.         );
  143.         return $this->render(
  144.             'default/association.html.twig',
  145.             [
  146.                 'page' => $page,
  147.             ]
  148.         );
  149.     }
  150. }