src/Controller/Frontend/OlympOnline/GalleryController.php line 117
<?php
namespace App\Controller\Frontend\OlympOnline;
use App\Entity\Gallery\Album;
use App\Entity\Gallery\Group;
use App\Entity\Gallery\Photo;
use App\Entity\Gallery\Video;
use App\Entity\Olympiad\Olympiad;
use App\Entity\Olympiad\Online\Event;
use App\Entity\Olympiad\Stage;
use App\Repository\Gallery\AlbumRepository;
use Doctrine\ORM\EntityManagerInterface;
use Knp\Component\Pager\PaginatorInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Entity;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Requirement\Requirement;
/**
* Class OnlineController
* @package App\Controller\OlympOnline
*/
#[Route(name: 'olympiad_gallery_', requirements: ['olymp_id' => '\d+'])]
#[Entity('olympiad', expr: 'repository.find(olymp_id)')]
class GalleryController extends AbstractController
{
/**
* @param Olympiad $olympiad
* @param Request $request
* @param PaginatorInterface $paginator
* @param EntityManagerInterface $em
* @return \Symfony\Component\HttpFoundation\Response
* @throws \Doctrine\ORM\NonUniqueResultException
*/
#[Route(path: '/olympiads/{olymp_id}/gallery', name: 'list')]
#[Route(path: '/gallery', name: '60_list', defaults: ['olymp_id' => 60])]
public function items(Olympiad $olympiad, Request $request, PaginatorInterface $paginator, EntityManagerInterface $em)
{
if ($olympiad->isDeleted() || !$olympiad->isActive()) throw $this->createNotFoundException();
$items = $em->getRepository(Group::class)->findActive($olympiad);
$stages = $em->getRepository(Stage::class)->findForOlymp($olympiad);
$online = $em->getRepository(Event::class)->find4View($olympiad->getUuid());
$onlineStages = [];
foreach ($stages as $st) {
$onlineStages[$st->getId()] = $em->getRepository(Event::class)->find4View($st->getUuid());
}
// dump($items);
return $this->render('olymp-online/gallery/items.html.twig', [
'items' => $items,
'item' => $olympiad,
'stages' => $stages,
'online' => $online,
'onlineStages' => $onlineStages,
]);
}
#[Route(path: '/gallery/{id}', name: '60_group', defaults: ['olymp_id' => 60])]
public function group(Olympiad $olympiad, Group $group, AlbumRepository $albumRepository, EntityManagerInterface $em)
{
if ($olympiad->isDeleted() || !$olympiad->isActive()) throw $this->createNotFoundException();
if ($group->getOwner()->getUuid() !== $olympiad->getUuid()) {
throw $this->createNotFoundException();
}
$albums = $albumRepository->findForGroup($group);
// $photos = $em->getRepository(Photo::class)->findActive($album);
// dump($photos);
/* $videos = $em->getRepository(Video::class)->findActive($album);
$items = array_merge($photos, $videos);
usort($items, function (AlbumItemInterface $a, AlbumItemInterface $b) {
$diff = $b->getWeight() <=> $a->getWeight();
if ($diff !== 0) {
return $diff;
}
return $a->getCreatedAt() <=> $b->getCreatedAt();
});*/
$stages = $em->getRepository(Stage::class)->findForOlymp($olympiad);
$online = $em->getRepository(Event::class)->find4View($olympiad->getUuid());
$onlineStages = [];
foreach ($stages as $st) {
$onlineStages[$st->getId()] = $em->getRepository(Event::class)->find4View($st->getUuid());
}
return $this->render('olymp-online/gallery/group.html.twig', [
'albums' => $albums,
'group' => $group,
'item' => $olympiad,
'stages' => $stages,
'online' => $online,
'onlineStages' => $onlineStages,
]);
}
/**
* @param Olympiad $olympiad
* @param Request $request
* @param PaginatorInterface $paginator
* @param EntityManagerInterface $em
* @return \Symfony\Component\HttpFoundation\Response
* @throws \Doctrine\ORM\NonUniqueResultException
*/
# [Route(path: '/olympiads/{olymp_id}/gallery/{id}', name: 'show')]
#[Route(
path: '/gallery/{group_id}/{id}',
name: '60_show',
requirements: ["group_id" => Requirement::DIGITS, 'id' => Requirement::DIGITS],
defaults: ['olymp_id' => 60]
)]
#[ParamConverter("group", options: ["id" => "group_id"])]
public function show(Olympiad $olympiad, Group $group, Album $album, EntityManagerInterface $em)
{
if ($olympiad->isDeleted() || !$olympiad->isActive()) throw $this->createNotFoundException();
if ($album->getGroup()->getOwner()->getUuid() !== $olympiad->getUuid()) {
throw $this->createNotFoundException();
}
$photos = $em->getRepository(Photo::class)->findActive($album);
// dump($photos);
/* $videos = $em->getRepository(Video::class)->findActive($album);
$items = array_merge($photos, $videos);
usort($items, function (AlbumItemInterface $a, AlbumItemInterface $b) {
$diff = $b->getWeight() <=> $a->getWeight();
if ($diff !== 0) {
return $diff;
}
return $a->getCreatedAt() <=> $b->getCreatedAt();
});*/
$stages = $em->getRepository(Stage::class)->findForOlymp($olympiad);
$online = $em->getRepository(Event::class)->find4View($olympiad->getUuid());
$onlineStages = [];
foreach ($stages as $st) {
$onlineStages[$st->getId()] = $em->getRepository(Event::class)->find4View($st->getUuid());
}
return $this->render('olymp-online/gallery/show.html.twig', [
'items' => $photos,
'album' => $album,
'item' => $olympiad,
'group' => $group,
'stages' => $stages,
'online' => $online,
'onlineStages' => $onlineStages,
]);
}
}