src/Controller/Frontend/OlympiadsController.php line 266

  1. <?php
  2. namespace App\Controller\Frontend;
  3. use App\Entity\Content\FAQ\Faq;
  4. use App\Entity\Content\Material;
  5. use App\Entity\Content\News;
  6. use App\Entity\Content\Parts\TextBlock;
  7. use App\Entity\Content\SMI\SmiItem;
  8. use App\Entity\Olympiad\Olympiad;
  9. use App\Entity\Olympiad\Online\Event;
  10. use App\Entity\Olympiad\Stage;
  11. use App\Forms\Types\Olympiad\SignupType;
  12. use App\Model\Content\Material\MaterialsShow;
  13. use App\Model\Content\NewsSearch;
  14. use App\Model\Olympiad\MaterialType;
  15. use App\Repository\Content\SmiItemRepository;
  16. use App\Repository\Gallery\PhotoRepository;
  17. use App\Service\Common\Contacts\Factory;
  18. use App\Service\Common\Owner\OwnerFactory;
  19. use Doctrine\ORM\EntityManagerInterface;
  20. use Knp\Component\Pager\PaginatorInterface;
  21. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Entity;
  22. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  23. use Symfony\Component\Form\FormError;
  24. use Symfony\Component\HttpFoundation\Request;
  25. use Symfony\Component\HttpFoundation\RequestStack;
  26. use Symfony\Component\HttpFoundation\Response;
  27. use Symfony\Component\Routing\Annotation\Route;
  28. use Symfony\Component\Routing\Requirement\Requirement;
  29. class OlympiadsController extends AbstractController
  30. {
  31.     public function __construct(private EntityManagerInterface $em)
  32.     {
  33.     }
  34.     #[Route("/olympiads/{id}"name"olympiad_show"requirements: ["id" => "\d+"], priority10)]
  35.     #[Route("/"name"main_olymp"defaults: ["id" => 60], priority50)]
  36.     #[Entity("olympiad"expr'repository.find4Show(id)')]
  37.     #[Entity('category'expr'repository.bySlug(category)')]
  38.     public function show(
  39.         Olympiad                        $olympiad,
  40.         Request                         $request,
  41.         PaginatorInterface              $paginator,
  42.         EntityManagerInterface          $em,
  43.         OwnerFactory                    $ownerProvider,
  44.         Factory                         $factory,
  45.         SmiItemRepository               $smiItemRepository,
  46.         PhotoRepository                 $photoRepository,
  47.         \App\Service\Site\Config\Config $config,
  48.     ): Response
  49.     {
  50.         if ($olympiad->isDeleted() || !$olympiad->isActive()) throw  $this->createNotFoundException();
  51.         $owner $ownerProvider->getOwner($olympiad);
  52. //        $materials = $em->getRepository(Material::class)->findByOwner($owner, [MaterialType::MATERIAL_MAIN_PAGE]);
  53.         $news $this->em->getRepository(News::class)->findNewsByOwner($owner4, [
  54.                 'locale' => $request->getLocale()
  55.             ]
  56.         );
  57. //        $events = $this->em->getRepository(News::class)->findEventsByOwner($owner, 4);
  58. //        $contacts = $factory->find($olympiad->getUuid());
  59. //        $privileges = $em->getRepository(OlympPrivilegy::class)->findForOlymp($olympiad);
  60.         $smi $smiItemRepository->findMainPage($owner$request->getLocale(), 2);
  61.         $media null;
  62.         $album_id $value $config->value('mainpage''media');
  63.         if ($album_id) {
  64.             $media $photoRepository->findMainPage($album_id);
  65.         }
  66.         list($online$stages$onlineStages) = $this->findOnline($olympiad);
  67. //        dump($onlineStages);
  68.         return $this->render(
  69.             'olympiads/iofs/view.html.twig',
  70.             [
  71.                 'item' => $olympiad,
  72. //                'materials' => $materials,
  73.                 'stages' => $stages,
  74.                 'news' => $news,
  75.                 'smi' => $smi,
  76.                 'media' => $media,
  77. //                'events' => $events,
  78. //                'contacts' => $contacts,
  79. //                'privileges' => $privileges,
  80.                 'online' => $online,
  81.                 'onlineStages' => $onlineStages,
  82.             ]
  83.         );
  84.     }
  85.     private function findOnline(Olympiad $olympiad): array
  86.     {
  87.         $online $this->em->getRepository(Event::class)->find4View($olympiad->getUuid());
  88.         $stages $this->em->getRepository(Stage::class)->findForOlymp($olympiad);
  89.         $onlineStages = [];
  90.         foreach ($stages as $st) {
  91.             $onlineStages[$st->getId()] = $this->em->getRepository(Event::class)->find4View($st->getUuid());
  92.         }
  93.         return array($online$stages$onlineStages);
  94.     }
  95.     #[Route("/olympiads/{id}/{block}"name"olympiad_text"requirements: ["id" => "\d+"], priority"-150")]
  96.     #[Route("/{block}"name"olympiad_60_text"requirements: ["id" => "\d+"], defaults: ["olympiad" => 60], priority"-150")]
  97.     public function show_block(
  98.         Olympiad               $olympiad,
  99.         string                 $block,
  100.         EntityManagerInterface $em,
  101.         OwnerFactory           $ownerProvider,
  102.         Factory                $factory,
  103.         Request                $request
  104.     ): Response
  105.     {
  106.         $owner $ownerProvider->getOwner($olympiad);
  107.         if ($olympiad->isDeleted() || !$olympiad->isActive()) throw  $this->createNotFoundException();
  108.         list($online$stages$onlineStages) = $this->findOnline($olympiad);
  109.         $text $em->getRepository(TextBlock::class)->find4Show($olympiad$block);
  110.         if (!$text) {
  111.             throw $this->createNotFoundException();
  112.         }
  113.         if (!$text->isActive() && !$this->isGranted('ROLE_ADMIN')) {
  114.             throw $this->createNotFoundException();
  115.         }
  116.         return $this->render(
  117.             'olympiads/iofs/text.html.twig',
  118.             [
  119.                 'item' => $olympiad,
  120.                 'stages' => $stages,
  121.                 'online' => $online,
  122.                 'onlineStages' => $onlineStages,
  123.                 'text' => $text,
  124.             ]
  125.         );
  126.     }
  127.     #[Route(path'/olympiads/{id}/stage-{stage_id}'name'olympiad_stage_show')]
  128.     #[Entity('olympiad'expr'repository.find(id)')]
  129.     #[Entity('stage'expr'repository.find(stage_id)')]
  130.     public function stage(
  131.         Olympiad               $olympiad,
  132.         Stage                  $stage,
  133.         Request                $request,
  134.         PaginatorInterface     $paginator,
  135.         EntityManagerInterface $em,
  136.         OwnerFactory           $ownerProvider,
  137.         Factory                $factory
  138.     ): Response
  139.     {
  140.         if ($olympiad->isDeleted() || !$olympiad->isActive()) throw  $this->createNotFoundException();
  141. //        dump($olympiad);
  142.         list($online$stages$onlineStages) = $this->findOnline($olympiad);
  143.         $contacts $factory->find($stage->getUuid());
  144.         $owner $ownerProvider->getOwner($olympiad);
  145.         $news $this->em->getRepository(News::class)->findNewsByOwner($owner);
  146.         return $this->render(
  147.             'olympiads/stage.html.twig',
  148.             [
  149.                 'olymp' => $olympiad,
  150.                 'stage' => $stage,
  151.                 'stages' => $stages,
  152.                 'contacts' => $contacts,
  153.                 'news' => $news,
  154.             ]
  155.         );
  156.     }
  157.     #[Route(path'/olympiads/{id}/signup'name'olympiad_signup')]
  158.     #[Entity('olympiad'expr'repository.find(id)')]
  159.     public function signUp(
  160.         Olympiad $olympiad,
  161.         Request  $request
  162.     ): Response
  163.     {
  164.         if ($olympiad->isDeleted()) {
  165.             throw $this->createNotFoundException();
  166.         }
  167.         $form $this->createForm(SignupType::class);
  168.         $form->handleRequest($request);
  169.         if ($form->isSubmitted() && $form->isValid()) {
  170.             $form->addError(new FormError('common error'));
  171.             $form->get('surname')->addError(new FormError('surname error'));
  172.         }
  173.         return $this->render(
  174.             'olympiads/signup.html.twig',
  175.             [
  176.                 'olymp' => $olympiad,
  177.                 'form' => $form->createView()
  178.             ]
  179.         );
  180.     }
  181.     #[Route(path'/faq'name'olympiad_faq')]
  182.     public function faqRequest $requestEntityManagerInterface $emPaginatorInterface $paginator): Response
  183.     {
  184.         $olympiad $em->getRepository(Olympiad::class)->findShow(60);
  185.         $faq $em->getRepository(Faq::class)->findView($olympiad$request->getLocale());
  186.         return $this->render(
  187.             'olympiads/faq.html.twig',
  188.             [
  189.                 'olympiad' => $olympiad,
  190.                 'faq' => $faq
  191.             ]
  192.         );
  193.     }
  194.     #[Route(path'/olympiads/{id}/news'name'olympiad_news'requirements: ['id' => '\d+'])]
  195.     #[Route(path'/news'name'olympiad_60_news'requirements: ['id' => '\d+'], defaults: ['olympiad' => 60])]
  196.     public function news(Olympiad $olympiad,
  197.                          Request  $requestPaginatorInterface $paginationOwnerFactory $ownerProvider,
  198.     ): Response
  199.     {
  200.         if ($olympiad->isDeleted()) {
  201.             throw $this->createNotFoundException();
  202.         }
  203. //        $this->checkIsGranted($org);
  204.         $owner $ownerProvider->getOwner($olympiad);
  205.         $filter = new NewsSearch();
  206.         $filter->setOwner($owner);
  207.         $filter->setLocale($request->getLocale());
  208.         $newsQb $this->em->getRepository(News::class)->findNewsQb($filter);
  209.         $page $request->query->getInt('page'1);
  210.         if ($page 1$page 1;
  211.         $news $pagination->paginate($newsQb$page12);
  212.         list($online$stages$onlineStages) = $this->findOnline($olympiad);
  213.         return $this->render(
  214.             'olympiads/news.html.twig',
  215.             [
  216.                 'item' => $olympiad,
  217.                 'news' => $news,
  218.                 'stages' => $stages,
  219.                 'online' => $online,
  220.                 'onlineStages' => $onlineStages,
  221.             ]
  222.         );
  223.     }
  224.     #[Route("/smi"name"olymp_smi"defaults: ["id" => 60])]
  225.     public function smi(Olympiad          $olympiadRequest $req,
  226.                         SmiItemRepository $smiItemRepositoryOwnerFactory $ownerFactoryPaginatorInterface $paginator): Response
  227.     {
  228.         $page $req->query->getInt('page'1);
  229.         $owner $ownerFactory->getOwner($olympiad);
  230.         $qb $smiItemRepository->findActiveQb($owner$req->getLocale());
  231.         $items $paginator->paginate($qb$pageSmiItem::SITE_PER_PAGE);
  232.         list($online$stages$onlineStages) = $this->findOnline($olympiad);
  233.         return $this->render('olympiads/smi.html.twig', [
  234.             'olympiad' => $olympiad,
  235.             'items' => $items,
  236.             'page' => $page,
  237.             'stages' => $stages,
  238.             'online' => $online,
  239.             'onlineStages' => $onlineStages,
  240.         ]);
  241.     }
  242.     #[Route("/smi/{smi_id}"name"olymp_smi_item"requirements: ['smi_id' => Requirement::DIGITS], defaults: ["id" => 60])]
  243.     public function smi_item(
  244.         Olympiad          $olympiad,
  245.         int               $smi_id,
  246.         Request           $req,
  247.         SmiItemRepository $smiItemRepository,
  248.         OwnerFactory      $ownerFactoryPaginatorInterface $paginator): Response
  249.     {
  250.         $smiItem $smiItemRepository->findView($smi_id$req->getLocale());
  251.         if (!$smiItem) throw $this->createNotFoundException();
  252.         list($online$stages$onlineStages) = $this->findOnline($olympiad);
  253.         return $this->render('olympiads/smi_item.html.twig', [
  254.             'olympiad' => $olympiad,
  255.             'smi_item' => $smiItem,
  256.             'stages' => $stages,
  257.             'online' => $online,
  258.             'onlineStages' => $onlineStages,
  259.         ]);
  260.     }
  261.     #[Route("/documents"name"documents"defaults: ["id" => 60])]
  262.     public function documents(Olympiad     $olympiad,
  263.                                      OwnerFactory $ownerFactoryRequestStack $requestStack): Response
  264.     {
  265.         $block 'documents';
  266.         $owner $ownerFactory->getOwner($olympiad);
  267.         $text $this->em->getRepository(TextBlock::class)->find4Show($olympiad$block);
  268.         if (!$text) {
  269.             throw $this->createNotFoundException();
  270.         }
  271.         if (!$text->isActive() && !$this->isGranted('ROLE_ADMIN')) {
  272.             throw $this->createNotFoundException();
  273.         }
  274.         $locale $requestStack->getMainRequest()->getLocale();
  275.         if ($locale === 'ru') {
  276.             $m $this->em->getRepository(Material::class)->findByOwner($owner, [MaterialType::MATERIAL_FOR_PARTICIPANTS]);
  277.         } else {
  278.             $m = [];
  279.         }
  280.         if ($locale === 'ru') {
  281.             $m_SO $this->em->getRepository(Material::class)->findByOwner($owner, [MaterialType::MATERIAL_FOR_PARTICIPANTS_STANDING_ORDER]);
  282.         } else {
  283.             $m_SO = [];
  284.         }
  285.         if ($locale === 'ru') {
  286.             $m_vuz $this->em->getRepository(Material::class)->findByOwner($owner, [MaterialType::MATERIAL_FOR_PARTICIPANTS_VUZ]);
  287.         } else {
  288.             $m_vuz = [];
  289.         }
  290.         $materials = new MaterialsShow('material.caption.for_participants'$m);
  291.         $materialsSO = new MaterialsShow('material.caption.for_participants_so'$m_SO);
  292.         $materials_vuz = new MaterialsShow('material.caption.for_participants_vuz'$m_vuz);
  293.         list($online$stages$onlineStages) = $this->findOnline($olympiad);
  294.         return $this->render('olympiads/iofs/text.html.twig', [
  295.             'item' => $olympiad,
  296.             'text' => $text,
  297.             'stages' => $stages,
  298.             'online' => $online,
  299.             'onlineStages' => $onlineStages,
  300.             'materials' => [$materialsSO$materials_vuz$materials,],
  301.         ]);
  302.     }
  303.     # [Route("/for-participants", name: "for_participants", defaults: ["id" => 60])]
  304.     public function for_participants(Olympiad     $olympiad,
  305.                                      OwnerFactory $ownerFactoryRequestStack $requestStack): Response
  306.     {
  307.         $block 'for-participants';
  308.         $owner $ownerFactory->getOwner($olympiad);
  309.         $text $this->em->getRepository(TextBlock::class)->find4Show($olympiad$block);
  310.         if (!$text) {
  311.             throw $this->createNotFoundException();
  312.         }
  313.         if (!$text->isActive() && !$this->isGranted('ROLE_ADMIN')) {
  314.             throw $this->createNotFoundException();
  315.         }
  316.         $locale $requestStack->getMainRequest()->getLocale();
  317.         if ($locale === 'ru') {
  318.             $m $this->em->getRepository(Material::class)->findByOwner($owner, [MaterialType::MATERIAL_FOR_PARTICIPANTS]);
  319.         } else {
  320.             $m = [];
  321.         }
  322.         if ($locale === 'ru') {
  323.             $m_SO $this->em->getRepository(Material::class)->findByOwner($owner, [MaterialType::MATERIAL_FOR_PARTICIPANTS_STANDING_ORDER]);
  324.         } else {
  325.             $m_SO = [];
  326.         }
  327.         if ($locale === 'ru') {
  328.             $m_vuz $this->em->getRepository(Material::class)->findByOwner($owner, [MaterialType::MATERIAL_FOR_PARTICIPANTS_VUZ]);
  329.         } else {
  330.             $m_vuz = [];
  331.         }
  332.         $materials = new MaterialsShow('material.caption.for_participants'$m);
  333.         $materialsSO = new MaterialsShow('material.caption.for_participants_so'$m_SO);
  334.         $materials_vuz = new MaterialsShow('material.caption.for_participants_vuz'$m_vuz);
  335.         list($online$stages$onlineStages) = $this->findOnline($olympiad);
  336.         return $this->render('olympiads/iofs/text.html.twig', [
  337.             'item' => $olympiad,
  338.             'text' => $text,
  339.             'stages' => $stages,
  340.             'online' => $online,
  341.             'onlineStages' => $onlineStages,
  342.             'materials' => [$materialsSO$materials_vuz$materials,],
  343.         ]);
  344.     }
  345.     /*#[Route("/documents", name: "documents", defaults: ["id" => 60])]
  346.     public function documents(Olympiad     $olympiad,
  347.                               OwnerFactory $ownerFactory,): Response
  348.     {
  349.         $block = 'documents';
  350.         $owner = $ownerFactory->getOwner($olympiad);
  351.         $text = $this->em->getRepository(TextBlock::class)->find4Show($olympiad, $block);
  352.         if (!$text) {
  353.             throw $this->createNotFoundException();
  354.         }
  355.         $m = $this->em->getRepository(Material::class)->findByOwner($owner, [MaterialType::MATERIAL_DOCS]);
  356.         $materials = new MaterialsShow('material.caption.documents', $m);
  357.         list($online, $stages, $onlineStages) = $this->findOnline($olympiad);
  358.         return $this->render('olympiads/iofs/text.html.twig', [
  359.             'item' => $olympiad,
  360.             'text' => $text,
  361.             'stages' => $stages,
  362.             'online' => $online,
  363.             'onlineStages' => $onlineStages,
  364.             'materials' => [$materials],
  365.         ]);
  366.     }*/
  367. }