<?php
namespace App\Controller\Content;
use App\Dictionary\ContentStatus;
use App\Dto\SearchOptions;
use App\Form\Search\ImagesetSearchForm;
use App\Security\ApiUser;
use App\Service\Client\Content\CategoryService;
use App\Service\Client\Content\CommentService;
use App\Service\Client\Content\ImagesetListingService;
use App\Service\Client\Content\ImagesetService;
use App\Service\Client\MediacenterService;
use App\Service\Client\Payment\PurchaseService;
use App\Service\Search\ImagesetSearchService;
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class ImagesetController extends AbstractController
{
protected ImagesetListingService $service;
protected ImagesetService $imagesetService;
protected ImagesetSearchService $imagesetSearch;
protected CommentService $commentService;
protected MediacenterService $mediacenterService;
public function __construct(
ImagesetListingService $service,
ImagesetService $videoService,
CommentService $commentService,
ImagesetSearchService $imagesetSearch,
MediacenterService $mediacenterService)
{
$this->service = $service;
$this->imagesetService = $videoService;
$this->imagesetSearch = $imagesetSearch;
$this->commentService = $commentService;
$this->mediacenterService = $mediacenterService;
}
/**
* @Route("/bilder/neue-amateur-sex-fotos/{page}", requirements={"page": "\d+"}, defaults={"page": 1})
* @Template()
* @param int $page
* @return array
*/
public function index(int $page = 1): array
{
return [
'imagesets' => $this->service->getNewestImagesets($page, 12),
'page' => $page
];
}
/**
* @Route("/bilder/top-amateursex-fotos-des-monats/{page}", requirements={"page": "\d+"}, defaults={"page": 1})
* @Template()
* @param int $page
* @return array
*/
public function topmonth(int $page = 1): array
{
return [
'imagesets' => $this->service->getBestOfTheMonthImagesets($page, 12),
'page' => $page
];
}
/**
* @Route("/bilder/finden")
* @Template()
* @return array
*/
public function search(Request $request): array
{
$searchOptions = new SearchOptions();
$form = $this->createForm(ImagesetSearchForm::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->imagesetSearch->findImagesets($searchOptions);
return [
'imagesets' => $result,
'form' => $form->createView(),
'minMaxImages' => $this->imagesetSearch->findMinMaxPicsCount()
];
}
/**
* @Route("/bilder/kategorien")
* @Template()
*/
public function categories(CategoryService $categoryService): array
{
return [
'categories' => $categoryService->getTree()
];
}
/**
* @param string $slug
* @return array
* @Route("/amateur-imageset/{slug}")
* @Template()
*/
public function detail(string $slug): array
{
/** @var ApiUser $user */
$user = $this->getUser();
$memberId = $user !== null ? $user->getMemberId() : 0;
$imageset = $this->imagesetService->getImagesetBySlug($slug);
if (!$imageset) {
throw $this->createNotFoundException();
}
if (ContentStatus::ACTIVE !== ((int)($imageset['content']['status'] ?? 0))) {
throw $this->createNotFoundException();
}
$member = $imageset['content']['member'];
if (array_key_exists('is_active', $member) && $member['is_active'] === false) {
throw $this->createNotFoundException();
}
try{
/** @var SlidingPaginationInterface $purchasedImages */
$purchasedImages = $this->imagesetService->purchasedImagesByMember($memberId, $slug, $imageset['content']['id']);
} catch(\Exception $e) {
$purchasedImages = [];
}
$this->mediacenterService->augumentPurchasesOnImageset($imageset, $purchasedImages);
return [
'imageset' => $imageset,
'content' => $imageset['content'],
'member' => $member,
'comments' => $this->commentService->getCommentsByContent($imageset['content']['id'], 1, 100)
];
}
/**
* @param string $slug
* @param int $imageId
* @Route("/amateur-imageset/{slug}/{imageId}", methods={"POST"})
*/
public function purchaseImage(string $slug, int $imageId, PurchaseService $service): Response
{
$user = $this->getUser();
$memberId = $user !== null ? $user->getMemberId() : 0;
$imageset = $this->imagesetService->getImagesetBySlug($slug);
foreach ($imageset['images'] as $loopIndex => $image) {
if ($image['id'] === $imageId) {
break;
}
}
$result = $service->buyContent($imageset['content']['id'], $memberId, $imageId);
if (isset($result['id'])) {
$service->getCacheService()->clearAmateurStatistics($imageset['content']['member']['id']);
$image['purchased'] = true;
return $this->render('content/imageset/detail_showimage.html.twig', [
'imageset' => $imageset,
'content' => $imageset['content'],
'image' => $image,
'loop' => ['index' => $loopIndex],
]);
}
return $this->render('_structure/bootstrap-toast.html.twig', [
'title' => 'Bildkauf',
'message' => $result['message'] ?? 'Fehler',
], new Response(null, Response::HTTP_PAYMENT_REQUIRED));
}
}