src/Controller/Content/PublicVideoController.php line 62

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Content;
  3. use App\Entity\Category;
  4. use App\Entity\Content;
  5. use App\Entity\ContentVideo;
  6. use App\Entity\Member;
  7. use App\Service\Content\ContentService;
  8. use App\Service\Content\VideoService;
  9. use App\StructSerializer\Main\StructOptions;
  10. use App\StructSerializer\Main\StructSerializer;
  11. use Doctrine\ORM\NonUniqueResultException;
  12. use Nelmio\ApiDocBundle\Annotation\Model;
  13. use Swagger\Annotations as SWG;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. use Symfony\Component\HttpFoundation\JsonResponse;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. /**
  19.  * @Route("/api/public/content")
  20.  */
  21. class PublicVideoController extends AbstractController
  22. {
  23.     protected VideoService $service;
  24.     protected ContentService $contentService;
  25.     protected StructSerializer $serializer2;
  26.     protected StructOptions $listStructOptions;
  27.     public function __construct(
  28.         VideoService $service,
  29.         ContentService $contentService,
  30.         StructSerializer $serializer2,
  31.     ) {
  32.         $this->service $service;
  33.         $this->contentService $contentService;
  34.         $this->serializer2 $serializer2;
  35.         $this->listStructOptions StructOptions::create();
  36.         $this->listStructOptions->skipProperty(Content::class, 'categories');
  37.         $this->listStructOptions->skipProperty(Content::class, 'comments');
  38.         $this->listStructOptions->skipProperty(Content::class, 'actors');
  39.         $this->listStructOptions->skipProperty(Content::class, 'imageset');
  40.         $this->listStructOptions->skipProperty(Member::class, 'main_photo');
  41.         $this->listStructOptions->skipProperty(Member::class, 'member_online');
  42.     }
  43.     /**
  44.      * @SWG\Get(tags={"Content", "Video"},
  45.      *
  46.      *    @SWG\Response(response=200, description="Paginated list of the most recently published videos, active only",
  47.      *
  48.      *     @SWG\Schema(ref=@Model(type=App\Entity\Content::class, groups={"contentlist"}))),
  49.      *
  50.      *    @SWG\Parameter(name="page", in="path", type="integer", required=true, description="Requested page for pagination"),
  51.      *    @SWG\Parameter(name="limit", in="query", type="integer", required=false, default=20, description="Number of items per page for pagination")
  52.      * )
  53.      *
  54.      * @Route("/videos/{page}", methods={"GET"})
  55.      */
  56.     public function index(Request $requestint $page): JsonResponse
  57.     {
  58.         $limit $request->query->getInt('limit'20);
  59.         $paginator $this->service->getRepository()->getFreshVideos($page$limit);
  60.         return new JsonResponse([
  61.             'data' => $this->serializer2->multipleToArray($this->listStructOptions,
  62.                 $paginator->getIterator()->getArrayCopy()),
  63.             'total' => $paginator->count(),
  64.         ]);
  65.     }
  66.     /**
  67.      * @SWG\Get(tags={"Content", "Video"},
  68.      *
  69.      *    @SWG\Response(response=200, description="Details of the requested video ID",
  70.      *
  71.      *     @SWG\Schema(ref=@Model(type=App\Entity\Content::class, groups={"contentlist", "contentdetail", "previewphotolist", "memberonlineindex"}))),
  72.      *
  73.      *    @SWG\Parameter(name="video", in="path", type="integer", required=true, description="Video ID in question"),
  74.      * )
  75.      *
  76.      * @Route("/video/{video}", methods={"GET"}, requirements={"video": "\d+"})
  77.      */
  78.     public function detail(ContentVideo $video): JsonResponse
  79.     {
  80.         $options StructOptions::create();
  81.         $options->skipProperty(Content::class, 'imageset');
  82.         $options->skipProperty(Member::class, 'member_online');
  83.         return new JsonResponse(
  84.             $this->serializer2->toArray($options$video),
  85.         );
  86.     }
  87.     /**
  88.      * @SWG\Get(tags={"Content", "Video"},
  89.      *
  90.      *    @SWG\Response(response=200, description="Find a video by slug",
  91.      *
  92.      *     @SWG\Schema(ref=@Model(type=App\Entity\Content::class, groups={"contentlist", "contentdetail", "actorlist", "previewphotolist", "memberonlineindex", "membermainphoto"}))),
  93.      *
  94.      *    @SWG\Parameter(name="slug", in="path", type="string", required=true, description="Unique slug url"),
  95.      *    @SWG\Parameter(name="ignoreContentStatus", in="query", type="boolean", required=false, description="Should content status ignored?")
  96.      * )
  97.      *
  98.      * @Route("/video/slug/{slug}", methods={"GET"}, priority=1)
  99.      *
  100.      * @throws NonUniqueResultException
  101.      */
  102.     public function slug(Request $requeststring $slug): JsonResponse
  103.     {
  104.         $ignoreContentStatus = (bool) $request->query->get('ignoreContentStatus') || false;
  105.         if (!$video $this->service->findBySlug($slug$ignoreContentStatus)) {
  106.             throw $this->createNotFoundException('Video not found by slug.');
  107.         }
  108.         $options StructOptions::create();
  109.         $options->skipProperty(Content::class, 'imageset');
  110.         return new JsonResponse($this->serializer2->toArray($options$video));
  111.     }
  112.     /**
  113.      * @SWG\Get(tags={"Content", "Video"},
  114.      *
  115.      *    @SWG\Response(response=200, description="Paginated list of the best rated videos of the last 7 days",
  116.      *
  117.      *     @SWG\Schema(ref=@Model(type=App\Entity\Content::class, groups={"contentlist", "previewphotolist"}))),
  118.      *
  119.      *    @SWG\Parameter(name="page", in="path", type="integer", description="Requested page for pagination"),
  120.      *    @SWG\Parameter(name="limit", in="query", type="integer", description="Number of items per page for pagination")
  121.      * )
  122.      *
  123.      * @Route("/videos/bestoftheweek/{page}", methods={"GET"}, requirements={"page": "\d+"})
  124.      *
  125.      * @return JsonResponse
  126.      */
  127.     public function bestoftheweek(Request $requestint $page)
  128.     {
  129.         $limit $request->query->getInt('limit'20);
  130.         $paginator $this->service->getRepository()->getBestVideosOfTheWeek($page$limit);
  131.         return new JsonResponse([
  132.             'data' => $this->serializer2->multipleToArray($this->listStructOptions,
  133.                 $paginator->getIterator()->getArrayCopy()),
  134.             'total' => $paginator->count(),
  135.         ]);
  136.     }
  137.     /**
  138.      * @SWG\Get(
  139.      *    tags={"Content", "Video"},
  140.      *
  141.      *    @SWG\Response(
  142.      *     response=200,
  143.      *     description="Paginated list of the best rated videos of the last 30 days",
  144.      *
  145.      *     @SWG\Schema(ref=@Model(type=App\Entity\Content::class, groups={"contentlist", "previewphotolist"}))),
  146.      *
  147.      *    @SWG\Parameter(name="page", in="path", type="integer", required=true, description="Requested page for pagination"),
  148.      *    @SWG\Parameter(name="limit", in="query", type="integer", required=false, default=20, description="Number of items per page for pagination")
  149.      * )
  150.      *
  151.      * @Route("/videos/bestofthemonth/{page}", methods={"GET"}, requirements={"page": "\d+"})
  152.      *
  153.      * @return JsonResponse
  154.      */
  155.     public function bestofthemonth(Request $requestint $page)
  156.     {
  157.         $limit $request->query->getInt('limit'20);
  158.         $paginator $this->service->getRepository()->getBestVideosOfTheMonth($page$limit);
  159.         return new JsonResponse([
  160.             'data' => $this->serializer2->multipleToArray($this->listStructOptions,
  161.                 $paginator->getIterator()->getArrayCopy()),
  162.             'total' => $paginator->count(),
  163.         ]);
  164.     }
  165.     /**
  166.      * @SWG\Get(tags={"Content", "Video"},
  167.      *
  168.      *    @SWG\Response(response=200, description="Paginated list of videos in a given category",
  169.      *
  170.      *     @SWG\Schema(ref=@Model(type=App\Entity\Content::class, groups={"contentlist", "previewphotolist"}))),
  171.      *
  172.      *    @SWG\Parameter(name="category", in="path", type="integer", required=true, description="Category ID in question"),
  173.      *    @SWG\Parameter(name="page", in="path", type="integer", required=true, description="Requested page for pagination"),
  174.      *    @SWG\Parameter(name="limit", in="query", type="integer", required=false, default=18, description="Number of items per page for pagination")
  175.      * )
  176.      *
  177.      * @Route("/videos/category/{category}/{page}", methods={"GET"}, requirements={"category": "\d+", "page": "\d+"})
  178.      *
  179.      * @return JsonResponse
  180.      */
  181.     public function category(Request $requestCategory $categoryint $page)
  182.     {
  183.         $limit $request->query->getInt('limit'18);
  184.         $paginator $this->service->getActiveVideosByCategory($category$page$limit);
  185.         return new JsonResponse([
  186.             'data' => $this->serializer2->multipleToArray($this->listStructOptions,
  187.                 $paginator->getIterator()->getArrayCopy()),
  188.             'total' => $paginator->count(),
  189.         ]);
  190.     }
  191. }