src/Controller/Frontend/OlympiadsController.php line 313
<?php
namespace App\Controller\Frontend;
use App\Entity\Content\FAQ\Faq;
use App\Entity\Content\Material;
use App\Entity\Content\News;
use App\Entity\Content\Parts\TextBlock;
use App\Entity\Content\SMI\SmiItem;
use App\Entity\Olympiad\Olympiad;
use App\Entity\Olympiad\Online\Event;
use App\Entity\Olympiad\Stage;
use App\Forms\Types\Olympiad\SignupType;
use App\Model\Content\Material\MaterialsShow;
use App\Model\Content\NewsSearch;
use App\Model\Olympiad\MaterialType;
use App\Repository\Content\SmiItemRepository;
use App\Repository\Gallery\PhotoRepository;
use App\Service\Common\Contacts\Factory;
use App\Service\Common\Owner\OwnerFactory;
use Doctrine\ORM\EntityManagerInterface;
use Knp\Component\Pager\PaginatorInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Entity;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormError;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Requirement\Requirement;
class OlympiadsController extends AbstractController
{
public function __construct(private EntityManagerInterface $em)
{
}
#[Route("/olympiads/{id}", name: "olympiad_show", requirements: ["id" => "\d+"], priority: 10)]
#[Route("/", name: "main_olymp", defaults: ["id" => 60], priority: 50)]
#[Entity("olympiad", expr: 'repository.find4Show(id)')]
#[Entity('category', expr: 'repository.bySlug(category)')]
public function show(
Olympiad $olympiad,
Request $request,
PaginatorInterface $paginator,
EntityManagerInterface $em,
OwnerFactory $ownerProvider,
Factory $factory,
SmiItemRepository $smiItemRepository,
PhotoRepository $photoRepository,
\App\Service\Site\Config\Config $config,
): Response
{
if ($olympiad->isDeleted() || !$olympiad->isActive()) throw $this->createNotFoundException();
$owner = $ownerProvider->getOwner($olympiad);
// $materials = $em->getRepository(Material::class)->findByOwner($owner, [MaterialType::MATERIAL_MAIN_PAGE]);
$news = $this->em->getRepository(News::class)->findNewsByOwner($owner, 4, [
'locale' => $request->getLocale()
]
);
// $events = $this->em->getRepository(News::class)->findEventsByOwner($owner, 4);
// $contacts = $factory->find($olympiad->getUuid());
// $privileges = $em->getRepository(OlympPrivilegy::class)->findForOlymp($olympiad);
$smi = $smiItemRepository->findMainPage($owner, $request->getLocale(), 2);
$media = null;
$album_id = $value = $config->value('mainpage', 'media');
if ($album_id) {
$media = $photoRepository->findMainPage($album_id);
}
list($online, $stages, $onlineStages) = $this->findOnline($olympiad);
// dump($onlineStages);
return $this->render(
'olympiads/iofs/view.html.twig',
[
'item' => $olympiad,
// 'materials' => $materials,
'stages' => $stages,
'news' => $news,
'smi' => $smi,
'media' => $media,
// 'events' => $events,
// 'contacts' => $contacts,
// 'privileges' => $privileges,
'online' => $online,
'onlineStages' => $onlineStages,
]
);
}
private function findOnline(Olympiad $olympiad): array
{
$online = $this->em->getRepository(Event::class)->find4View($olympiad->getUuid());
$stages = $this->em->getRepository(Stage::class)->findForOlymp($olympiad);
$onlineStages = [];
foreach ($stages as $st) {
$onlineStages[$st->getId()] = $this->em->getRepository(Event::class)->find4View($st->getUuid());
}
return array($online, $stages, $onlineStages);
}
#[Route("/olympiads/{id}/{block}", name: "olympiad_text", requirements: ["id" => "\d+"], priority: "-150")]
#[Route("/{block}", name: "olympiad_60_text", requirements: ["id" => "\d+"], defaults: ["olympiad" => 60], priority: "-150")]
public function show_block(
Olympiad $olympiad,
string $block,
EntityManagerInterface $em,
OwnerFactory $ownerProvider,
Factory $factory,
Request $request
): Response
{
$owner = $ownerProvider->getOwner($olympiad);
if ($olympiad->isDeleted() || !$olympiad->isActive()) throw $this->createNotFoundException();
list($online, $stages, $onlineStages) = $this->findOnline($olympiad);
$text = $em->getRepository(TextBlock::class)->find4Show($olympiad, $block);
if (!$text) {
throw $this->createNotFoundException();
}
if (!$text->isActive() && !$this->isGranted('ROLE_ADMIN')) {
throw $this->createNotFoundException();
}
return $this->render(
'olympiads/iofs/text.html.twig',
[
'item' => $olympiad,
'stages' => $stages,
'online' => $online,
'onlineStages' => $onlineStages,
'text' => $text,
]
);
}
#[Route(path: '/olympiads/{id}/stage-{stage_id}', name: 'olympiad_stage_show')]
#[Entity('olympiad', expr: 'repository.find(id)')]
#[Entity('stage', expr: 'repository.find(stage_id)')]
public function stage(
Olympiad $olympiad,
Stage $stage,
Request $request,
PaginatorInterface $paginator,
EntityManagerInterface $em,
OwnerFactory $ownerProvider,
Factory $factory
): Response
{
if ($olympiad->isDeleted() || !$olympiad->isActive()) throw $this->createNotFoundException();
// dump($olympiad);
list($online, $stages, $onlineStages) = $this->findOnline($olympiad);
$contacts = $factory->find($stage->getUuid());
$owner = $ownerProvider->getOwner($olympiad);
$news = $this->em->getRepository(News::class)->findNewsByOwner($owner);
return $this->render(
'olympiads/stage.html.twig',
[
'olymp' => $olympiad,
'stage' => $stage,
'stages' => $stages,
'contacts' => $contacts,
'news' => $news,
]
);
}
#[Route(path: '/olympiads/{id}/signup', name: 'olympiad_signup')]
#[Entity('olympiad', expr: 'repository.find(id)')]
public function signUp(
Olympiad $olympiad,
Request $request
): Response
{
if ($olympiad->isDeleted()) {
throw $this->createNotFoundException();
}
$form = $this->createForm(SignupType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$form->addError(new FormError('common error'));
$form->get('surname')->addError(new FormError('surname error'));
}
return $this->render(
'olympiads/signup.html.twig',
[
'olymp' => $olympiad,
'form' => $form->createView()
]
);
}
#[Route(path: '/faq', name: 'olympiad_faq')]
public function faq( Request $request, EntityManagerInterface $em, PaginatorInterface $paginator): Response
{
$olympiad = $em->getRepository(Olympiad::class)->findShow(60);
$faq = $em->getRepository(Faq::class)->findView($olympiad, $request->getLocale());
return $this->render(
'olympiads/faq.html.twig',
[
'olympiad' => $olympiad,
'faq' => $faq
]
);
}
#[Route(path: '/olympiads/{id}/news', name: 'olympiad_news', requirements: ['id' => '\d+'])]
#[Route(path: '/news', name: 'olympiad_60_news', requirements: ['id' => '\d+'], defaults: ['olympiad' => 60])]
public function news(Olympiad $olympiad,
Request $request, PaginatorInterface $pagination, OwnerFactory $ownerProvider,
): Response
{
if ($olympiad->isDeleted()) {
throw $this->createNotFoundException();
}
// $this->checkIsGranted($org);
$owner = $ownerProvider->getOwner($olympiad);
$filter = new NewsSearch();
$filter->setOwner($owner);
$filter->setLocale($request->getLocale());
$newsQb = $this->em->getRepository(News::class)->findNewsQb($filter);
$page = $request->query->getInt('page', 1);
if ($page < 1) $page = 1;
$news = $pagination->paginate($newsQb, $page, 12);
list($online, $stages, $onlineStages) = $this->findOnline($olympiad);
return $this->render(
'olympiads/news.html.twig',
[
'item' => $olympiad,
'news' => $news,
'stages' => $stages,
'online' => $online,
'onlineStages' => $onlineStages,
]
);
}
#[Route("/smi", name: "olymp_smi", defaults: ["id" => 60])]
public function smi(Olympiad $olympiad, Request $req,
SmiItemRepository $smiItemRepository, OwnerFactory $ownerFactory, PaginatorInterface $paginator): Response
{
$page = $req->query->getInt('page', 1);
$owner = $ownerFactory->getOwner($olympiad);
$qb = $smiItemRepository->findActiveQb($owner, $req->getLocale());
$items = $paginator->paginate($qb, $page, SmiItem::SITE_PER_PAGE);
list($online, $stages, $onlineStages) = $this->findOnline($olympiad);
return $this->render('olympiads/smi.html.twig', [
'olympiad' => $olympiad,
'items' => $items,
'page' => $page,
'stages' => $stages,
'online' => $online,
'onlineStages' => $onlineStages,
]);
}
#[Route("/smi/{smi_id}", name: "olymp_smi_item", requirements: ['smi_id' => Requirement::DIGITS], defaults: ["id" => 60])]
public function smi_item(
Olympiad $olympiad,
int $smi_id,
Request $req,
SmiItemRepository $smiItemRepository,
OwnerFactory $ownerFactory, PaginatorInterface $paginator): Response
{
$smiItem = $smiItemRepository->findView($smi_id, $req->getLocale());
if (!$smiItem) throw $this->createNotFoundException();
list($online, $stages, $onlineStages) = $this->findOnline($olympiad);
return $this->render('olympiads/smi_item.html.twig', [
'olympiad' => $olympiad,
'smi_item' => $smiItem,
'stages' => $stages,
'online' => $online,
'onlineStages' => $onlineStages,
]);
}
#[Route("/documents", name: "documents", defaults: ["id" => 60])]
public function documents(Olympiad $olympiad,
OwnerFactory $ownerFactory, RequestStack $requestStack): Response
{
$block = 'documents';
$owner = $ownerFactory->getOwner($olympiad);
$text = $this->em->getRepository(TextBlock::class)->find4Show($olympiad, $block);
if (!$text) {
throw $this->createNotFoundException();
}
if (!$text->isActive() && !$this->isGranted('ROLE_ADMIN')) {
throw $this->createNotFoundException();
}
$locale = $requestStack->getMainRequest()->getLocale();
if ($locale === 'ru') {
$m = $this->em->getRepository(Material::class)->findByOwner($owner, [MaterialType::MATERIAL_FOR_PARTICIPANTS]);
} else {
$m = [];
}
if ($locale === 'ru') {
$m_SO = $this->em->getRepository(Material::class)->findByOwner($owner, [MaterialType::MATERIAL_FOR_PARTICIPANTS_STANDING_ORDER]);
} else {
$m_SO = [];
}
if ($locale === 'ru') {
$m_vuz = $this->em->getRepository(Material::class)->findByOwner($owner, [MaterialType::MATERIAL_FOR_PARTICIPANTS_VUZ]);
} else {
$m_vuz = [];
}
$materials = new MaterialsShow('material.caption.for_participants', $m);
$materialsSO = new MaterialsShow('material.caption.for_participants_so', $m_SO);
$materials_vuz = new MaterialsShow('material.caption.for_participants_vuz', $m_vuz);
list($online, $stages, $onlineStages) = $this->findOnline($olympiad);
return $this->render('olympiads/iofs/text.html.twig', [
'item' => $olympiad,
'text' => $text,
'stages' => $stages,
'online' => $online,
'onlineStages' => $onlineStages,
'materials' => [$materialsSO, $materials_vuz, $materials,],
]);
}
# [Route("/for-participants", name: "for_participants", defaults: ["id" => 60])]
public function for_participants(Olympiad $olympiad,
OwnerFactory $ownerFactory, RequestStack $requestStack): Response
{
$block = 'for-participants';
$owner = $ownerFactory->getOwner($olympiad);
$text = $this->em->getRepository(TextBlock::class)->find4Show($olympiad, $block);
if (!$text) {
throw $this->createNotFoundException();
}
if (!$text->isActive() && !$this->isGranted('ROLE_ADMIN')) {
throw $this->createNotFoundException();
}
$locale = $requestStack->getMainRequest()->getLocale();
if ($locale === 'ru') {
$m = $this->em->getRepository(Material::class)->findByOwner($owner, [MaterialType::MATERIAL_FOR_PARTICIPANTS]);
} else {
$m = [];
}
if ($locale === 'ru') {
$m_SO = $this->em->getRepository(Material::class)->findByOwner($owner, [MaterialType::MATERIAL_FOR_PARTICIPANTS_STANDING_ORDER]);
} else {
$m_SO = [];
}
if ($locale === 'ru') {
$m_vuz = $this->em->getRepository(Material::class)->findByOwner($owner, [MaterialType::MATERIAL_FOR_PARTICIPANTS_VUZ]);
} else {
$m_vuz = [];
}
$materials = new MaterialsShow('material.caption.for_participants', $m);
$materialsSO = new MaterialsShow('material.caption.for_participants_so', $m_SO);
$materials_vuz = new MaterialsShow('material.caption.for_participants_vuz', $m_vuz);
list($online, $stages, $onlineStages) = $this->findOnline($olympiad);
return $this->render('olympiads/iofs/text.html.twig', [
'item' => $olympiad,
'text' => $text,
'stages' => $stages,
'online' => $online,
'onlineStages' => $onlineStages,
'materials' => [$materialsSO, $materials_vuz, $materials,],
]);
}
/*#[Route("/documents", name: "documents", defaults: ["id" => 60])]
public function documents(Olympiad $olympiad,
OwnerFactory $ownerFactory,): Response
{
$block = 'documents';
$owner = $ownerFactory->getOwner($olympiad);
$text = $this->em->getRepository(TextBlock::class)->find4Show($olympiad, $block);
if (!$text) {
throw $this->createNotFoundException();
}
$m = $this->em->getRepository(Material::class)->findByOwner($owner, [MaterialType::MATERIAL_DOCS]);
$materials = new MaterialsShow('material.caption.documents', $m);
list($online, $stages, $onlineStages) = $this->findOnline($olympiad);
return $this->render('olympiads/iofs/text.html.twig', [
'item' => $olympiad,
'text' => $text,
'stages' => $stages,
'online' => $online,
'onlineStages' => $onlineStages,
'materials' => [$materials],
]);
}*/
}