src/Pumukit/WebTVBundle/Controller/ModulesController.php line 204

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Pumukit\WebTVBundle\Controller;
  4. use Doctrine\ODM\MongoDB\DocumentManager;
  5. use Pumukit\CoreBundle\Controller\WebTVControllerInterface;
  6. use Pumukit\SchemaBundle\Document\MultimediaObject;
  7. use Pumukit\SchemaBundle\Document\Series;
  8. use Pumukit\SchemaBundle\Document\Tag;
  9. use Pumukit\SchemaBundle\Services\AnnounceService;
  10. use Pumukit\SchemaBundle\Services\EmbeddedEventSessionService;
  11. use Pumukit\StatsBundle\Services\StatsService;
  12. use Pumukit\WebTVBundle\Services\BreadcrumbsService;
  13. use Pumukit\WebTVBundle\Services\ListService;
  14. use Pumukit\WebTVBundle\Services\MenuService;
  15. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpFoundation\RequestStack;
  18. use Symfony\Component\HttpFoundation\Response;
  19. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  20. use Symfony\Contracts\Translation\TranslatorInterface;
  21. class ModulesController extends AbstractController implements WebTVControllerInterface
  22. {
  23.     public static $menuResponse;
  24.     protected $menuTemplate '@PumukitWebTV/Modules/widget_menu.html.twig';
  25.     protected $translator;
  26.     protected $statService;
  27.     protected $pumukitSchemaAnnounce;
  28.     protected $menuService;
  29.     protected $listService;
  30.     protected $documentManager;
  31.     protected $requestStack;
  32.     protected $breadcrumbService;
  33.     protected $eventSessionService;
  34.     protected $byTagBlockObjectsByCol;
  35.     protected $limitObjsMostViewed;
  36.     protected $showMostViewedLastMonth;
  37.     protected $mostViewedObjectsByCol;
  38.     protected $showLatestWithPudeNew;
  39.     protected $limitObjsHightlight;
  40.     protected $hightlightObjectsByCol;
  41.     protected $menuHomeTitle;
  42.     protected $menuAnnouncesTitle;
  43.     protected $menuSearchTitle;
  44.     protected $menuMediatecaTitle;
  45.     protected $menuCategoriesTitle;
  46.     protected $limitObjsLiveBlock;
  47.     protected $liveBlockObjectsByCol;
  48.     protected $locales;
  49.     protected $limitObjsRecentlyAdded;
  50.     protected $recentlyAddedObjectsByCol;
  51.     protected $imagePosterSlider;
  52.     public function __construct(
  53.         TranslatorInterface $translator,
  54.         StatsService $statService,
  55.         AnnounceService $pumukitSchemaAnnounce,
  56.         MenuService $menuService,
  57.         ListService $listService,
  58.         DocumentManager $documentManager,
  59.         RequestStack $requestStack,
  60.         BreadcrumbsService $breadcrumbService,
  61.         EmbeddedEventSessionService $eventSessionService,
  62.         $byTagBlockObjectsByCol,
  63.         $limitObjsMostViewed,
  64.         $showMostViewedLastMonth,
  65.         $mostViewedObjectsByCol,
  66.         $showLatestWithPudeNew,
  67.         $limitObjsHightlight,
  68.         $hightlightObjectsByCol,
  69.         $menuHomeTitle,
  70.         $menuAnnouncesTitle,
  71.         $menuSearchTitle,
  72.         $menuMediatecaTitle,
  73.         $menuCategoriesTitle,
  74.         $limitObjsLiveBlock,
  75.         $liveBlockObjectsByCol,
  76.         $locales,
  77.         $limitObjsRecentlyAdded,
  78.         $recentlyAddedObjectsByCol,
  79.         $imagePosterSlider,
  80.     ) {
  81.         $this->translator $translator;
  82.         $this->statService $statService;
  83.         $this->pumukitSchemaAnnounce $pumukitSchemaAnnounce;
  84.         $this->menuService $menuService;
  85.         $this->listService $listService;
  86.         $this->documentManager $documentManager;
  87.         $this->requestStack $requestStack;
  88.         $this->breadcrumbService $breadcrumbService;
  89.         $this->eventSessionService $eventSessionService;
  90.         $this->byTagBlockObjectsByCol $byTagBlockObjectsByCol;
  91.         $this->limitObjsMostViewed $limitObjsMostViewed;
  92.         $this->showMostViewedLastMonth $showMostViewedLastMonth;
  93.         $this->mostViewedObjectsByCol $mostViewedObjectsByCol;
  94.         $this->showLatestWithPudeNew $showLatestWithPudeNew;
  95.         $this->limitObjsHightlight $limitObjsHightlight;
  96.         $this->hightlightObjectsByCol $hightlightObjectsByCol;
  97.         $this->menuHomeTitle $menuHomeTitle;
  98.         $this->menuAnnouncesTitle $menuAnnouncesTitle;
  99.         $this->menuSearchTitle $menuSearchTitle;
  100.         $this->menuMediatecaTitle $menuMediatecaTitle;
  101.         $this->menuCategoriesTitle $menuCategoriesTitle;
  102.         $this->limitObjsLiveBlock $limitObjsLiveBlock;
  103.         $this->liveBlockObjectsByCol $liveBlockObjectsByCol;
  104.         $this->locales $locales;
  105.         $this->limitObjsRecentlyAdded $limitObjsRecentlyAdded;
  106.         $this->recentlyAddedObjectsByCol $recentlyAddedObjectsByCol;
  107.         $this->imagePosterSlider $imagePosterSlider;
  108.     }
  109.     public function mostViewedAction(string $design 'horizontal'): Response
  110.     {
  111.         if ($this->showMostViewedLastMonth) {
  112.             $objects $this->statService->getMostViewedUsingFilters(30$this->limitObjsMostViewed);
  113.             $title $this->translator->trans('Most viewed on the last month');
  114.         } else {
  115.             $objects $this->documentManager->getRepository(MultimediaObject::class)->findStandardBy(
  116.                 [
  117.                     'head' => ['$ne' => true],
  118.                     'tail' => ['$ne' => true],
  119.                 ],
  120.                 ['numview' => -1],
  121.                 $this->limitObjsMostViewed,
  122.                 0
  123.             );
  124.             $title $this->translator->trans('Most viewed');
  125.         }
  126.         return $this->render('@PumukitWebTV/Modules/widget_media.html.twig', [
  127.             'design' => $design,
  128.             'objects' => $objects,
  129.             'objectByCol' => $this->mostViewedObjectsByCol,
  130.             'title' => $title,
  131.             'class' => 'mostviewed',
  132.             'show_info' => true,
  133.             'show_more' => false,
  134.             'show_more_path' => false,
  135.         ]);
  136.     }
  137.     /**
  138.      * Returns all videos with PUDENEW tag.
  139.      */
  140.     public function highlightAction(): Response
  141.     {
  142.         if (!$this->showLatestWithPudeNew) {
  143.             throw new \Exception('Show latest with pudenew parameters must be true to use this module');
  144.         }
  145.         $title $this->translator->trans('Hightlight');
  146.         $last $this->pumukitSchemaAnnounce->getLast($this->limitObjsHightlight);
  147.         return $this->render('@PumukitWebTV/Modules/widget_media.html.twig', [
  148.             'objects' => $last,
  149.             'objectByCol' => $this->hightlightObjectsByCol,
  150.             'class' => 'highlight',
  151.             'title' => $title,
  152.             'show_info' => true,
  153.             'show_more' => false,
  154.             'show_more_path' => 'pumukit_webtv_announces_latestuploads',
  155.         ]);
  156.     }
  157.     /**
  158.      * Returns all videos without PUDENEW tag.
  159.      */
  160.     public function recentlyAddedWithoutHighlightAction(string $design 'horizontal'): Response
  161.     {
  162.         $last $this->documentManager->getRepository(MultimediaObject::class)->findStandardBy(
  163.             [
  164.                 'tags.cod' => ['$ne' => 'PUDENEW'],
  165.                 'head' => ['$ne' => true],
  166.                 'tail' => ['$ne' => true],
  167.             ],
  168.             [
  169.                 'public_date' => -1,
  170.             ],
  171.             $this->limitObjsRecentlyAdded,
  172.             0
  173.         );
  174.         return $this->render('@PumukitWebTV/Modules/widget_media.html.twig', [
  175.             'design' => $design,
  176.             'objects' => $last,
  177.             'objectByCol' => $this->recentlyAddedObjectsByCol,
  178.             'title' => $this->translator->trans('Recently added'),
  179.             'class' => 'recently',
  180.             'show_info' => true,
  181.             'show_more' => false,
  182.             'show_more_path' => 'pumukit_webtv_announces_latestuploads',
  183.         ]);
  184.     }
  185.     /**
  186.      * Returns all videos without PUDENEW tag.
  187.      */
  188.     public function recentlyAddedAllAction(string $design 'horizontal'): Response
  189.     {
  190.         $last $this->documentManager->getRepository(MultimediaObject::class)->findStandardBy(
  191.             [
  192.                 'head' => ['$ne' => true],
  193.                 'tail' => ['$ne' => true],
  194.             ],
  195.             [
  196.                 'public_date' => -1,
  197.             ],
  198.             $this->limitObjsRecentlyAdded,
  199.             0
  200.         );
  201.         return $this->render('@PumukitWebTV/Modules/widget_media.html.twig', [
  202.             'design' => $design,
  203.             'objects' => $last,
  204.             'objectByCol' => $this->recentlyAddedObjectsByCol,
  205.             'title' => $this->translator->trans('Recently added'),
  206.             'class' => 'recently',
  207.             'show_info' => true,
  208.             'show_more' => false,
  209.             'show_more_path' => 'pumukit_webtv_announces_latestuploads',
  210.         ]);
  211.     }
  212.     public function statsAction(): Response
  213.     {
  214.         $mmRepo $this->documentManager->getRepository(MultimediaObject::class);
  215.         $seriesRepo $this->documentManager->getRepository(Series::class);
  216.         $counts = [
  217.             'series' => $seriesRepo->countPublic(),
  218.             'mms' => $mmRepo->count(),
  219.             'hours' => $mmRepo->countDuration(),
  220.         ];
  221.         return $this->render('@PumukitWebTV/Modules/widget_stats.html.twig', [
  222.             'counts' => $counts,
  223.         ]);
  224.     }
  225.     public function breadcrumbsAction(): Response
  226.     {
  227.         return $this->render('@PumukitWebTV/Modules/widget_breadcrumb.html.twig', ['breadcrumbs' => $this->breadcrumbService->getBreadcrumbs()]);
  228.     }
  229.     public function languageAction(): Response
  230.     {
  231.         if ((is_countable($this->locales) ? count($this->locales) : 0) <= 1) {
  232.             return new Response('');
  233.         }
  234.         return $this->render('@PumukitWebTV/Modules/widget_language.html.twig', ['languages' => $this->locales]);
  235.     }
  236.     public function categoriesAction(Request $requeststring $titlestring $class$categoriesint $cols 6bool $sort true): Response
  237.     {
  238.         if (!$categories) {
  239.             throw new NotFoundHttpException('Categories not found');
  240.         }
  241.         if ($sort) {
  242.             if (is_array($categories)) {
  243.                 $tags $this->documentManager->createQueryBuilder(Tag::class)
  244.                     ->field('cod')->in($categories)
  245.                     ->field('display')->equals(true)
  246.                     ->sort('title.'.$request->getLocale())
  247.                     ->getQuery()
  248.                     ->execute()
  249.                 ;
  250.             } else {
  251.                 $tag $this->documentManager->getRepository(Tag::class)->findOneBy([
  252.                     'cod' => $categories,
  253.                 ]);
  254.                 if (!$tag) {
  255.                     throw new NotFoundHttpException('Category not found');
  256.                 }
  257.                 $tags $tag->getChildren();
  258.             }
  259.         } else {
  260.             $tags = [];
  261.             foreach ($categories as $categoryCod) {
  262.                 $tags[] = $this->documentManager->getRepository(Tag::class)->findOneBy(['cod' => $categoryCod'display' => true]);
  263.             }
  264.         }
  265.         return $this->render('@PumukitWebTV/Modules/widget_categories.html.twig', [
  266.             'objectByCol' => $cols,
  267.             'objects' => $tags,
  268.             'objectsData' => $categories,
  269.             'title' => $this->translator->trans($title),
  270.             'class' => $class,
  271.         ]);
  272.     }
  273.     /**
  274.      * This module was create to keep BC. Uses vertical design by default.
  275.      * Returns:
  276.      * - showPudenew = true => Only videos with PUDENEW tag and announce property true
  277.      * - showPudenew = false => Returns all videos.
  278.      */
  279.     public function legacyRecentlyAdded(string $design 'vertical')
  280.     {
  281.         $last $this->pumukitSchemaAnnounce->getLast($this->limitObjsRecentlyAdded$this->showLatestWithPudeNew);
  282.         return $this->render('@PumukitWebTV/Modules/widget_media.html.twig', [
  283.             'design' => $design,
  284.             'objects' => $last,
  285.             'objectByCol' => $this->recentlyAddedObjectsByCol,
  286.             'title' => $this->translator->trans('Recently added'),
  287.             'class' => 'recently',
  288.             'show_info' => true,
  289.             'show_more' => false,
  290.             'show_more_path' => 'pumukit_webtv_announces_latestuploads',
  291.         ]);
  292.     }
  293.     /**
  294.      * This module represents old categories block of PuMuKIT. Remember fix responsive design ( depends of height of images ).
  295.      */
  296.     public function legacyCategoriesAction(): Response
  297.     {
  298.         return $this->render('@PumukitWebTV/Modules/widget_block_categories.html.twig', []);
  299.     }
  300.     /**
  301.      * This module represents old menu block of PuMuKIT ( vertical menu ). This design is just bootstrap panel example.
  302.      */
  303.     public function legacyMenuAction(): Response
  304.     {
  305.         if (self::$menuResponse) {
  306.             return self::$menuResponse;
  307.         }
  308.         $params $this->getLegacyMenuElements();
  309.         self::$menuResponse $this->render($this->menuTemplate$params);
  310.         return self::$menuResponse;
  311.     }
  312.     public function liveBlockAction(): Response
  313.     {
  314.         $objects $this->listService->getLives($this->limitObjsLiveBlock);
  315.         return $this->render('@PumukitWebTV/Modules/widget_event.html.twig', [
  316.             'objects' => $objects,
  317.             'objectByCol' => $this->liveBlockObjectsByCol,
  318.             'title' => $this->translator->trans('Live events'),
  319.             'class' => 'live_events',
  320.             'show_info' => false,
  321.             'show_more' => false,
  322.             'show_more_path' => 'pumukit_webtv_events',
  323.         ]);
  324.     }
  325.     public function wallBlockAction(): Response
  326.     {
  327.         $objects $this->listService->getWallVideos();
  328.         return $this->render('@PumukitWebTV/Modules/widget_wall.html.twig', [
  329.             'objects' => $objects,
  330.             'objectByCol' => 1,
  331.             'title' => $this->translator->trans('Wall'),
  332.             'class' => 'wall_block',
  333.             'show_info' => false,
  334.             'show_more' => false,
  335.         ]);
  336.     }
  337.     public function searchBlockAction(): Response
  338.     {
  339.         return $this->render('@PumukitWebTV/Modules/widget_search.html.twig', []);
  340.     }
  341.     public function byTagBlockAction(string $tagCodstring $title): Response
  342.     {
  343.         $objects $this->listService->getVideosByTag($tagCod$this->byTagBlockObjectsByCol);
  344.         return $this->render('@PumukitWebTV/Modules/widget_media.html.twig', [
  345.             'objects' => $objects,
  346.             'objectByCol' => $this->byTagBlockObjectsByCol,
  347.             'title' => $this->translator->trans($title),
  348.             'class' => 'by-tag-block',
  349.             'show_info' => true,
  350.             'show_more' => false,
  351.             'show_more_path' => false,
  352.         ]);
  353.     }
  354.     public function embedVideoBlockAction(string $tagCod): Response
  355.     {
  356.         $object $this->listService->getEmbedVideoBlock($tagCod);
  357.         return $this->render('@PumukitWebTV/Modules/widget_player.html.twig', [
  358.             'object' => $object,
  359.             'autostart' => false,
  360.         ]);
  361.     }
  362.     public function eventBlockAction()
  363.     {
  364.         $events $this->eventSessionService->findWidgetEvents(3);
  365.         $limitEvents 3;
  366.         return $this->render('@PumukitWebTV/Modules/widget_events.html.twig', [
  367.             'title' => $this->translator->trans('Events'),
  368.             'events' => $events,
  369.             'limitEvents' => $limitEvents,
  370.         ]);
  371.     }
  372.     public function sliderAction()
  373.     {
  374.         $multimediaObjects $this->documentManager->getRepository(MultimediaObject::class)
  375.             ->createStandardQueryBuilder()
  376.             ->field('tags.cod')
  377.             ->equals('PUDEWALL')
  378.             ->getQuery()
  379.             ->execute()
  380.         ;
  381.         $images $this->imagePosterSlider;
  382.         return $this->render('@PumukitWebTV/Modules/widget_slider.html.twig', [
  383.             'title' => $this->translator->trans('News'),
  384.             'posterEvent' => $images,
  385.             'multimediaObjects' => $multimediaObjects,
  386.         ]);
  387.     }
  388.     private function getLegacyMenuElements(): array
  389.     {
  390.         [$events$channels$liveEventTypeSession] = $this->menuService->getMenuEventsElement();
  391.         return [
  392.             'events' => $events,
  393.             'channels' => $channels,
  394.             'type' => $liveEventTypeSession,
  395.             'menu_selected' => $this->requestStack->getMasterRequest()->get('_route'),
  396.             'home_title' => $this->menuHomeTitle,
  397.             'announces_title' => $this->menuAnnouncesTitle,
  398.             'search_title' => $this->menuSearchTitle,
  399.             'catalogue_title' => $this->menuMediatecaTitle,
  400.             'categories_title' => $this->menuCategoriesTitle,
  401.         ];
  402.     }
  403. }