src/Controller/Frontend/OlympOnline/GalleryController.php line 63

  1. <?php
  2. namespace App\Controller\Frontend\OlympOnline;
  3. use App\Entity\Gallery\Album;
  4. use App\Entity\Gallery\Group;
  5. use App\Entity\Gallery\Photo;
  6. use App\Entity\Gallery\Video;
  7. use App\Entity\Olympiad\Olympiad;
  8. use App\Entity\Olympiad\Online\Event;
  9. use App\Entity\Olympiad\Stage;
  10. use App\Repository\Gallery\AlbumRepository;
  11. use Doctrine\ORM\EntityManagerInterface;
  12. use Knp\Component\Pager\PaginatorInterface;
  13. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Entity;
  14. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  15. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. use Symfony\Component\Routing\Requirement\Requirement;
  19. /**
  20.  * Class OnlineController
  21.  * @package App\Controller\OlympOnline
  22.  */
  23. #[Route(name'olympiad_gallery_'requirements: ['olymp_id' => '\d+'])]
  24. #[Entity('olympiad'expr'repository.find(olymp_id)')]
  25. class GalleryController extends AbstractController
  26. {
  27.     /**
  28.      * @param Olympiad $olympiad
  29.      * @param Request $request
  30.      * @param PaginatorInterface $paginator
  31.      * @param EntityManagerInterface $em
  32.      * @return \Symfony\Component\HttpFoundation\Response
  33.      * @throws \Doctrine\ORM\NonUniqueResultException
  34.      */
  35.     #[Route(path'/olympiads/{olymp_id}/gallery'name'list')]
  36.     #[Route(path'/gallery'name'60_list'defaults: ['olymp_id' => 60])]
  37.     public function items(Olympiad $olympiadRequest $requestPaginatorInterface $paginatorEntityManagerInterface $em)
  38.     {
  39.         if ($olympiad->isDeleted() || !$olympiad->isActive()) throw  $this->createNotFoundException();
  40.         $items $em->getRepository(Group::class)->findActive($olympiad);
  41.         $stages $em->getRepository(Stage::class)->findForOlymp($olympiad);
  42.         $online $em->getRepository(Event::class)->find4View($olympiad->getUuid());
  43.         $onlineStages = [];
  44.         foreach ($stages as $st) {
  45.             $onlineStages[$st->getId()] = $em->getRepository(Event::class)->find4View($st->getUuid());
  46.         }
  47. //        dump($items);
  48.         return $this->render('olymp-online/gallery/items.html.twig', [
  49.             'items' => $items,
  50.             'item' => $olympiad,
  51.             'stages' => $stages,
  52.             'online' => $online,
  53.             'onlineStages' => $onlineStages,
  54.         ]);
  55.     }
  56.     #[Route(path'/gallery/{id}'name'60_group'defaults: ['olymp_id' => 60])]
  57.     public function group(Olympiad $olympiadGroup $groupAlbumRepository $albumRepositoryEntityManagerInterface $em)
  58.     {
  59.         if ($olympiad->isDeleted() || !$olympiad->isActive()) throw  $this->createNotFoundException();
  60.         if ($group->getOwner()->getUuid() !== $olympiad->getUuid()) {
  61.             throw $this->createNotFoundException();
  62.         }
  63.         $albums $albumRepository->findForGroup($group);
  64. //        $photos = $em->getRepository(Photo::class)->findActive($album);
  65. //        dump($photos);
  66.         /*   $videos = $em->getRepository(Video::class)->findActive($album);
  67.            $items = array_merge($photos, $videos);
  68.            usort($items, function (AlbumItemInterface $a, AlbumItemInterface $b) {
  69.                $diff = $b->getWeight() <=> $a->getWeight();
  70.                if ($diff !== 0) {
  71.                    return $diff;
  72.                }
  73.                return $a->getCreatedAt() <=> $b->getCreatedAt();
  74.            });*/
  75.         $stages $em->getRepository(Stage::class)->findForOlymp($olympiad);
  76.         $online $em->getRepository(Event::class)->find4View($olympiad->getUuid());
  77.         $onlineStages = [];
  78.         foreach ($stages as $st) {
  79.             $onlineStages[$st->getId()] = $em->getRepository(Event::class)->find4View($st->getUuid());
  80.         }
  81.         return $this->render('olymp-online/gallery/group.html.twig', [
  82.             'albums' => $albums,
  83.             'group' => $group,
  84.             'item' => $olympiad,
  85.             'stages' => $stages,
  86.             'online' => $online,
  87.             'onlineStages' => $onlineStages,
  88.         ]);
  89.     }
  90.     /**
  91.      * @param Olympiad $olympiad
  92.      * @param Request $request
  93.      * @param PaginatorInterface $paginator
  94.      * @param EntityManagerInterface $em
  95.      * @return \Symfony\Component\HttpFoundation\Response
  96.      * @throws \Doctrine\ORM\NonUniqueResultException
  97.      */
  98.     # [Route(path: '/olympiads/{olymp_id}/gallery/{id}', name: 'show')]
  99.     #[Route(
  100.         path'/gallery/{group_id}/{id}',
  101.         name'60_show',
  102.         requirements: ["group_id" => Requirement::DIGITS'id' => Requirement::DIGITS],
  103.         defaults: ['olymp_id' => 60]
  104.     )]
  105.     #[ParamConverter("group"options: ["id" => "group_id"])]
  106.     public function show(Olympiad $olympiadGroup $groupAlbum $albumEntityManagerInterface $em)
  107.     {
  108.         if ($olympiad->isDeleted() || !$olympiad->isActive()) throw  $this->createNotFoundException();
  109.         if ($album->getGroup()->getOwner()->getUuid() !== $olympiad->getUuid()) {
  110.             throw $this->createNotFoundException();
  111.         }
  112.         $photos $em->getRepository(Photo::class)->findActive($album);
  113. //        dump($photos);
  114.         /*   $videos = $em->getRepository(Video::class)->findActive($album);
  115.            $items = array_merge($photos, $videos);
  116.            usort($items, function (AlbumItemInterface $a, AlbumItemInterface $b) {
  117.                $diff = $b->getWeight() <=> $a->getWeight();
  118.                if ($diff !== 0) {
  119.                    return $diff;
  120.                }
  121.                return $a->getCreatedAt() <=> $b->getCreatedAt();
  122.            });*/
  123.         $stages $em->getRepository(Stage::class)->findForOlymp($olympiad);
  124.         $online $em->getRepository(Event::class)->find4View($olympiad->getUuid());
  125.         $onlineStages = [];
  126.         foreach ($stages as $st) {
  127.             $onlineStages[$st->getId()] = $em->getRepository(Event::class)->find4View($st->getUuid());
  128.         }
  129.         return $this->render('olymp-online/gallery/show.html.twig', [
  130.             'items' => $photos,
  131.             'album' => $album,
  132.             'item' => $olympiad,
  133.             'group' => $group,
  134.             'stages' => $stages,
  135.             'online' => $online,
  136.             'onlineStages' => $onlineStages,
  137.         ]);
  138.     }
  139. }