src/Controller/ProfileListController.php line 539

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by simpson <simpsonwork@gmail.com>
  4.  * Date: 2019-03-19
  5.  * Time: 22:28
  6.  */
  7. namespace App\Controller;
  8. use App\Bridge\Porpaginas\Doctrine\ORM\FakeORMQueryPage;
  9. use App\Entity\Location\City;
  10. use App\Entity\Location\County;
  11. use App\Entity\Location\District;
  12. use App\Entity\Location\Station;
  13. use App\Entity\Profile\BodyTypes;
  14. use App\Entity\Profile\BreastTypes;
  15. use App\Entity\Profile\Genders;
  16. use App\Entity\Profile\HairColors;
  17. use App\Entity\Profile\Nationalities;
  18. use App\Entity\Profile\PrivateHaircuts;
  19. use App\Entity\Service;
  20. use App\Entity\ServiceGroups;
  21. use App\Entity\TakeOutLocations;
  22. use App\Repository\ServiceRepository;
  23. use App\Repository\StationRepository;
  24. use App\Service\CountryCurrencyResolver;
  25. use App\Service\DefaultCityProvider;
  26. use App\Service\Features;
  27. use App\Service\ListingRotationApi;
  28. use App\Service\ListingService;
  29. use App\Service\ProfileList;
  30. use App\Service\ProfileListingDataCreator;
  31. use App\Service\ProfileListSpecificationService;
  32. use App\Service\ProfileFilterService;
  33. use App\Specification\ElasticSearch\ISpecification;
  34. use App\Specification\Profile\ProfileHasApartments;
  35. use App\Specification\Profile\ProfileHasComments;
  36. use App\Specification\Profile\ProfileHasVideo;
  37. use App\Specification\Profile\ProfileIdIn;
  38. use App\Specification\Profile\ProfileIdINOrderedByINValues;
  39. use App\Specification\Profile\ProfileIdNotIn;
  40. use App\Specification\Profile\ProfileIsApproved;
  41. use App\Specification\Profile\ProfileIsElite;
  42. use App\Specification\Profile\ProfileIsLocated;
  43. use App\Specification\Profile\ProfileIsProvidingOneOfServices;
  44. use App\Specification\Profile\ProfileIsProvidingTakeOut;
  45. use App\Specification\Profile\ProfileWithAge;
  46. use App\Specification\Profile\ProfileWithBodyType;
  47. use App\Specification\Profile\ProfileWithBreastType;
  48. use App\Specification\Profile\ProfileWithHairColor;
  49. use App\Specification\Profile\ProfileWithNationality;
  50. use App\Specification\Profile\ProfileWithApartmentsOneHourPrice;
  51. use App\Specification\Profile\ProfileWithPrivateHaircut;
  52. use Flagception\Bundle\FlagceptionBundle\Annotations\Feature;
  53. use Happyr\DoctrineSpecification\Filter\Filter;
  54. use Happyr\DoctrineSpecification\Logic\OrX;
  55. use Porpaginas\Doctrine\ORM\ORMQueryResult;
  56. use Porpaginas\Page;
  57. use Psr\Cache\CacheItemPoolInterface;
  58. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
  59. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Entity;
  60. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  61. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  62. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  63. use Symfony\Component\HttpFoundation\Request;
  64. use Happyr\DoctrineSpecification\Spec;
  65. use Symfony\Component\HttpFoundation\RequestStack;
  66. use Symfony\Component\HttpFoundation\Response;
  67. /**
  68.  * @see \App\Console\Export\ExportRotationListingsConfigCommand for listing API endpoints
  69.  */
  70. #[Cache(maxage60, public: true)]
  71. class ProfileListController extends AbstractController
  72. {
  73.     use ExtendedPaginationTrait;
  74.     use SpecTrait;
  75.     use ProfileMinPriceTrait;
  76.     use ResponseTrait;
  77.     const ENTRIES_ON_PAGE 36;
  78.     const RESULT_SOURCE_COUNTY 'county';
  79.     const RESULT_SOURCE_DISTRICT 'district';
  80.     const RESULT_SOURCE_STATION 'station';
  81.     const RESULT_SOURCE_APPROVED 'approved';
  82.     const RESULT_SOURCE_WITH_COMMENTS 'with_comments';
  83.     const RESULT_SOURCE_WITH_VIDEO 'with_video';
  84.     const RESULT_SOURCE_WITH_SELFIE 'with_selfie';
  85.     const RESULT_SOURCE_ELITE 'elite';
  86.     const RESULT_SOURCE_MASSEURS 'masseurs';
  87.     const RESULT_SOURCE_MASSAGE_SERVICE 'massage_service';
  88.     const RESULT_SOURCE_BY_PARAMS 'by_params';
  89.     const RESULT_SOURCE_SERVICE 'service';
  90.     const RESULT_SOURCE_CITY 'city';
  91.     const RESULT_SOURCE_COUNTRY 'country';
  92.     const CACHE_ITEM_STATION_ADDED_PROFILES 'station_added_profiles_ids_';
  93.     private ?string $source null;
  94.     public function __construct(
  95.         private RequestStack $requestStack,
  96.         private ProfileList $profileList,
  97.         private CountryCurrencyResolver $countryCurrencyResolver,
  98.         private ServiceRepository $serviceRepository,
  99.         private ListingService $listingService,
  100.         private Features $features,
  101.         private ProfileFilterService $profilesFilterService,
  102.         private ProfileListSpecificationService $profileListSpecificationService,
  103.         private ProfileListingDataCreator $profileListingDataCreator,
  104.         private CacheItemPoolInterface $stationAddedProfilesCache,
  105.         private ParameterBagInterface $parameterBag,
  106.         private ListingRotationApi $listingRotationApi,
  107.     ) {}
  108.     /**
  109.      * @Feature("has_masseurs")
  110.      */
  111.     #[ParamConverter("city"converter"city_converter")]
  112.     public function listForMasseur(City $cityServiceRepository $serviceRepository): Response
  113.     {
  114.         $specs $this->profileListSpecificationService->listForMasseur($city);
  115.         $response null;
  116.         try {
  117.             $result $this->listingRotationApi->paginate('/city/{city}/masseur', ['city' => $city->getId()], $this->getCurrentPageNumber());
  118.             $response = new Response();
  119.             $response->setMaxAge(10);
  120.         } catch (\Exception) {
  121.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  122.         }
  123.         $massageGroupServices $serviceRepository->findBy(['group' => ServiceGroups::MASSAGE]);
  124.         $orX $this->getORSpecForItemsArray([$massageGroupServices], function($item): ProfileIsProvidingOneOfServices {
  125.             return new ProfileIsProvidingOneOfServices($item);
  126.         });
  127.         $prevCount $result->count();
  128.         $result $this->checkEmptyResultNotMasseur($result$city$orXself::RESULT_SOURCE_MASSAGE_SERVICE);
  129.         if ($result->count() > $prevCount) {
  130.             $response?->setMaxAge(60);
  131.         }
  132.         return $this->render('ProfileList/list.html.twig', [
  133.             'profiles' => $result,
  134.             'source' => $this->source,
  135.             'source_default' => self::RESULT_SOURCE_MASSEURS,
  136.             'recommendationSpec' => $specs->recommendationSpec(),
  137.         ], response$response);
  138.     }
  139.     public function listByDefaultCity(ParameterBagInterface $parameterBagRequest $request): Response
  140.     {
  141.         $controller get_class($this).'::listByCity';
  142.         $path = [
  143.             'city' => $parameterBag->get('default_city'),
  144.             'subRequest' => true,
  145.         ];
  146.         //чтобы в обработчике можно было понять, по какому роуту зашли
  147.         $request->request->set('_route''profile_list.list_by_city');
  148.         return $this->forward($controller$path);
  149.     }
  150.     #[ParamConverter("city"converter"city_converter")]
  151.     public function listByCity(ParameterBagInterface $parameterBagRequest $requestCity $citybool $subRequest false): Response
  152.     {
  153.         $page $this->getCurrentPageNumber();
  154.         if ($this->features->redirect_default_city_to_homepage() && false === $subRequest && $city->equals($parameterBag->get('default_city')) && $page 2) {
  155.             return $this->redirectToRoute('homepage', [], 301);
  156.         }
  157.         $specs $this->profileListSpecificationService->listByCity();
  158.         $response null;
  159.         try {
  160.             $result $this->listingRotationApi->paginate('/city/{city}', ['city' => $city->getId()], $page);
  161.             $response = new Response();
  162.             $response->setMaxAge(10);
  163.         } catch (\Exception) {
  164.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  165.         }
  166.         return $this->render('ProfileList/list.html.twig', [
  167.             'profiles' => $result,
  168.             'recommendationSpec' => $specs->recommendationSpec(),
  169.         ], response$response);
  170.     }
  171.     /**
  172.      * @Feature("intim_moscow_listing")
  173.      */
  174.     public function listIntim(DefaultCityProvider $defaultCityProvider): Response
  175.     {
  176.         $city $defaultCityProvider->getDefaultCity();
  177.         $request $this->requestStack->getCurrentRequest();
  178.         $request?->attributes->set('city'$city);
  179.         $specs $this->profileListSpecificationService->listByCity();
  180.         $response null;
  181.         try {
  182.             $result $this->listingRotationApi->paginate('/city/{city}', ['city' => $city->getId()], $this->getCurrentPageNumber());
  183.             $response = new Response();
  184.             $response->setMaxAge(10);
  185.         } catch (\Exception) {
  186.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  187.         }
  188.         $result $this->shuffleProfilesOnPage($result);
  189.         return $this->render('ProfileList/list.html.twig', [
  190.             'profiles' => $result,
  191.             'city' => $city,
  192.             'recommendationSpec' => $specs->recommendationSpec(),
  193.         ], response$response);
  194.     }
  195.     #[ParamConverter("city"converter"city_converter")]
  196.     #[Entity("county"expr:"repository.ofUriIdentityWithinCity(county, city)")]
  197.     public function listByCounty(Request $requestCity $cityCounty $county): Response
  198.     {
  199.         if (!$city->hasCounty($county)) {
  200.             throw $this->createNotFoundException();
  201.         }
  202.         $specs $this->profileListSpecificationService->listByCounty($county);
  203.         $response null;
  204.         try {
  205.             $result $this->listingRotationApi->paginate('/city/{city}/county/{county}', ['city' => $city->getId(), 'county' => $county->getId()], $this->getCurrentPageNumber());
  206.             $response = new Response();
  207.             $response->setMaxAge(10);
  208.         } catch (\Exception) {
  209.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  210.         }
  211.         $prevCount $result->count();
  212.         $result $this->checkEmptyResultNotMasseur($result$citySpec::orX(ProfileIsLocated::withinCounties($city$city->getCounties()->toArray())), self::RESULT_SOURCE_COUNTY);
  213.         if ($result->count() > $prevCount) {
  214.             $response?->setMaxAge(60);
  215.         }
  216.         return $this->render('ProfileList/list.html.twig', [
  217.             'profiles' => $result,
  218.             'source' => $this->source,
  219.             'source_default' => self::RESULT_SOURCE_COUNTY,
  220.             'county' => $county,
  221.             'category_url' => $this->generateUrl($request->attributes->get('_route'), [
  222.                 'city' => $city->getUriIdentity(),
  223.                 'county' => $county->getUriIdentity(),
  224.                 'page' => $this->getCurrentPageNumber()
  225.             ]),
  226.             'recommendationSpec' => $specs->recommendationSpec(),
  227.         ], response$response);
  228.     }
  229.     #[ParamConverter("city"converter"city_converter")]
  230.     #[Entity("district"expr:"repository.ofUriIdentityWithinCity(district, city)")]
  231.     public function listByDistrict(Request $requestCity $cityDistrict $district): Response
  232.     {
  233.         if (!$city->hasDistrict($district)) {
  234.             throw $this->createNotFoundException();
  235.         }
  236.         $specs $this->profileListSpecificationService->listByDistrict($district);
  237.         $response null;
  238.         try {
  239.             $result $this->listingRotationApi->paginate('/city/{city}/district/{district}', ['city' => $city->getId(), 'district' => $district->getId()], $this->getCurrentPageNumber());
  240.             $response = new Response();
  241.             $response->setMaxAge(10);
  242.         } catch (\Exception) {
  243.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  244.         }
  245.         $prevCount $result->count();
  246.         $result $this->checkEmptyResultNotMasseur($result$citySpec::orX(ProfileIsLocated::withinDistricts($city$city->getDistricts()->toArray())), self::RESULT_SOURCE_DISTRICT);
  247.         if ($result->count() > $prevCount) {
  248.             $response?->setMaxAge(60);
  249.         }
  250.         return $this->render('ProfileList/list.html.twig', [
  251.             'profiles' => $result,
  252.             'source' => $this->source,
  253.             'source_default' => self::RESULT_SOURCE_DISTRICT,
  254.             'district' => $district,
  255.             'category_url' => $this->generateUrl($request->attributes->get('_route'), [
  256.                 'city' => $city->getUriIdentity(),
  257.                 'district' => $district->getUriIdentity(),
  258.                 'page' => $this->getCurrentPageNumber()
  259.             ]),
  260.             'recommendationSpec' => $specs->recommendationSpec(),
  261.         ], response$response);
  262.     }
  263.     #[ParamConverter("city"converter"city_converter")]
  264.     #[Entity("station"expr:"repository.ofUriIdentityWithinCity(station, city)")]
  265.     public function listByStation(Request $requestCity $cityStation $station): Response
  266.     {
  267.         if (!$city->hasStation($station)) {
  268.             throw $this->createNotFoundException();
  269.         }
  270.         $specs $this->profileListSpecificationService->listByStation($station);
  271.         $response null;
  272.         try {
  273.             $result $this->listingRotationApi->paginate('/city/{city}/station/{station}', ['city' => $city->getId(), 'station' => $station->getId()], $this->getCurrentPageNumber());
  274.             $response = new Response();
  275.             $response->setMaxAge(10);
  276.         } catch (\Exception) {
  277.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  278.         }
  279.         $prevCount $result->count();
  280.         if(true === $this->features->station_page_add_profiles()) {
  281.             $spread $this->parameterBag->get('app.profile.station_page.added_profiles.spread');
  282.             $result $this->addSinglePageStationResults($result$city$station$spread ?: 5);
  283.         }
  284.         if (null !== $station->getDistrict()) {
  285.             $result $this->checkEmptyResultNotMasseur($result$citySpec::orX(ProfileIsLocated::nearStations($city$station->getDistrict()->getStations()->toArray())), self::RESULT_SOURCE_STATION);
  286.         } else {
  287.             $result $this->checkCityAndCountrySource($result$city);
  288.         }
  289.         if ($result->count() > $prevCount) {
  290.             $response?->setMaxAge(60);
  291.         }
  292.         return $this->render('ProfileList/list.html.twig', [
  293.             'profiles' => $result,
  294.             'source' => $this->source,
  295.             'source_default' => self::RESULT_SOURCE_STATION,
  296.             'station' => $station,
  297.             'category_url' => $this->generateUrl($request->attributes->get('_route'), [
  298.                 'city' => $city->getUriIdentity(),
  299.                 'station' => $station->getUriIdentity(),
  300.                 'page' => $this->getCurrentPageNumber()
  301.             ]),
  302.             'recommendationSpec' => $specs->recommendationSpec(),
  303.         ], response$response);
  304.     }
  305.     private function addSinglePageStationResults(Page $resultCity $cityStation $stationint $spread): Page
  306.     {
  307.         if($result->totalCount() >= $result->getCurrentLimit()) {
  308.             return $result;
  309.         }
  310.         $addedProfileIds $this->stationAddedProfilesCache->get(self::CACHE_ITEM_STATION_ADDED_PROFILES $station->getId(), function() use ($result$city$station$spread): array {
  311.             $currentSpread rand(0$spread);
  312.             $plannedTotalCount $result->getCurrentLimit() - $spread $currentSpread;
  313.             $result iterator_to_array($result->getIterator());
  314.             $originalProfileIds array_map(fn($item) => $item->id$result);
  315.             if($station->getDistrict()) {
  316.                 $result $this->addSinglePageResultsUptoAmount($result$citySpec::orX(ProfileIsLocated::withinDistrict($station->getDistrict())), $plannedTotalCount);
  317.             }
  318.             if($station->getDistrict()?->getCounty()) {
  319.                 $result $this->addSinglePageResultsUptoAmount($result$citySpec::orX(ProfileIsLocated::withinCounty($station->getDistrict()->getCounty())), $plannedTotalCount);
  320.             }
  321.             $result $this->addSinglePageResultsUptoAmount($result$citySpec::orX(ProfileIsLocated::withinCity($city)), $plannedTotalCount);
  322.             $result array_map(fn($item) => $item->id$result);
  323.             return array_diff($result$originalProfileIds);
  324.         });
  325.         $addedProfileIds array_slice($addedProfileIds0$result->getCurrentLimit() - $result->totalCount());
  326.         $originalProfiles iterator_to_array($result->getIterator());
  327.         $addedProfiles $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacementLimited($city, new ProfileIdIn($addedProfileIds), null, [Genders::FEMALE], count($addedProfileIds));
  328.         $newResult array_merge($originalProfiles$addedProfiles);
  329.         return new FakeORMQueryPage(01$result->getCurrentLimit(), count($newResult), $newResult);
  330.     }
  331.     private function addSinglePageResultsUptoAmount(array $resultCity $city, ?Filter $specsint $totalCount): array
  332.     {
  333.         $toAdd $totalCount count($result);
  334.         $currentResultIds array_map(fn($profile) => $profile->id$result);
  335.         $resultsToAdd $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacementLimited($city$specs, [new ProfileIdNotIn($currentResultIds)], [Genders::FEMALE], $toAdd);
  336.         $result array_merge($result$resultsToAdd);
  337.         return $result;
  338.     }
  339.     #[ParamConverter("city"converter"city_converter")]
  340.     public function listByStations(City $citystring $stationsStationRepository $stationRepository): Response
  341.     {
  342.         $stationIds explode(','$stations);
  343.         $stations $stationRepository->findBy(['uriIdentity' => $stationIds]);
  344.         $specs $this->profileListSpecificationService->listByStations($stations);
  345.         $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  346.         return $this->render('ProfileList/list.html.twig', [
  347.             'profiles' => $result,
  348.             'recommendationSpec' => $specs->recommendationSpec(),
  349.         ]);
  350.     }
  351.     #[ParamConverter("city"converter"city_converter")]
  352.     public function listApproved(Request $requestCity $city): Response
  353.     {
  354.         $specs $this->profileListSpecificationService->listApproved();
  355.         $response null;
  356.         try {
  357.             $result $this->listingRotationApi->paginate('/city/{city}/approved', ['city' => $city->getId()], $this->getCurrentPageNumber());
  358.             $response = new Response();
  359.             $response->setMaxAge(10);
  360.         } catch (\Exception) {
  361.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  362.         }
  363.         $prevCount $result->count();
  364.         if($this->features->fill_empty_profile_list() && $result->count() == 0) {
  365.             $this->source self::RESULT_SOURCE_WITH_COMMENTS;
  366.             $result $this->listRandomSinglePage($citynull, new ProfileHasComments(), nulltruefalse);
  367.             if($result->count() == 0) {
  368.                 $this->source self::RESULT_SOURCE_WITH_VIDEO;
  369.                 $result $this->listRandomSinglePage($citynull, new ProfileHasVideo(), nulltruefalse);
  370.             }
  371.             if($result->count() == 0) {
  372.                 $this->source self::RESULT_SOURCE_ELITE;
  373.                 $result $this->listRandomSinglePage($citynull$this->getSpecForEliteGirls($city), nulltruenull);
  374.             }
  375.             $result $this->checkEmptyResultNotMasseur($result$citynullself::RESULT_SOURCE_CITY);
  376.         }
  377.         if ($result->count() > $prevCount) {
  378.             $response?->setMaxAge(60);
  379.         }
  380.         return $this->render('ProfileList/list.html.twig', [
  381.             'profiles' => $result,
  382.             'source' => $this->source,
  383.             'source_default' => self::RESULT_SOURCE_APPROVED,
  384.             'category_url' => $this->generateUrl($request->attributes->get('_route'), [
  385.                 'city' => $city->getUriIdentity(),
  386.                 'page' => $this->getCurrentPageNumber()
  387.             ]),
  388.             'recommendationSpec' => $specs->recommendationSpec(),
  389.         ], response$response);
  390.     }
  391.     #[ParamConverter("city"converter"city_converter")]
  392.     public function listWithComments(Request $requestCity $city): Response
  393.     {
  394.         $specs $this->profileListSpecificationService->listWithComments();
  395.         $response null;
  396.         try {
  397.             $result $this->listingRotationApi->paginate('/city/{city}/with_comments', ['city' => $city->getId()], $this->getCurrentPageNumber());
  398.             $response = new Response();
  399.             $response->setMaxAge(10);
  400.         } catch (\Exception) {
  401.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  402.         }
  403.         $prevCount $result->count();
  404.         if($this->features->fill_empty_profile_list() && $result->count() == 0) {
  405.             $this->source self::RESULT_SOURCE_APPROVED;
  406.             $result $this->listRandomSinglePage($citynull, new ProfileIsApproved(), nulltruefalse);
  407.             if ($result->count() == 0) {
  408.                 $this->source self::RESULT_SOURCE_WITH_VIDEO;
  409.                 $result $this->listRandomSinglePage($citynull, new ProfileHasVideo(), nulltruefalse);
  410.             }
  411.             if ($result->count() == 0) {
  412.                 $this->source self::RESULT_SOURCE_ELITE;
  413.                 $result $this->listRandomSinglePage($citynull$this->getSpecForEliteGirls($city), nulltruenull);
  414.             }
  415.             $result $this->checkEmptyResultNotMasseur($result$citynullself::RESULT_SOURCE_CITY);
  416.         }
  417.         if ($result->count() > $prevCount) {
  418.             $response?->setMaxAge(60);
  419.         }
  420.         return $this->render('ProfileList/list.html.twig', [
  421.             'profiles' => $result,
  422.             'source' => $this->source,
  423.             'source_default' => self::RESULT_SOURCE_WITH_COMMENTS,
  424.             'category_url' => $this->generateUrl($request->attributes->get('_route'), [
  425.                 'city' => $city->getUriIdentity(),
  426.                 'page' => $this->getCurrentPageNumber()
  427.             ]),
  428.             'recommendationSpec' => $specs->recommendationSpec(),
  429.         ], response$response);
  430.     }
  431.     #[ParamConverter("city"converter"city_converter")]
  432.     public function listWithVideo(Request $requestCity $city): Response
  433.     {
  434.         $specs $this->profileListSpecificationService->listWithVideo();
  435.         $response null;
  436.         try {
  437.             $result $this->listingRotationApi->paginate('/city/{city}/with_video', ['city' => $city->getId()], $this->getCurrentPageNumber());
  438.             $response = new Response();
  439.             $response->setMaxAge(10);
  440.         } catch (\Exception) {
  441.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  442.         }
  443.         $prevCount $result->count();
  444.         if($this->features->fill_empty_profile_list() && $result->count() == 0) {
  445.             $this->source self::RESULT_SOURCE_APPROVED;
  446.             $result $this->listRandomSinglePage($citynull, new ProfileIsApproved(), nulltruefalse);
  447.             if($result->count() == 0) {
  448.                 $this->source self::RESULT_SOURCE_WITH_COMMENTS;
  449.                 $result $this->listRandomSinglePage($citynull, new ProfileHasComments(), nulltruefalse);
  450.             }
  451.             if($result->count() == 0) {
  452.                 $this->source self::RESULT_SOURCE_ELITE;
  453.                 $result $this->listRandomSinglePage($citynull$this->getSpecForEliteGirls($city), nulltruenull);
  454.             }
  455.             $result $this->checkEmptyResultNotMasseur($result$citynullself::RESULT_SOURCE_CITY);
  456.         }
  457.         if ($result->count() > $prevCount) {
  458.             $response?->setMaxAge(60);
  459.         }
  460.         return $this->render('ProfileList/list.html.twig', [
  461.             'profiles' => $result,
  462.             'source' => $this->source,
  463.             'source_default' => self::RESULT_SOURCE_WITH_VIDEO,
  464.             'category_url' => $this->generateUrl($request->attributes->get('_route'), [
  465.                 'city' => $city->getUriIdentity(),
  466.                 'page' => $this->getCurrentPageNumber()
  467.             ]),
  468.             'recommendationSpec' => $specs->recommendationSpec(),
  469.         ], response$response);
  470.     }
  471.     #[ParamConverter("city"converter"city_converter")]
  472.     public function listWithSelfie(Request $requestCity $city): Response
  473.     {
  474.         $specs $this->profileListSpecificationService->listWithSelfie();
  475.         $response null;
  476.         try {
  477.             $result $this->listingRotationApi->paginate('/city/{city}/with_selfie', ['city' => $city->getId()], $this->getCurrentPageNumber());
  478.             $response = new Response();
  479.             $response->setMaxAge(10);
  480.         } catch (\Exception) {
  481.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  482.         }
  483.         $prevCount $result->count();
  484.         if($this->features->fill_empty_profile_list() && $result->count() == 0) {
  485.             $this->source self::RESULT_SOURCE_WITH_VIDEO;
  486.             $result $this->listRandomSinglePage($citynull, new ProfileHasVideo(), nulltruefalse);
  487.             if ($result->count() == 0) {
  488.                 $this->source self::RESULT_SOURCE_APPROVED;
  489.                 $result $this->listRandomSinglePage($citynull, new ProfileIsApproved(), nulltruefalse);
  490.             }
  491.             if ($result->count() == 0) {
  492.                 $this->source self::RESULT_SOURCE_ELITE;
  493.                 $result $this->listRandomSinglePage($citynull$this->getSpecForEliteGirls($city), nulltruenull);
  494.             }
  495.             $result $this->checkEmptyResultNotMasseur($result$citynullself::RESULT_SOURCE_CITY);
  496.         }
  497.         if ($result->count() > $prevCount) {
  498.             $response?->setMaxAge(60);
  499.         }
  500.         return $this->render('ProfileList/list.html.twig', [
  501.             'profiles' => $result,
  502.             'source' => $this->source,
  503.             'source_default' => self::RESULT_SOURCE_WITH_SELFIE,
  504.             'category_url' => $this->generateUrl($request->attributes->get('_route'), [
  505.                 'city' => $city->getUriIdentity(),
  506.                 'page' => $this->getCurrentPageNumber()
  507.             ]),
  508.             'recommendationSpec' => $specs->recommendationSpec(),
  509.         ], response$response);
  510.     }
  511.     #[ParamConverter("city"converter"city_converter")]
  512.     public function listByPrice(Request $requestCountryCurrencyResolver $countryCurrencyResolverCity $citystring $priceTypeint $minPrice nullint $maxPrice null): Response
  513.     {
  514.         $specs $this->profileListSpecificationService->listByPrice($city$priceType$minPrice$maxPrice);
  515.         $response null;
  516.         try {
  517.             if (!in_array($priceType, ['low''high''elite'])) {
  518.                 throw new \LogicException(sprintf('Price type "%s" is not supported'$priceType));
  519.             }
  520.             $result $this->listingRotationApi->paginate('/city/{city}/price/'.$priceType, ['city' => $city->getId()], $this->getCurrentPageNumber());
  521.             $response = new Response();
  522.             $response->setMaxAge(10);
  523.         } catch (\Exception) {
  524.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  525.         }
  526.         $prevCount $result->count();
  527.         if($this->features->fill_empty_profile_list() && $result->count() == 0) {
  528.             $result $this->processListByPriceEmptyResult($result$city$priceType$minPrice$maxPrice);
  529.         }
  530.         if ($result->count() > $prevCount) {
  531.             $response?->setMaxAge(60);
  532.         }
  533.         return $this->render('ProfileList/list.html.twig', [
  534.             'profiles' => $result,
  535.             'source' => $this->source,
  536.             'source_default' => self::RESULT_SOURCE_BY_PARAMS,
  537.             'category_url' => $this->generateUrl($request->attributes->get('_route'), [
  538.                 'city' => $city->getUriIdentity(),
  539.                 'priceType' => $priceType,
  540.                 'minPrice' => $minPrice,
  541.                 'maxPrice' => $maxPrice,
  542.                 'page' => $this->getCurrentPageNumber()
  543.             ]),
  544.             'recommendationSpec' => $specs->recommendationSpec(),
  545.         ], response$response);
  546.     }
  547.     private function processListByPriceEmptyResult(Page $resultCity $citystring $priceTypeint $minPrice nullint $maxPrice null)
  548.     {
  549.         if(!$this->features->fill_empty_profile_list())
  550.             return $result;
  551.         $this->source self::RESULT_SOURCE_BY_PARAMS;
  552.         if($this->countryCurrencyResolver->getCurrencyFor($city->getCountryCode()) == 'RUB') {
  553.             if ($minPrice && $maxPrice) {
  554.                 if ($minPrice == 2000 && $maxPrice == 3000) {
  555.                     $priceSpec = [
  556.                         ProfileWithApartmentsOneHourPrice::range(15002000),
  557.                         ProfileWithApartmentsOneHourPrice::range(30004000),
  558.                     ];
  559.                 } else if ($minPrice == 3000 && $maxPrice == 4000) {
  560.                     $priceSpec = [
  561.                         ProfileWithApartmentsOneHourPrice::range(20003000),
  562.                         ProfileWithApartmentsOneHourPrice::range(40005000),
  563.                     ];
  564.                 } else if ($minPrice == 4000 && $maxPrice == 5000) {
  565.                     $priceSpec = [
  566.                         ProfileWithApartmentsOneHourPrice::range(30004000),
  567.                         ProfileWithApartmentsOneHourPrice::range(50006000),
  568.                     ];
  569.                 } else if ($minPrice == 5000 && $maxPrice == 6000) {
  570.                     $priceSpec = [
  571.                         ProfileWithApartmentsOneHourPrice::range(4000999999)
  572.                     ];
  573.                 } else {
  574.                     $priceSpec = [
  575.                         ProfileWithApartmentsOneHourPrice::range($minPrice$maxPrice)
  576.                     ];
  577.                 }
  578.                 $result $this->listRandomSinglePage($citynullnull$priceSpectruefalse);
  579.             } elseif ($maxPrice) {
  580.                 if ($maxPrice == 500) {
  581.                     $priceSpec ProfileWithApartmentsOneHourPrice::cheaperThan(1500);
  582.                     $result $this->listRandomSinglePage($citynull$priceSpecnulltruefalse);
  583.                     if ($result->count() == 0) {
  584.                         $priceSpec ProfileWithApartmentsOneHourPrice::range(15002000);
  585.                         $result $this->listRandomSinglePage($citynull$priceSpecnulltruefalse);
  586.                     }
  587.                 } else if ($maxPrice == 1500) {
  588.                     $priceSpec ProfileWithApartmentsOneHourPrice::range(15002000);
  589.                     $result $this->listRandomSinglePage($citynull$priceSpecnulltruefalse);
  590.                     if ($result->count() == 0) {
  591.                         $priceSpec ProfileWithApartmentsOneHourPrice::range(20003000);
  592.                         $result $this->listRandomSinglePage($citynull$priceSpecnulltruefalse);
  593.                     }
  594.                 }
  595.             } else {
  596.                 switch ($priceType) {
  597.                     case 'not_expensive':
  598.                         $priceSpec ProfileWithApartmentsOneHourPrice::cheaperThan(2000);
  599.                         break;
  600.                     case 'high':
  601.                         $priceSpec ProfileWithApartmentsOneHourPrice::range(30006000);
  602.                         break;
  603.                     case 'low':
  604.                         $priceSpec ProfileWithApartmentsOneHourPrice::cheaperThan(2000);
  605.                         break;
  606.                     case 'elite':
  607.                         $priceSpec ProfileWithApartmentsOneHourPrice::moreExpensiveThan(6000);
  608.                         break;
  609.                     default:
  610.                         throw new \LogicException('Unknown price type');
  611.                         break;
  612.                 }
  613.                 $result $this->listRandomSinglePage($citynull$priceSpecnulltruefalse);
  614.             }
  615.         }
  616.         $result $this->checkEmptyResultNotMasseur($result$citynullself::RESULT_SOURCE_CITY);
  617.         return $result;
  618.     }
  619.     #[ParamConverter("city"converter"city_converter")]
  620.     public function listByAge(Request $requestCity $citystring $ageTypeint $minAge nullint $maxAge null): Response
  621.     {
  622.         $specs $this->profileListSpecificationService->listByAge($ageType$minAge$maxAge);
  623.         $response null;
  624.         try {
  625.             if (!in_array($ageType, ['young''old'])) {
  626.                 throw new \LogicException(sprintf('Age type "%s" is not supported'$ageType));
  627.             }
  628.             $result $this->listingRotationApi->paginate('/city/{city}/age/'.$ageType, ['city' => $city->getId()], $this->getCurrentPageNumber());
  629.             $response = new Response();
  630.             $response->setMaxAge(10);
  631.         } catch (\Exception) {
  632.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  633.         }
  634.         $prevCount $result->count();
  635.         if($this->features->fill_empty_profile_list() && $result->count() == 0) {
  636.             $filled $this->processListByAgeEmptyResult($result$city$ageType$minAge$maxAge);
  637.             if($filled)
  638.                 $result $filled;
  639.         }
  640.         if ($result->count() > $prevCount) {
  641.             $response?->setMaxAge(60);
  642.         }
  643.         return $this->render('ProfileList/list.html.twig', [
  644.             'profiles' => $result,
  645.             'source' => $this->source,
  646.             'source_default' => self::RESULT_SOURCE_BY_PARAMS,
  647.             'category_url' => $this->generateUrl($request->attributes->get('_route'), [
  648.                 'city' => $city->getUriIdentity(),
  649.                 'ageType' => $ageType,
  650.                 'minAge' => $minAge,
  651.                 'maxAge' => $maxAge,
  652.                 'page' => $this->getCurrentPageNumber()
  653.             ]),
  654.             'recommendationSpec' => $specs->recommendationSpec(),
  655.         ], response$response);
  656.     }
  657.     private function processListByAgeEmptyResult(Page $resultCity $citystring $ageTypeint $minAge nullint $maxAge null)
  658.     {
  659.         if(!$this->features->fill_empty_profile_list())
  660.             return $result;
  661.         $this->source self::RESULT_SOURCE_BY_PARAMS;
  662.         if ($minAge && !$maxAge) {
  663.             $startMinAge $minAge;
  664.             do {
  665.                 $startMinAge -= 2;
  666.                 $ageSpec ProfileWithAge::olderThan($startMinAge);
  667.                 $result $this->listRandomSinglePage($citynull$ageSpecnulltruefalse);
  668.             } while($result->count() == && $startMinAge >= 18);
  669.         } else if($ageType == 'young') {
  670.             $startMaxAge 20;
  671.             do {
  672.                 $startMaxAge += 2;
  673.                 $ageSpec ProfileWithAge::youngerThan($startMaxAge);
  674.                 $result $this->listRandomSinglePage($citynull$ageSpecnulltruefalse);
  675.             } while($result->count() == && $startMaxAge <= 100);
  676.         }
  677.         $result $this->checkEmptyResultNotMasseur($result$citynullself::RESULT_SOURCE_CITY);
  678.         return $result;
  679.     }
  680.     #[ParamConverter("city"converter"city_converter")]
  681.     public function listByHeight(Request $requestCity $citystring $heightType): Response
  682.     {
  683.         $specs $this->profileListSpecificationService->listByHeight($heightType);
  684.         $response null;
  685.         try {
  686.             $result $this->listingRotationApi->paginate('/city/{city}/height/'.$heightType, ['city' => $city->getId()], $this->getCurrentPageNumber());
  687.             $response = new Response();
  688.             $response->setMaxAge(10);
  689.         } catch (\Exception) {
  690.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  691.         }
  692.         $prevCount $result->count();
  693.         $result $this->checkEmptyResultNotMasseur($result$citynullself::RESULT_SOURCE_CITY);
  694.         if ($result->count() > $prevCount) {
  695.             $response?->setMaxAge(60);
  696.         }
  697.         return $this->render('ProfileList/list.html.twig', [
  698.             'profiles' => $result,
  699.             'source' => $this->source,
  700.             'source_default' => self::RESULT_SOURCE_BY_PARAMS,
  701.             'category_url' => $this->generateUrl($request->attributes->get('_route'), [
  702.                 'city' => $city->getUriIdentity(),
  703.                 'heightType' => $heightType,
  704.                 'page' => $this->getCurrentPageNumber()
  705.             ]),
  706.             'recommendationSpec' => $specs->recommendationSpec(),
  707.         ], response$response);
  708.     }
  709.     #[ParamConverter("city"converter"city_converter")]
  710.     public function listByBreastType(Request $requestCity $citystring $breastType): Response
  711.     {
  712.         if(null === $type BreastTypes::getValueByUriIdentity($breastType))
  713.             throw $this->createNotFoundException();
  714.         $specs $this->profileListSpecificationService->listByBreastType($breastType);
  715.         $response null;
  716.         try {
  717.             $result $this->listingRotationApi->paginate('/city/{city}/breasttype/'.$type, ['city' => $city->getId()], $this->getCurrentPageNumber());
  718.             $response = new Response();
  719.             $response->setMaxAge(10);
  720.         } catch (\Exception) {
  721.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  722.         }
  723.         $orX $this->getORSpecForItemsArray(BreastTypes::getList(), function($item): ProfileWithBreastType {
  724.             return new ProfileWithBreastType($item);
  725.         });
  726.         $prevCount $result->count();
  727.         $result $this->checkEmptyResultNotMasseur($result$city$orXself::RESULT_SOURCE_BY_PARAMS);
  728.         if ($result->count() > $prevCount) {
  729.             $response?->setMaxAge(60);
  730.         }
  731.         return $this->render('ProfileList/list.html.twig', [
  732.             'profiles' => $result,
  733.             'source' => $this->source,
  734.             'source_default' => self::RESULT_SOURCE_BY_PARAMS,
  735.             'category_url' => $this->generateUrl($request->attributes->get('_route'), [
  736.                 'city' => $city->getUriIdentity(),
  737.                 'breastType' => $breastType,
  738.                 'page' => $this->getCurrentPageNumber()
  739.             ]),
  740.             'recommendationSpec' => $specs->recommendationSpec(),
  741.         ], response$response);
  742.     }
  743.     #[ParamConverter("city"converter"city_converter")]
  744.     public function listByHairColor(Request $requestCity $citystring $hairColor): Response
  745.     {
  746.         if(null === $color HairColors::getValueByUriIdentity($hairColor))
  747.             throw $this->createNotFoundException();
  748.         $specs $this->profileListSpecificationService->listByHairColor($hairColor);
  749.         $response null;
  750.         try {
  751.             $result $this->listingRotationApi->paginate('/city/{city}/haircolor/'.$color, ['city' => $city->getId()], $this->getCurrentPageNumber());
  752.             $response = new Response();
  753.             $response->setMaxAge(10);
  754.         } catch (\Exception) {
  755.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  756.         }
  757.         $orX $this->getORSpecForItemsArray(HairColors::getList(), function($item): ProfileWithHairColor {
  758.             return new ProfileWithHairColor($item);
  759.         });
  760.         $prevCount $result->count();
  761.         $result $this->checkEmptyResultNotMasseur($result$city$orXself::RESULT_SOURCE_BY_PARAMS);
  762.         if ($result->count() > $prevCount) {
  763.             $response?->setMaxAge(60);
  764.         }
  765.         return $this->render('ProfileList/list.html.twig', [
  766.             'profiles' => $result,
  767.             'source' => $this->source,
  768.             'source_default' => self::RESULT_SOURCE_BY_PARAMS,
  769.             'category_url' => $this->generateUrl($request->attributes->get('_route'), [
  770.                 'city' => $city->getUriIdentity(),
  771.                 'hairColor' => $hairColor,
  772.                 'page' => $this->getCurrentPageNumber()
  773.             ]),
  774.             'recommendationSpec' => $specs->recommendationSpec(),
  775.         ], response$response);
  776.     }
  777.     #[ParamConverter("city"converter"city_converter")]
  778.     public function listByBodyType(Request $requestCity $citystring $bodyType): Response
  779.     {
  780.         if(null === $type BodyTypes::getValueByUriIdentity($bodyType))
  781.             throw $this->createNotFoundException();
  782.         $specs $this->profileListSpecificationService->listByBodyType($bodyType);
  783.         $response null;
  784.         try {
  785.             $result $this->listingRotationApi->paginate('/city/{city}/bodytype/'.$type, ['city' => $city->getId()], $this->getCurrentPageNumber());
  786.             $response = new Response();
  787.             $response->setMaxAge(10);
  788.         } catch (\Exception) {
  789.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  790.         }
  791.         $orX $this->getORSpecForItemsArray(BodyTypes::getList(), function($item): ProfileWithBodyType {
  792.             return new ProfileWithBodyType($item);
  793.         });
  794.         $prevCount $result->count();
  795.         $result $this->checkEmptyResultNotMasseur($result$city$orXself::RESULT_SOURCE_BY_PARAMS);
  796.         if ($result->count() > $prevCount) {
  797.             $response?->setMaxAge(60);
  798.         }
  799.         return $this->render('ProfileList/list.html.twig', [
  800.             'profiles' => $result,
  801.             'source' => $this->source,
  802.             'source_default' => self::RESULT_SOURCE_BY_PARAMS,
  803.             'category_url' => $this->generateUrl($request->attributes->get('_route'), [
  804.                 'city' => $city->getUriIdentity(),
  805.                 'bodyType' => $bodyType,
  806.                 'page' => $this->getCurrentPageNumber()
  807.             ]),
  808.             'recommendationSpec' => $specs->recommendationSpec(),
  809.         ], response$response);
  810.     }
  811.     #[ParamConverter("city"converter"city_converter")]
  812.     public function listByPlace(Request $requestCity $citystring $placeTypestring $takeOutLocation null): Response
  813.     {
  814.         $specs $this->profileListSpecificationService->listByPlace($placeType$takeOutLocation);
  815.         if(null === $specs)
  816.             throw $this->createNotFoundException();
  817.         $response null;
  818.         try {
  819.             $endpoint '/city/{city}/place/'.$placeType;
  820.             if (null !== $takeOutLocation) {
  821.                 $endpoint .= '/'.$takeOutLocation;
  822.             }
  823.             $result $this->listingRotationApi->paginate($endpoint, ['city' => $city->getId()], $this->getCurrentPageNumber());
  824.             $response = new Response();
  825.             $response->setMaxAge(10);
  826.         } catch (\Exception) {
  827.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  828.         }
  829.         $orX $this->getORSpecForItemsArray(TakeOutLocations::getList(), function($item): ProfileIsProvidingTakeOut {
  830.             return new ProfileIsProvidingTakeOut($item);
  831.         });
  832.         if($placeType == 'take-out')
  833.             $orX->orX(new ProfileHasApartments());
  834.         $prevCount $result->count();
  835.         $result $this->checkEmptyResultNotMasseur($result$city$orXself::RESULT_SOURCE_BY_PARAMS);
  836.         if ($result->count() > $prevCount) {
  837.             $response?->setMaxAge(60);
  838.         }
  839.         return $this->render('ProfileList/list.html.twig', [
  840.             'profiles' => $result,
  841.             'source' => $this->source,
  842.             'source_default' => self::RESULT_SOURCE_BY_PARAMS,
  843.             'category_url' => $this->generateUrl($request->attributes->get('_route'), [
  844.                 'city' => $city->getUriIdentity(),
  845.                 'placeType' => $placeType,
  846.                 'takeOutLocation' => TakeOutLocations::getUriIdentity(TakeOutLocations::getValueByUriIdentity($takeOutLocation)),
  847.                 'page' => $this->getCurrentPageNumber()
  848.             ]),
  849.             'recommendationSpec' => $specs->recommendationSpec(),
  850.         ], response$response);
  851.     }
  852.     #[ParamConverter("city"converter"city_converter")]
  853.     public function listByPrivateHaircut(Request $requestCity $citystring $privateHaircut): Response
  854.     {
  855.         if(null === $type PrivateHaircuts::getValueByUriIdentity($privateHaircut))
  856.             throw $this->createNotFoundException();
  857.         $specs $this->profileListSpecificationService->listByPrivateHaircut($privateHaircut);
  858.         $response null;
  859.         try {
  860.             $result $this->listingRotationApi->paginate('/city/{city}/privatehaircut/'.$type, ['city' => $city->getId()], $this->getCurrentPageNumber());
  861.             $response = new Response();
  862.             $response->setMaxAge(10);
  863.         } catch (\Exception) {
  864.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  865.         }
  866.         $orX $this->getORSpecForItemsArray(PrivateHaircuts::getList(), function($item): ProfileWithPrivateHaircut {
  867.             return new ProfileWithPrivateHaircut($item);
  868.         });
  869.         $prevCount $result->count();
  870.         $result $this->checkEmptyResultNotMasseur($result$city$orXself::RESULT_SOURCE_BY_PARAMS);
  871.         if ($result->count() > $prevCount) {
  872.             $response?->setMaxAge(60);
  873.         }
  874.         return $this->render('ProfileList/list.html.twig', [
  875.             'profiles' => $result,
  876.             'source' => $this->source,
  877.             'source_default' => self::RESULT_SOURCE_BY_PARAMS,
  878.             'category_url' => $this->generateUrl($request->attributes->get('_route'), [
  879.                 'city' => $city->getUriIdentity(),
  880.                 'privateHaircut' => $privateHaircut,
  881.                 'page' => $this->getCurrentPageNumber()
  882.             ]),
  883.             'recommendationSpec' => $specs->recommendationSpec(),
  884.         ], response$response);
  885.     }
  886.     #[ParamConverter("city"converter"city_converter")]
  887.     public function listByNationality(Request $requestCity $citystring $nationality): Response
  888.     {
  889.         if(null === $type Nationalities::getValueByUriIdentity($nationality))
  890.             throw $this->createNotFoundException();
  891.         $specs $this->profileListSpecificationService->listByNationality($nationality);
  892.         $response null;
  893.         try {
  894.             $result $this->listingRotationApi->paginate('/city/{city}/nationality/'.$type, ['city' => $city->getId()], $this->getCurrentPageNumber());
  895.             $response = new Response();
  896.             $response->setMaxAge(10);
  897.         } catch (\Exception) {
  898.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  899.         }
  900.         $orX $this->getORSpecForItemsArray(Nationalities::getList(), function($item): ProfileWithNationality {
  901.             return new ProfileWithNationality($item);
  902.         });
  903.         $prevCount $result->count();
  904.         $result $this->checkEmptyResultNotMasseur($result$city$orXself::RESULT_SOURCE_BY_PARAMS);
  905.         if ($result->count() > $prevCount) {
  906.             $response?->setMaxAge(60);
  907.         }
  908.         return $this->render('ProfileList/list.html.twig', [
  909.             'profiles' => $result,
  910.             'source' => $this->source,
  911.             'source_default' => self::RESULT_SOURCE_BY_PARAMS,
  912.             'category_url' => $this->generateUrl($request->attributes->get('_route'), [
  913.                 'city' => $city->getUriIdentity(),
  914.                 'nationality' => $nationality,
  915.                 'page' => $this->getCurrentPageNumber()
  916.             ]),
  917.             'recommendationSpec' => $specs->recommendationSpec(),
  918.         ], response$response);
  919.     }
  920.     #[ParamConverter("city"converter"city_converter")]
  921.     #[ParamConverter("service"options: ['mapping' => ['service' => 'uriIdentity']])]
  922.     public function listByProvidedService(Request $requestCity $cityService $service): Response
  923.     {
  924.         $specs $this->profileListSpecificationService->listByProvidedService($service$city);
  925.         $response null;
  926.         try {
  927.             $result $this->listingRotationApi->paginate('/city/{city}/service/{service}', ['city' => $city->getId(), 'service' => $service->getId()], $this->getCurrentPageNumber());
  928.             $response = new Response();
  929.             $response->setMaxAge(10);
  930.         } catch (\Exception) {
  931.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  932.         }
  933.         $prevCount $result->count();
  934.         $sameGroupServices $this->serviceRepository->findBy(['group' => $service->getGroup()]);
  935.         $orX $this->getORSpecForItemsArray([$sameGroupServices], function($item): ProfileIsProvidingOneOfServices {
  936.             return new ProfileIsProvidingOneOfServices($item);
  937.         });
  938.         $result $this->checkEmptyResultNotMasseur($result$city$orXself::RESULT_SOURCE_SERVICE);
  939.         if ($result->count() > $prevCount) {
  940.             $response?->setMaxAge(60);
  941.         }
  942.         return $this->render('ProfileList/list.html.twig', [
  943.             'profiles' => $result,
  944.             'source' => $this->source,
  945.             'source_default' => self::RESULT_SOURCE_SERVICE,
  946.             'service' => $service,
  947.             'category_url' => $this->generateUrl($request->attributes->get('_route'), [
  948.                 'city' => $city->getUriIdentity(),
  949.                 'service' => $service->getUriIdentity(),
  950.                 'page' => $this->getCurrentPageNumber()
  951.             ]),
  952.             'recommendationSpec' => $specs->recommendationSpec(),
  953.         ], response$response);
  954.     }
  955.     /**
  956.      * @Feature("has_archive_page")
  957.      */
  958.     #[ParamConverter("city"converter"city_converter")]
  959.     public function listArchived(Request $requestCity $city): Response
  960.     {
  961.         $result $this->profileList->list($citynullnullnullfalsenullProfileList::ORDER_BY_UPDATED);
  962.         return $this->render('ProfileList/list.html.twig', [
  963.             'profiles' => $result,
  964.             'recommendationSpec' => new \App\Specification\ElasticSearch\ProfileIsNotArchived(), //ProfileIsArchived, согласно https://redminez.net/issues/28305 в реках выводятся неарзивные
  965.         ]);
  966.     }
  967.     #[ParamConverter("city"converter"city_converter")]
  968.     public function listNew(City $cityint $weeks 2): Response
  969.     {
  970.         $specs $this->profileListSpecificationService->listNew($weeks);
  971.         $response null;
  972.         try {
  973.             $result $this->listingRotationApi->paginate('/city/{city}/recent', ['city' => $city->getId()], $this->getCurrentPageNumber());
  974.             $response = new Response();
  975.             $response->setMaxAge(10);
  976.         } catch (\Exception) {
  977.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  978.         }
  979.         return $this->render('ProfileList/list.html.twig', [
  980.             'profiles' => $result,
  981.             'recommendationSpec' => $specs->recommendationSpec(),
  982.         ], response$response);
  983.     }
  984.     #[ParamConverter("city"converter"city_converter")]
  985.     public function listByNoRetouch(City $city): Response
  986.     {
  987.         $specs $this->profileListSpecificationService->listByNoRetouch();
  988.         $response null;
  989.         try {
  990.             $result $this->listingRotationApi->paginate('/city/{city}/noretouch', ['city' => $city->getId()], $this->getCurrentPageNumber());
  991.             $response = new Response();
  992.             $response->setMaxAge(10);
  993.         } catch (\Exception) {
  994.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  995.         }
  996.         $prevCount $result->count();
  997.         $result $this->checkEmptyResultNotMasseur($result$citynullself::RESULT_SOURCE_CITY);
  998.         if ($result->count() > $prevCount) {
  999.             $response?->setMaxAge(60);
  1000.         }
  1001.         return $this->render('ProfileList/list.html.twig', [
  1002.             'profiles' => $result,
  1003.             'source' => $this->source,
  1004.             'recommendationSpec' => $specs->recommendationSpec(),
  1005.         ], response$response);
  1006.     }
  1007.     #[ParamConverter("city"converter"city_converter")]
  1008.     public function listByNice(City $city): Response
  1009.     {
  1010.         $specs $this->profileListSpecificationService->listByNice();
  1011.         $response null;
  1012.         try {
  1013.             $result $this->listingRotationApi->paginate('/city/{city}/nice', ['city' => $city->getId()], $this->getCurrentPageNumber());
  1014.             $response = new Response();
  1015.             $response->setMaxAge(10);
  1016.         } catch (\Exception) {
  1017.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  1018.         }
  1019.         $prevCount $result->count();
  1020.         $result $this->checkEmptyResultNotMasseur($result$citynullself::RESULT_SOURCE_CITY);
  1021.         if ($result->count() > $prevCount) {
  1022.             $response?->setMaxAge(60);
  1023.         }
  1024.         return $this->render('ProfileList/list.html.twig', [
  1025.             'profiles' => $result,
  1026.             'source' => $this->source,
  1027.             'recommendationSpec' => $specs->recommendationSpec(),
  1028.         ], response$response);
  1029.     }
  1030.     #[ParamConverter("city"converter"city_converter")]
  1031.     public function listByOnCall(City $city): Response
  1032.     {
  1033.         $specs $this->profileListSpecificationService->listByOnCall();
  1034.         $response null;
  1035.         try {
  1036.             $result $this->listingRotationApi->paginate('/city/{city}/oncall', ['city' => $city->getId()], $this->getCurrentPageNumber());
  1037.             $response = new Response();
  1038.             $response->setMaxAge(10);
  1039.         } catch (\Exception) {
  1040.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  1041.         }
  1042.         $prevCount $result->count();
  1043.         $result $this->checkEmptyResultNotMasseur($result$citynullself::RESULT_SOURCE_CITY);
  1044.         if ($result->count() > $prevCount) {
  1045.             $response?->setMaxAge(60);
  1046.         }
  1047.         return $this->render('ProfileList/list.html.twig', [
  1048.             'profiles' => $result,
  1049.             'source' => $this->source,
  1050.             'recommendationSpec' => $specs->recommendationSpec(),
  1051.         ], response$response);
  1052.     }
  1053.     #[ParamConverter("city"converter"city_converter")]
  1054.     public function listForHour(City $city): Response
  1055.     {
  1056.         $specs $this->profileListSpecificationService->listForHour();
  1057.         $response null;
  1058.         try {
  1059.             $result $this->listingRotationApi->paginate('/city/{city}/forhour', ['city' => $city->getId()], $this->getCurrentPageNumber());
  1060.             $response = new Response();
  1061.             $response->setMaxAge(10);
  1062.         } catch (\Exception) {
  1063.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  1064.         }
  1065.         $prevCount $result->count();
  1066.         $result $this->checkEmptyResultNotMasseur($result$citynullself::RESULT_SOURCE_CITY);
  1067.         if ($result->count() > $prevCount) {
  1068.             $response?->setMaxAge(60);
  1069.         }
  1070.         return $this->render('ProfileList/list.html.twig', [
  1071.             'profiles' => $result,
  1072.             'source' => $this->source,
  1073.             'recommendationSpec' => $specs->recommendationSpec(),
  1074.         ], response$response);
  1075.     }
  1076.     #[ParamConverter("city"converter"city_converter")]
  1077.     public function listForNight(City $city): Response
  1078.     {
  1079.         $specs $this->profileListSpecificationService->listForNight();
  1080.         $response null;
  1081.         try {
  1082.             $result $this->listingRotationApi->paginate('/city/{city}/fornight', ['city' => $city->getId()], $this->getCurrentPageNumber());
  1083.             $response = new Response();
  1084.             $response->setMaxAge(10);
  1085.         } catch (\Exception) {
  1086.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  1087.         }
  1088.         $prevCount $result->count();
  1089.         $result $this->checkEmptyResultNotMasseur($result$citynullself::RESULT_SOURCE_CITY);
  1090.         if ($result->count() > $prevCount) {
  1091.             $response?->setMaxAge(60);
  1092.         }
  1093.         return $this->render('ProfileList/list.html.twig', [
  1094.             'profiles' => $result,
  1095.             'source' => $this->source,
  1096.             'recommendationSpec' => $specs->recommendationSpec(),
  1097.         ], response$response);
  1098.     }
  1099.     private function getSpecForEliteGirls(City $city):Filter
  1100.     {
  1101.         $minPrice $this->countryCurrencyResolver->getValueByCountryCode($city->getCountryCode(), [
  1102.             'RUB' => 5000,
  1103.             'UAH' => 1500,
  1104.             'USD' => 100,
  1105.             'EUR' => 130,
  1106.         ]);
  1107.         return new ProfileIsElite($minPrice);
  1108.     }
  1109.     private function getElasticSearchSpecForEliteGirls(City $city): ISpecification
  1110.     {
  1111.         $minPrice $this->countryCurrencyResolver->getValueByCountryCode($city->getCountryCode(), [
  1112.             'RUB' => 5000,
  1113.             'UAH' => 1500,
  1114.             'USD' => 100,
  1115.             'EUR' => 130,
  1116.         ]);
  1117.         return new \App\Specification\ElasticSearch\ProfileIsElite($minPrice);
  1118.     }
  1119.     #[ParamConverter("city"converter"city_converter")]
  1120.     public function listForEliteGirls(CountryCurrencyResolver $countryCurrencyResolverRequest $requestCity $city): Response
  1121.     {
  1122.         $specs $this->profileListSpecificationService->listForEliteGirls($city);
  1123.         $response null;
  1124.         try {
  1125.             $result $this->listingRotationApi->paginate('/city/{city}/elite', ['city' => $city->getId()], $this->getCurrentPageNumber());
  1126.             $response = new Response();
  1127.             $response->setMaxAge(10);
  1128.         } catch (\Exception) {
  1129.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  1130.         }
  1131.         $prevCount $result->count();
  1132.         if($this->features->fill_empty_profile_list() && $result->count() == 0) {
  1133.             $prices = [
  1134.                 'RUB' => 5000,
  1135.                 'UAH' => 1500,
  1136.                 'USD' => 100,
  1137.                 'EUR' => 130,
  1138.             ];
  1139.             $currency $countryCurrencyResolver->getCurrencyFor($city->getCountryCode());
  1140.             if(isset($prices[$currency])) {
  1141.                 $minPrice $prices[$currency];
  1142.                 switch ($currency) {
  1143.                     case 'RUB'$diff 1000; break;
  1144.                     case 'UAH'$diff 500; break;
  1145.                     case 'USD':
  1146.                     case 'EUR'$diff 20; break;
  1147.                     default:
  1148.                         throw new \LogicException('Unexpected currency code');
  1149.                 }
  1150.                 while ($minPrice >= $diff) {
  1151.                     $minPrice -= $diff;
  1152.                     $result $this->listRandomSinglePage($citynullProfileWithApartmentsOneHourPrice::moreExpensiveThan($minPrice), nulltruefalse);
  1153.                     if ($result->count() > 0) {
  1154.                         $this->source self::RESULT_SOURCE_BY_PARAMS;
  1155.                         break;
  1156.                     }
  1157.                 }
  1158.                 $result $this->checkEmptyResultNotMasseur($result$citynullself::RESULT_SOURCE_CITY);
  1159.             }
  1160.         }
  1161.         if ($result->count() > $prevCount) {
  1162.             $response?->setMaxAge(60);
  1163.         }
  1164.         return $this->render('ProfileList/list.html.twig', [
  1165.             'profiles' => $result,
  1166.             'source' => $this->source,
  1167.             'source_default' => self::RESULT_SOURCE_BY_PARAMS,
  1168.             'category_url' => $this->generateUrl($request->attributes->get('_route'), [
  1169.                 'city' => $city->getUriIdentity(),
  1170.                 'page' => $this->getCurrentPageNumber()
  1171.             ]),
  1172.             'recommendationSpec' => $specs->recommendationSpec(),
  1173.         ], response$response);
  1174.     }
  1175.     #[ParamConverter("city"converter"city_converter")]
  1176.     public function listForRealElite(CountryCurrencyResolver $countryCurrencyResolverCity $city): Response
  1177.     {
  1178.         $specs $this->profileListSpecificationService->listForRealElite($city);
  1179.         $response null;
  1180.         try {
  1181.             $result $this->listingRotationApi->paginate('/city/{city}/realelite', ['city' => $city->getId()], $this->getCurrentPageNumber());
  1182.             $response = new Response();
  1183.             $response->setMaxAge(10);
  1184.         } catch (\Exception) {
  1185.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  1186.         }
  1187.         $prevCount $result->count();
  1188.         $result $this->checkEmptyResultNotMasseur($result$citynullself::RESULT_SOURCE_CITY);
  1189.         if ($result->count() > $prevCount) {
  1190.             $response?->setMaxAge(60);
  1191.         }
  1192.         return $this->render('ProfileList/list.html.twig', [
  1193.             'profiles' => $result,
  1194.             'source' => $this->source,
  1195.             'recommendationSpec' => $specs->recommendationSpec(),
  1196.         ], response$response);
  1197.     }
  1198.     #[ParamConverter("city"converter"city_converter")]
  1199.     public function listForVipPros(CountryCurrencyResolver $countryCurrencyResolverCity $city): Response
  1200.     {
  1201.         $specs $this->profileListSpecificationService->listForVipPros($city);
  1202.         $response null;
  1203.         try {
  1204.             $result $this->listingRotationApi->paginate('/city/{city}/vip', ['city' => $city->getId()], $this->getCurrentPageNumber());
  1205.             $response = new Response();
  1206.             $response->setMaxAge(10);
  1207.         } catch (\Exception) {
  1208.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  1209.         }
  1210.         $prevCount $result->count();
  1211.         $result $this->checkEmptyResultNotMasseur($result$citynullself::RESULT_SOURCE_CITY);
  1212.         if ($result->count() > $prevCount) {
  1213.             $response?->setMaxAge(60);
  1214.         }
  1215.         return $this->render('ProfileList/list.html.twig', [
  1216.             'profiles' => $result,
  1217.             'source' => $this->source,
  1218.             'recommendationSpec' => $specs->recommendationSpec(),
  1219.         ], response$response);
  1220.     }
  1221.     #[ParamConverter("city"converter"city_converter")]
  1222.     public function listForVipIndividual(CountryCurrencyResolver $countryCurrencyResolverCity $city): Response
  1223.     {
  1224.         $specs $this->profileListSpecificationService->listForVipIndividual($city);
  1225.         $response null;
  1226.         try {
  1227.             $result $this->listingRotationApi->paginate('/city/{city}/vipindi', ['city' => $city->getId()], $this->getCurrentPageNumber());
  1228.             $response = new Response();
  1229.             $response->setMaxAge(10);
  1230.         } catch (\Exception) {
  1231.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  1232.         }
  1233.         $prevCount $result->count();
  1234.         $result $this->checkEmptyResultNotMasseur($result$citynullself::RESULT_SOURCE_CITY);
  1235.         if ($result->count() > $prevCount) {
  1236.             $response?->setMaxAge(60);
  1237.         }
  1238.         return $this->render('ProfileList/list.html.twig', [
  1239.             'profiles' => $result,
  1240.             'source' => $this->source,
  1241.             'recommendationSpec' => $specs->recommendationSpec(),
  1242.         ], response$response);
  1243.     }
  1244.     #[ParamConverter("city"converter"city_converter")]
  1245.     public function listForVipGirlsCity(City $city): Response
  1246.     {
  1247.         $specs $this->profileListSpecificationService->listForVipGirlsCity($city);
  1248.         $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  1249.         $result $this->checkEmptyResultNotMasseur($result$citynullself::RESULT_SOURCE_CITY);
  1250.         return $this->render('ProfileList/list.html.twig', [
  1251.             'profiles' => $result,
  1252.             'source' => $this->source,
  1253.             'recommendationSpec' => $specs->recommendationSpec(),
  1254.         ]);
  1255.     }
  1256.     #[ParamConverter("city"converter"city_converter")]
  1257.     public function listOfGirlfriends(City $city): Response
  1258.     {
  1259.         $specs $this->profileListSpecificationService->listOfGirlfriends();
  1260.         $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  1261.         $result $this->checkEmptyResultNotMasseur($result$citynullself::RESULT_SOURCE_CITY);
  1262.         return $this->render('ProfileList/list.html.twig', [
  1263.             'profiles' => $result,
  1264.             'source' => $this->source,
  1265.             'recommendationSpec' => $specs->recommendationSpec(),
  1266.         ]);
  1267.     }
  1268.     #[ParamConverter("city"converter"city_converter")]
  1269.     public function listOfMostExpensive(City $city): Response
  1270.     {
  1271.         $specs $this->profileListSpecificationService->listOfMostExpensive($city);
  1272.         $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec());
  1273.         $result $this->checkEmptyResultNotMasseur($result$citynullself::RESULT_SOURCE_CITY);
  1274.         return $this->render('ProfileList/list.html.twig', [
  1275.             'profiles' => $result,
  1276.             'source' => $this->source,
  1277.             'recommendationSpec' => $specs->recommendationSpec(),
  1278.         ]);
  1279.     }
  1280.     #[ParamConverter("city"converter"city_converter")]
  1281.     public function listBdsm(City $cityServiceRepository $serviceRepositoryParameterBagInterface $parameterBag): Response
  1282.     {
  1283.         $specs $this->profileListSpecificationService->listBdsm();
  1284.         $response null;
  1285.         try {
  1286.             $result $this->listingRotationApi->paginate('/city/{city}/bdsm', ['city' => $city->getId()], $this->getCurrentPageNumber());
  1287.             $response = new Response();
  1288.             $response->setMaxAge(10);
  1289.         } catch (\Exception) {
  1290.             $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec(), $specs->additionalSpecs());
  1291.         }
  1292.         $bdsmIds $serviceRepository->findBy(['group' => ServiceGroups::BDSM]);
  1293.         return $this->render('ProfileList/list.html.twig', [
  1294.             'profiles' => $result,
  1295.             'recommendationSpec' => $specs->recommendationSpec(),
  1296.         ], response$response);
  1297.     }
  1298.     #[ParamConverter("city"converter"city_converter")]
  1299.     public function listByGender(City $citystring $genderDefaultCityProvider $defaultCityProvider): Response
  1300.     {
  1301.         if($city->getId() != $defaultCityProvider->getDefaultCity()->getId()) {
  1302.             throw $this->createNotFoundException();
  1303.         }
  1304.         if(null === Genders::getValueByUriIdentity($gender))
  1305.             throw $this->createNotFoundException();
  1306.         $specs $this->profileListSpecificationService->listByGender($gender);
  1307.         $result $this->listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement($city$specs->spec(), $specs->additionalSpecs(), $specs->genders());
  1308.         return $this->render('ProfileList/list.html.twig', [
  1309.             'profiles' => $result,
  1310.             'recommendationSpec' => $specs->recommendationSpec(),
  1311.         ]);
  1312.     }
  1313.     protected function checkCityAndCountrySource(Page $resultCity $city): Page
  1314.     {
  1315.         if(($result && $result->count() != 0) || false == $this->features->fill_empty_profile_list())
  1316.             return $result;
  1317.         $this->source self::RESULT_SOURCE_CITY;
  1318.         $result $this->listRandomSinglePage($citynullnullnulltruefalse);
  1319.         if($result->count() == 0) {
  1320.             $this->source self::RESULT_SOURCE_COUNTRY;
  1321.             $result $this->listRandomSinglePage($city$city->getCountryCode(), nullnulltruefalse);
  1322.         }
  1323.         return $result;
  1324.     }
  1325.     protected function checkEmptyResultNotMasseur(Page $resultCity $city, ?OrX $alternativeSpecstring $source): Page
  1326.     {
  1327.         if($result->count() != || false == $this->features->fill_empty_profile_list())
  1328.             return $result;
  1329.         if(null != $alternativeSpec) {
  1330.             $this->source $source;
  1331.             $result $this->listRandomSinglePage($citynull$alternativeSpecnulltruefalse);
  1332.         }
  1333.         if($result->count() == 0)
  1334.             $result $this->checkCityAndCountrySource($result$city);
  1335.         return $result;
  1336.     }
  1337.     /**
  1338.      * Сейчас не используется, решили доставать их всех соседних подкатегорий разом.
  1339.      * Пока оставил, вдруг передумают.
  1340.      * @deprecated
  1341.      */
  1342.     public function listByNextSimilarCategories(callable $listMethod$requestCategory, array $similarItems): ORMQueryResult
  1343.     {
  1344.         $similarItems array_filter($similarItems, function($item) use ($requestCategory): bool {
  1345.             return $item != $requestCategory;
  1346.         });
  1347.         //shuffle($similarItems);
  1348.         $item null$result null;
  1349.         do {
  1350.             $item $item == null current($similarItems) : next($similarItems);
  1351.             if(false === $item)
  1352.                 return $result;
  1353.             $result $listMethod($item);
  1354.         } while($result->count() == 0);
  1355.         return $result;
  1356.     }
  1357.     protected function getCurrentPageNumber(): int
  1358.     {
  1359.         $page = (int) $this->requestStack->getCurrentRequest()?->get($this->pageParameter1);
  1360.         if ($page 1) {
  1361.             $page 1;
  1362.         }
  1363.         return $page;
  1364.     }
  1365.     protected function render(string $view, array $parameters = [], Response $response null): Response
  1366.     {
  1367.         $this->listingService->setCurrentListingPage($parameters['profiles']);
  1368.         $requestAttrs $this->requestStack->getCurrentRequest();
  1369.         $listing $requestAttrs->get('_controller');
  1370.         $listing is_array($listing) ? $listing[count($listing) - 1] : $listing;
  1371.         $listing preg_replace('/[^:]+::/'''$listing);
  1372.         $listingParameters $requestAttrs->get('_route_params');
  1373.         $listingParameters is_array($listingParameters) ? $listingParameters : [];
  1374.         $mainRequestHasPageParam = isset(($this->requestStack->getMainRequest()->get('_route_params') ?? [])['page']);
  1375.         if($this->requestStack->getCurrentRequest()->isXmlHttpRequest()) {
  1376.             $view = (
  1377.                 str_starts_with($listing'list')
  1378.                 && 'ProfileList/list.html.twig' === $view
  1379.                 && $mainRequestHasPageParam //isset($listingParameters['page'])
  1380.             )
  1381.                 ? 'ProfileList/list.profiles.html.twig'
  1382.                 $view
  1383.             ;
  1384.             return $this->prepareForXhr(parent::render($view$parameters$response));
  1385.             //return $this->getJSONResponse($parameters);
  1386.         } else {
  1387.             $parameters array_merge($parameters, [
  1388.                 'listing' => $listing,
  1389.                 'listing_parameters' => $listingParameters,
  1390.             ]);
  1391.             return parent::render($view$parameters$response);
  1392.         }
  1393.     }
  1394.     private function listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement(
  1395.         City $city, ?Filter $spec, array $additionalSpecs null, array $genders = [Genders::FEMALE]
  1396.     ): array|Page
  1397.     {
  1398.         return $this->profileList->listActiveWithinCityOrderedByStatusWithSpec($city$spec$additionalSpecs$genders$this->getCurrentPageNumber() < 2);
  1399.     }
  1400.     private function listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacementLimited(
  1401.         City $city, ?Filter $spec, array $additionalSpecs null, array $genders = [Genders::FEMALE], int $limit 0,
  1402.     ): array|Page
  1403.     {
  1404.         return $this->profileList->listActiveWithinCityOrderedByStatusWithSpecLimited($city$spec$additionalSpecs$genderstrue$limit);
  1405.     }
  1406.     private function listRandomSinglePage(
  1407.         City $city, ?string $country, ?Filter $spec, ?array $additionalSpecsbool $active, ?bool $masseur false,
  1408.         array $genders = [Genders::FEMALE]
  1409.     ): Page
  1410.     {
  1411.         return $this->profileList->listRandom($city$country$spec$additionalSpecs$active$masseur$genderstrue);
  1412.     }
  1413.     private function shuffleProfilesOnPage(Page $result): Page
  1414.     {
  1415.         $profiles iterator_to_array($result->getIterator());
  1416.         if(count($profiles) > 1) {
  1417.             shuffle($profiles);
  1418.         }
  1419.         return new FakeORMQueryPage(
  1420.             $result->getCurrentOffset(),
  1421.             $result->getCurrentPage(),
  1422.             $result->getCurrentLimit(),
  1423.             $result->totalCount(),
  1424.             $profiles
  1425.         );
  1426.     }
  1427. //    protected function getJSONResponse(array $parameters)
  1428. //    {
  1429. //        $request = $this->request;
  1430. //        $data = json_decode($request->getContent(), true);
  1431. //
  1432. //        $imageSize = !empty($data['imageSize']) ? $data['imageSize'] : "357x500";
  1433. //
  1434. //        /** @var FakeORMQueryPage $queryPage */
  1435. //        $queryPage = $parameters['profiles'];
  1436. //
  1437. //        $profiles = array_map(function(ProfileListingReadModel $profile) use ($imageSize) {
  1438. //            $profile->stations = array_values($profile->stations);
  1439. //            $profile->avatar['path'] = $this->responsiveAssetsService->getResponsiveImageUrl($profile->avatar['path'], 'profile_media', $imageSize, 'jpg');
  1440. //            $profile->uri = $this->generateUrl('profile_preview.page', ['city' => $profile->city->uriIdentity, 'profile' => $profile->uriIdentity]);
  1441. //            return $profile;
  1442. //        }, $queryPage->getArray());
  1443. //
  1444. //        return new JsonResponse([
  1445. //            'profiles' => $profiles,
  1446. //            'currentPage' => $queryPage->getCurrentPage(),
  1447. //        ], Response::HTTP_OK);
  1448. //    }
  1449. }