src/Controller/Content/ImagesetController.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\ImagesetSearchForm;
  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\ImagesetListingService;
  10. use App\Service\Client\Content\ImagesetService;
  11. use App\Service\Client\MediacenterService;
  12. use App\Service\Client\Payment\PurchaseService;
  13. use App\Service\Search\ImagesetSearchService;
  14. use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
  15. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  16. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use Symfony\Component\HttpFoundation\Response;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. class ImagesetController extends AbstractController
  21. {
  22.     protected ImagesetListingService $service;
  23.     protected ImagesetService $imagesetService;
  24.     protected ImagesetSearchService $imagesetSearch;
  25.     protected CommentService $commentService;
  26.     protected MediacenterService $mediacenterService;
  27.     public function __construct(
  28.         ImagesetListingService $service,
  29.         ImagesetService $videoService,
  30.         CommentService $commentService,
  31.         ImagesetSearchService $imagesetSearch,
  32.         MediacenterService $mediacenterService)
  33.     {
  34.         $this->service $service;
  35.         $this->imagesetService $videoService;
  36.         $this->imagesetSearch $imagesetSearch;
  37.         $this->commentService $commentService;
  38.         $this->mediacenterService $mediacenterService;
  39.     }
  40.     /**
  41.      * @Route("/bilder/neue-amateur-sex-fotos/{page}", requirements={"page": "\d+"}, defaults={"page": 1})
  42.      * @Template()
  43.      * @param int $page
  44.      * @return array
  45.      */
  46.     public function index(int $page 1): array
  47.     {
  48.         return [
  49.             'imagesets' => $this->service->getNewestImagesets($page12),
  50.             'page' => $page
  51.         ];
  52.     }
  53.     /**
  54.      * @Route("/bilder/top-amateursex-fotos-des-monats/{page}", requirements={"page": "\d+"}, defaults={"page": 1})
  55.      * @Template()
  56.      * @param int $page
  57.      * @return array
  58.      */
  59.     public function topmonth(int $page 1): array
  60.     {
  61.         return [
  62.             'imagesets' => $this->service->getBestOfTheMonthImagesets($page12),
  63.             'page' => $page
  64.         ];
  65.     }
  66.     /**
  67.      * @Route("/bilder/finden")
  68.      * @Template()
  69.      * @return array
  70.      */
  71.     public function search(Request $request): array
  72.     {
  73.         $searchOptions = new SearchOptions();
  74.         $form $this->createForm(ImagesetSearchForm::class, $searchOptions);
  75.         $form->handleRequest($request);
  76.         if (!$form->isSubmitted()) {//Incoming from global search
  77.             $searchOptions->initDefaults()->fromGlobalSearch($request->query);
  78.             $form->setData($searchOptions);
  79.         }
  80.         $searchOptions->pageFromQuery($request->query);
  81.         $result $this->imagesetSearch->findImagesets($searchOptions);
  82.         return [
  83.             'imagesets' => $result,
  84.             'form' => $form->createView(),
  85.             'minMaxImages' => $this->imagesetSearch->findMinMaxPicsCount()
  86.         ];
  87.     }
  88.     /**
  89.      * @Route("/bilder/kategorien")
  90.      * @Template()
  91.      */
  92.     public function categories(CategoryService $categoryService): array
  93.     {
  94.         return [
  95.             'categories' => $categoryService->getTree()
  96.         ];
  97.     }
  98.     /**
  99.      * @param string $slug
  100.      * @return array
  101.      * @Route("/amateur-imageset/{slug}")
  102.      * @Template()
  103.      */
  104.     public function detail(string $slug): array
  105.     {
  106.         /** @var ApiUser $user */
  107.         $user $this->getUser();
  108.         $memberId $user !== null $user->getMemberId() : 0;
  109.         $imageset $this->imagesetService->getImagesetBySlug($slug);
  110.         if (!$imageset) {
  111.             throw $this->createNotFoundException();
  112.         }
  113.         if (ContentStatus::ACTIVE !== ((int)($imageset['content']['status'] ?? 0))) {
  114.             throw $this->createNotFoundException();
  115.         }
  116.         $member $imageset['content']['member'];
  117.         if (array_key_exists('is_active'$member) && $member['is_active'] === false) {
  118.             throw $this->createNotFoundException();
  119.         }
  120.         try{
  121.             /** @var SlidingPaginationInterface $purchasedImages */
  122.             $purchasedImages $this->imagesetService->purchasedImagesByMember($memberId$slug$imageset['content']['id']);
  123.         } catch(\Exception $e) {
  124.             $purchasedImages = [];
  125.         }
  126.         $this->mediacenterService->augumentPurchasesOnImageset($imageset$purchasedImages);
  127.         return [
  128.             'imageset' => $imageset,
  129.             'content' => $imageset['content'],
  130.             'member' => $member,
  131.             'comments' => $this->commentService->getCommentsByContent($imageset['content']['id'], 1100)
  132.         ];
  133.     }
  134.     /**
  135.      * @param string $slug
  136.      * @param int $imageId
  137.      * @Route("/amateur-imageset/{slug}/{imageId}", methods={"POST"})
  138.      */
  139.     public function purchaseImage(string $slugint $imageIdPurchaseService $service): Response
  140.     {
  141.         $user $this->getUser();
  142.         $memberId $user !== null $user->getMemberId() : 0;
  143.         $imageset $this->imagesetService->getImagesetBySlug($slug);
  144.         foreach ($imageset['images'] as $loopIndex => $image) {
  145.             if ($image['id'] === $imageId) {
  146.                 break;
  147.             }
  148.         }
  149.         $result $service->buyContent($imageset['content']['id'], $memberId$imageId);
  150.         if (isset($result['id'])) {
  151.             $service->getCacheService()->clearAmateurStatistics($imageset['content']['member']['id']);
  152.             $image['purchased'] = true;
  153.             return $this->render('content/imageset/detail_showimage.html.twig', [
  154.                 'imageset' => $imageset,
  155.                 'content' => $imageset['content'],
  156.                 'image' => $image,
  157.                 'loop' => ['index' => $loopIndex],
  158.             ]);
  159.         }
  160.         return $this->render('_structure/bootstrap-toast.html.twig', [
  161.             'title' => 'Bildkauf',
  162.             'message' => $result['message'] ?? 'Fehler',
  163.         ], new Response(nullResponse::HTTP_PAYMENT_REQUIRED));
  164.     }
  165. }