src/Controller/Content/VideoController.php line 115

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Content;
  3. use App\Dictionary\ContentStatus;
  4. use App\Dto\SearchOptions;
  5. use App\Form\Search\VideoSearchForm;
  6. use App\Security\ApiUser;
  7. use App\Service\Client\Content\CategoryService;
  8. use App\Service\Client\Content\CommentService;
  9. use App\Service\Client\Content\VideoListingService as ListingService;
  10. use App\Service\Client\Content\VideoService;
  11. use App\Service\Search\VideoSearchService;
  12. use Psr\Log\LoggerInterface;
  13. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. use Symfony\Component\HttpFoundation\RedirectResponse;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpKernel\Exception\HttpException;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. class VideoController extends AbstractController
  20. {
  21.     protected ListingService $service;
  22.     protected VideoService $videoService;
  23.     protected CommentService $commentService;
  24.     protected VideoSearchService $videoSearch;
  25.     private LoggerInterface $logger;
  26.     public function __construct(
  27.         LoggerInterface $logger,
  28.         ListingService $service,
  29.         VideoService $videoService,
  30.         CommentService $commentService,
  31.         VideoSearchService $videoSearch
  32.     ) {
  33.         $this->service $service;
  34.         $this->videoService $videoService;
  35.         $this->commentService $commentService;
  36.         $this->videoSearch $videoSearch;
  37.         $this->logger $logger;
  38.     }
  39.     /**
  40.      * @Route("/videos/neuste-amateursex-pornos/{page}", requirements={"page": "\d+"}, defaults={"page": 1})
  41.      * @Template()
  42.      * @param int $page
  43.      * @return array
  44.      */
  45.     public function index(int $page 1): array
  46.     {
  47.         return [
  48.             'videos' => $this->service->getNewestVideos($page12),
  49.             'page' => $page
  50.         ];
  51.     }
  52.     /**
  53.      * @Route("/videos/top-amateursex-clips-der-woche/{page}", requirements={"page": "\d+"}, defaults={"page": 1})
  54.      * @Template()
  55.      * @param int $page
  56.      * @return array
  57.      */
  58.     public function topweek(int $page 1): array
  59.     {
  60.         return [
  61.             'videos' => $this->service->getBestOfTheWeekVideos($page12),
  62.             'page' => $page
  63.         ];
  64.     }
  65.     /**
  66.      * @Route("/videos/top-amateursex-movies-des-monats/{page}", requirements={"page": "\d+"}, defaults={"page": 1})
  67.      * @Template()
  68.      * @param int $page
  69.      * @return array
  70.      */
  71.     public function topmonth(int $page 1): array
  72.     {
  73.         return [
  74.             'videos' => $this->service->getBestOfTheMonthVideos($page12),
  75.             'page' => $page
  76.         ];
  77.     }
  78.     /**
  79.      * @Route("/videos/finden")
  80.      * @Template()
  81.      * @return array
  82.      */
  83.     public function search(Request $request): array
  84.     {
  85.         $searchOptions = new SearchOptions();
  86.         $form $this->createForm(VideoSearchForm::class, $searchOptions);
  87.         $form->handleRequest($request);
  88.         if (!$form->isSubmitted()) {//Incoming from global search
  89.             $searchOptions->initDefaults()->fromGlobalSearch($request->query);
  90.             $form->setData($searchOptions);
  91.         }
  92.         $searchOptions->pageFromQuery($request->query);
  93.         $result $this->videoSearch->findVideos($searchOptions);
  94.         return [
  95.             'form' => $form->createView(),
  96.             'videos' => $result,
  97.             'minMaxDuration' => $this->videoSearch->findMinMaxDurations()
  98.         ];
  99.     }
  100.     /**
  101.      * @Route("/videos/kategorien")
  102.      * @Template()
  103.      */
  104.     public function categories(CategoryService $categoryService): array
  105.     {
  106.         return [
  107.             'categories' => $categoryService->getTree()
  108.         ];
  109.     }
  110.     /**
  111.      * @Route("/amateur-video/{slug}")
  112.      * @Template()
  113.      * @param string $slug
  114.      * @return array
  115.      * @throws \Psr\Cache\InvalidArgumentException
  116.      * @throws \ReflectionException
  117.      */
  118.     public function detail(string $slug): array
  119.     {
  120.         if (!$video $this->videoService->getVideoBySlug($slug)) {
  121.             throw $this->createNotFoundException();
  122.         }
  123.         if (ContentStatus::ACTIVE !== ((int)($video['content']['status'] ?? 0))) {
  124.             throw $this->createNotFoundException();
  125.         }
  126.         $member $video['content']['member'];
  127.         if (array_key_exists('is_active'$member) && $member['is_active'] === false) {
  128.             throw $this->createNotFoundException();
  129.         }
  130.         try {
  131.             $user $this->getUser();
  132.             if($user instanceof ApiUser) {
  133.                 $videoLinks $this->videoService->getLinks($user$video['id']);
  134.             }
  135.         } catch(HttpException $e) {
  136.         }
  137.         return [
  138.             'video' => $video,
  139.             'videoLinks' => $videoLinks ?? [],
  140.             'content' => $video['content'],
  141.             'member' => $member,
  142.             'comments' => $this->commentService->getCommentsByContent($video['content']['id'], 1100)
  143.         ];
  144.     }
  145.     /**
  146.      * @Route("/amateur-watch-video/{slug}")
  147.      * @Template()
  148.      * @param string $slug
  149.      * @return array
  150.      */
  151.     public function watch(string $slug): array|RedirectResponse
  152.     {
  153.         $allowedContentStatus = [
  154.             ContentStatus::ACTIVE,
  155.             ContentStatus::INACTIVE,
  156.             ContentStatus::DELETED,
  157.             ContentStatus::BLOCKED
  158.         ];
  159.         $user $this->getUser();
  160.         if (!$user instanceof ApiUser) {
  161.             return $this->redirectToRoute('login');
  162.         }
  163.         if (!$video $this->videoService->getVideoBySlug($slugtrue)) {
  164.             throw $this->createNotFoundException();
  165.         }
  166.         if (!in_array(((int)$video['content']['status']), $allowedContentStatus)) {
  167.             throw $this->createNotFoundException();
  168.         }
  169.         try {
  170.             $user $this->getUser();
  171.             if ($user instanceof ApiUser) {
  172.                 $videoLinks $this->videoService->getLinks($user$video['id']);
  173.             }
  174.         } catch (\HttpException $exception) {
  175.         }
  176.         return [
  177.             'video' => $video,
  178.             'videoLinks' => $videoLinks ?? [],
  179.             'content' => $video['content'],
  180.             'member' => $video['content']['member'],
  181.             'comments' => $this->commentService->getCommentsByContent($video['content']['id'], 1100)
  182.         ];
  183.     }
  184. }