src/Controller/SaloonListController.php line 73

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by simpson <simpsonwork@gmail.com>
  4.  * Date: 2019-04-15
  5.  * Time: 19:51
  6.  */
  7. namespace App\Controller;
  8. use AngelGamez\PorpaginasBundle\Controller\PaginationTrait;
  9. use App\Entity\Location\City;
  10. use App\Repository\DistrictRepository;
  11. use App\Repository\SaloonRepository;
  12. use App\Service\CountryCurrencyResolver;
  13. use App\Service\Features;
  14. use App\Service\ProfileListingRecommendationsFiller;
  15. use App\Service\ResponsiveAssetsService;
  16. use App\Service\SaloonListSpecificationService;
  17. use App\Specification\QueryModifier\FreeProfilesFeatureSaloonOrder;
  18. use App\Specification\Saloon\SaloonIsNotHidden;
  19. use App\Specification\QueryModifier\SaloonOrderedByStatus;
  20. use App\Specification\Saloon\SaloonInMoskowDistricts;
  21. use App\Specification\Saloon\SaloonIsActive;
  22. use App\Specification\Saloon\SaloonIsLocated;
  23. use App\Specification\Saloon\SaloonIsVip;
  24. use Flagception\Bundle\FlagceptionBundle\Annotations\Feature;
  25. use Happyr\DoctrineSpecification\Spec;
  26. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  27. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  28. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  29. use Symfony\Component\HttpFoundation\Request;
  30. use Symfony\Component\HttpFoundation\RequestStack;
  31. use Symfony\Component\HttpFoundation\Response;
  32. use Symfony\Component\Routing\Annotation\Route;
  33. use OpenApi\Attributes as OA;
  34. use Porpaginas\Page;
  35. class SaloonListController extends AbstractController
  36. {
  37.     use PaginationTrait;
  38.     use ResponseTrait;
  39.     const ENTRIES_ON_PAGE 36;
  40.     private mixed $perPage;
  41.     public function __construct(
  42.         private SaloonRepository $saloonRepository,
  43.         private DistrictRepository $districtRepository,
  44.         private Features $features,
  45.         private RequestStack $requestStack,
  46.         private ResponsiveAssetsService $responsiveAssetsService,
  47.         private ProfileListingRecommendationsFiller $profileListingRecommendationsFiller,
  48.         private SaloonListSpecificationService $saloonListSpecificationService,
  49.         ParameterBagInterface $parameterBag
  50.     )
  51.     {
  52.         $this->perPage $parameterBag->get('saloon_list.per_page');
  53.     }
  54.     /**
  55.      * @Feature("has_saloons")
  56.      */
  57.     #[ParamConverter('city'converter'city_converter')]
  58.     #[Route("/api/saloons/listing/city/{city}"name"api.saloon_listing.by_city"methods"GET"format"json")]
  59.     #[OA\Parameter(name"page"in"query"schema: new OA\Schema(type"integer", default: 1minimum1))]
  60.     #[OA\Tag(name"SaloonListing")]
  61.     #[OA\Response(
  62.         response200,
  63.         description'',
  64.         content: new OA\JsonContent(ref"#/components/schemas/SaloonListingPage")
  65.     )]
  66.     public function listByCity(Request $requestCity $city): Response
  67.     {
  68.         $criteria $this->saloonListSpecificationService->listByCity($city);
  69.         return $this->saloonListing($request$city$criteria);
  70.     }
  71.     /** @Feature("salons_massage") */
  72.     #[ParamConverter('city'converter'city_converter')]
  73.     #[Route("/api/saloons/listing/city/{city}/massage"name"api.saloon_listing.massage"methods"GET"format"json")]
  74.     #[OA\Parameter(name"page"in"query"schema: new OA\Schema(type"integer", default: 1minimum1))]
  75.     #[OA\Tag(name"SaloonListing")]
  76.     #[OA\Response(response200description''content: new OA\JsonContent(ref"#/components/schemas/SaloonListingPage"))]
  77.     public function listMassage(Request $requestCity $city): Response
  78.     {
  79.         return $this->saloonListing($request$city$this->saloonListSpecificationService->listMassage($city));
  80.     }
  81.     /** @Feature("salons_brothel") */
  82.     #[ParamConverter('city'converter'city_converter')]
  83.     #[Route("/api/saloons/listing/city/{city}/brothels"name"api.saloon_listing.brothels"methods"GET"format"json")]
  84.     #[OA\Parameter(name"page"in"query"schema: new OA\Schema(type"integer", default: 1minimum1))]
  85.     #[OA\Tag(name"SaloonListing")]
  86.     #[OA\Response(response200description''content: new OA\JsonContent(ref"#/components/schemas/SaloonListingPage"))]
  87.     public function listBrothel(Request $requestCity $city): Response
  88.     {
  89.         return $this->saloonListing($request$city$this->saloonListSpecificationService->listBrothel($city));
  90.     }
  91.     private function saloonListing(Request $requestCity $city\Happyr\DoctrineSpecification\Filter\Filter $criteria): Response
  92.     {
  93.         $result $this->saloonRepository->matchingSpec($criteria);
  94.         $saloons $this->takePage($result$this->perPage);
  95.         $recommendationsFill $this->getRecommendationsFill($city$saloons);
  96.         if ($this->isApiRequest($request)) {
  97.             return $this->json($saloonscontext: ['groups' => ['listing']]);
  98.         }
  99.         $request->attributes->set('saloons_count'$saloons->totalCount());
  100.         $request->attributes->set('city'$city);
  101.         return $this->render('SaloonList/list.html.twig', [
  102.             'saloons' => $saloons,
  103.             'recommended_profiles' => $recommendationsFill['profiles'],
  104.             'ssr_recommended_profiles' => $recommendationsFill['ssr_profiles'],
  105.             'recommendations_fill_applied' => $recommendationsFill['applied'],
  106.             'recommendations_fill_original_count' => $recommendationsFill['original_count'],
  107.         ]);
  108.     }
  109.     /**
  110.      * @Feature("has_saloons")
  111.      */
  112.     #[ParamConverter('city'converter'city_converter')]
  113.     public function listForVipRelax(CountryCurrencyResolver $countryCurrencyResolverRequest $requestCity $city): Response
  114.     {
  115.         $minPrice $countryCurrencyResolver->getValueByCountryCode($city->getCountryCode(), [
  116.             'RUB' => 4000,
  117.             'UAH' => 1200,
  118.             'USD' => 100,
  119.             'EUR' => 100,
  120.         ]);
  121.         $districts = [];
  122.         foreach (SaloonInMoskowDistricts::$districtsUri as $uri) {
  123.             if (null !== $district $this->districtRepository->ofUriIdentityWithinCity($uri$city)) {
  124.                 $districts[] = $district;
  125.             }
  126.         }
  127.         if (!empty($districts)) {
  128.             $criteria Spec::andX(
  129.                 $this->features->free_profiles() ? new SaloonIsNotHidden() : new SaloonIsActive(),
  130.                 SaloonIsLocated::withinCity($city),
  131.                 new SaloonIsVip($city$districts$minPrice),
  132.                 $this->features->free_profiles() ? new FreeProfilesFeatureSaloonOrder() : new SaloonOrderedByStatus()
  133.             );
  134.             $result $this->saloonRepository->matchingSpec($criteria);
  135.             $saloons $this->takePage($result$this->perPage);
  136.         } else {
  137.             $saloons $this->emptyPagination();
  138.         }
  139.         $recommendationsFill $this->getRecommendationsFill($city$saloons);
  140.         return $this->render('SaloonList/list.html.twig', [
  141.             'saloons' => $saloons,
  142.             'recommended_profiles' => $recommendationsFill['profiles'],
  143.             'ssr_recommended_profiles' => $recommendationsFill['ssr_profiles'],
  144.             'recommendations_fill_applied' => $recommendationsFill['applied'],
  145.             'recommendations_fill_original_count' => $recommendationsFill['original_count'],
  146.         ]);
  147.     }
  148.     private function getRecommendationsFill(City $cityPage $saloons): array
  149.     {
  150.         $fill $this->profileListingRecommendationsFiller->recommendedProfilesForPage($city$saloons);
  151.         $fill['ssr_profiles'] = !$fill['applied']
  152.             ? $this->profileListingRecommendationsFiller->popularProfilesForBlock($city$saloons)
  153.             : [];
  154.         return $fill;
  155.     }
  156.     protected function render(string $view, array $parameters = [], Response $response null): Response
  157.     {
  158.         if($this->requestStack->getCurrentRequest()->getMethod() == 'POST') {
  159.             $response parent::render('SaloonList/list.saloons.html.twig'$parameters$response);
  160.             $content preg_replace('/\s{2,}/'' '$response->getContent());
  161.             $response->setContent($content);
  162.             return $response;
  163.         } else {
  164.             return parent::render($view$parameters$response);
  165.         }
  166.     }
  167. }