<?php
namespace App\Controller\Content;
use App\Dictionary\ContentStatus;
use App\Dto\SearchOptions;
use App\Form\Search\VideoSearchForm;
use App\Security\ApiUser;
use App\Service\Client\Content\CategoryService;
use App\Service\Client\Content\CommentService;
use App\Service\Client\Content\VideoListingService as ListingService;
use App\Service\Client\Content\VideoService;
use App\Service\Search\VideoSearchService;
use Psr\Log\LoggerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Routing\Annotation\Route;
class VideoController extends AbstractController
{
protected ListingService $service;
protected VideoService $videoService;
protected CommentService $commentService;
protected VideoSearchService $videoSearch;
private LoggerInterface $logger;
public function __construct(
LoggerInterface $logger,
ListingService $service,
VideoService $videoService,
CommentService $commentService,
VideoSearchService $videoSearch
) {
$this->service = $service;
$this->videoService = $videoService;
$this->commentService = $commentService;
$this->videoSearch = $videoSearch;
$this->logger = $logger;
}
/**
* @Route("/videos/neuste-amateursex-pornos/{page}", requirements={"page": "\d+"}, defaults={"page": 1})
* @Template()
* @param int $page
* @return array
*/
public function index(int $page = 1): array
{
return [
'videos' => $this->service->getNewestVideos($page, 12),
'page' => $page
];
}
/**
* @Route("/videos/top-amateursex-clips-der-woche/{page}", requirements={"page": "\d+"}, defaults={"page": 1})
* @Template()
* @param int $page
* @return array
*/
public function topweek(int $page = 1): array
{
return [
'videos' => $this->service->getBestOfTheWeekVideos($page, 12),
'page' => $page
];
}
/**
* @Route("/videos/top-amateursex-movies-des-monats/{page}", requirements={"page": "\d+"}, defaults={"page": 1})
* @Template()
* @param int $page
* @return array
*/
public function topmonth(int $page = 1): array
{
return [
'videos' => $this->service->getBestOfTheMonthVideos($page, 12),
'page' => $page
];
}
/**
* @Route("/videos/finden")
* @Template()
* @return array
*/
public function search(Request $request): array
{
$searchOptions = new SearchOptions();
$form = $this->createForm(VideoSearchForm::class, $searchOptions);
$form->handleRequest($request);
if (!$form->isSubmitted()) {//Incoming from global search
$searchOptions->initDefaults()->fromGlobalSearch($request->query);
$form->setData($searchOptions);
}
$searchOptions->pageFromQuery($request->query);
$result = $this->videoSearch->findVideos($searchOptions);
return [
'form' => $form->createView(),
'videos' => $result,
'minMaxDuration' => $this->videoSearch->findMinMaxDurations()
];
}
/**
* @Route("/videos/kategorien")
* @Template()
*/
public function categories(CategoryService $categoryService): array
{
return [
'categories' => $categoryService->getTree()
];
}
/**
* @Route("/amateur-video/{slug}")
* @Template()
* @param string $slug
* @return array
* @throws \Psr\Cache\InvalidArgumentException
* @throws \ReflectionException
*/
public function detail(string $slug): array
{
if (!$video = $this->videoService->getVideoBySlug($slug)) {
throw $this->createNotFoundException();
}
if (ContentStatus::ACTIVE !== ((int)($video['content']['status'] ?? 0))) {
throw $this->createNotFoundException();
}
$member = $video['content']['member'];
if (array_key_exists('is_active', $member) && $member['is_active'] === false) {
throw $this->createNotFoundException();
}
try {
$user = $this->getUser();
if($user instanceof ApiUser) {
$videoLinks = $this->videoService->getLinks($user, $video['id']);
}
} catch(HttpException $e) {
}
return [
'video' => $video,
'videoLinks' => $videoLinks ?? [],
'content' => $video['content'],
'member' => $member,
'comments' => $this->commentService->getCommentsByContent($video['content']['id'], 1, 100)
];
}
/**
* @Route("/amateur-watch-video/{slug}")
* @Template()
* @param string $slug
* @return array
*/
public function watch(string $slug): array|RedirectResponse
{
$allowedContentStatus = [
ContentStatus::ACTIVE,
ContentStatus::INACTIVE,
ContentStatus::DELETED,
ContentStatus::BLOCKED
];
$user = $this->getUser();
if (!$user instanceof ApiUser) {
return $this->redirectToRoute('login');
}
if (!$video = $this->videoService->getVideoBySlug($slug, true)) {
throw $this->createNotFoundException();
}
if (!in_array(((int)$video['content']['status']), $allowedContentStatus)) {
throw $this->createNotFoundException();
}
try {
$user = $this->getUser();
if ($user instanceof ApiUser) {
$videoLinks = $this->videoService->getLinks($user, $video['id']);
}
} catch (\HttpException $exception) {
}
return [
'video' => $video,
'videoLinks' => $videoLinks ?? [],
'content' => $video['content'],
'member' => $video['content']['member'],
'comments' => $this->commentService->getCommentsByContent($video['content']['id'], 1, 100)
];
}
}