src/Controller/MapController.php line 56

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Location\City;
  4. use App\Entity\Profile\Genders;
  5. use App\Entity\Saloon\Saloon;
  6. use App\Event\Profile\ProfilesShownEvent;
  7. use App\Form\FilterMapForm;
  8. use App\Repository\CityRepository;
  9. use App\Repository\ProfileRepository;
  10. use App\Repository\ReadModel\ProfileMapReadModel;
  11. use App\Repository\SaloonRepository;
  12. use App\Repository\ServiceRepository;
  13. use App\Service\Features;
  14. use App\Service\ProfileList;
  15. use App\Specification\Profile\ProfileHasMapCoordinates;
  16. use App\Specification\Profile\ProfileIdINOrderedByINValues;
  17. use App\Specification\Profile\ProfileIsLocated;
  18. use App\Specification\QueryModifier\PossibleSaloonAdBoardPlacement;
  19. use App\Specification\QueryModifier\PossibleSaloonPlacementHiding;
  20. use App\Specification\Saloon\SaloonIsNotHidden;
  21. use App\Specification\QueryModifier\SaloonThumbnail;
  22. use App\Specification\Saloon\SaloonIsActive;
  23. use Happyr\DoctrineSpecification\Spec;
  24. use Psr\Cache\CacheItemPoolInterface;
  25. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  26. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  27. use Symfony\Component\Asset\Packages;
  28. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  29. use Symfony\Component\HttpFoundation\JsonResponse;
  30. use Symfony\Component\HttpFoundation\Request;
  31. use Symfony\Component\HttpFoundation\Response;
  32. use Symfony\Contracts\Cache\ItemInterface;
  33. use Symfony\Contracts\Translation\TranslatorInterface;
  34. class MapController extends AbstractController
  35. {
  36.     use ProfileMinPriceTrait;
  37.     const MAP_PROFILES_CACHE_ITEM_NAME 'map_profiles_';
  38.     public function __construct(
  39.         private ProfileRepository $profileRepository,
  40.         private CityRepository $cityRepository,
  41.         private Features $features,
  42.         private Packages $assetPackage,
  43.         private SaloonRepository $saloonRepository,
  44.         private ProfileList $profileList,
  45.         private EventDispatcherInterface $eventDispatcher,
  46.         private ServiceRepository $serviceRepository,
  47.         private CacheItemPoolInterface $profilesFilterCache,
  48.     ) {}
  49.     #[ParamConverter("city"converter"city_converter")]
  50.     public function page(City $city): Response
  51.     {
  52.         return $this->render('Map/page.html.twig', [
  53.             'cityUriIdentity' => $city->getUriIdentity(),
  54.             'cityLatitude' => $city->getMapCoordinate()->getLatitude(),
  55.             'cityLongitude' => $city->getMapCoordinate()->getLongitude(),
  56.             'multipleCities' => (int)$this->features->multiple_cities(),
  57.         ]);
  58.     }
  59.     public function form(City $city): Response
  60.     {
  61.         $form $this->createForm(FilterMapForm::class, null, ['data' => ['city_id' => $city->getId()]]);
  62.         return $this->render('Map/form.html.twig', [
  63.             'form' => $form->createView(),
  64.         ]);
  65.     }
  66.     public function filter(Request $requestTranslatorInterface $translator): Response
  67.     {
  68. //        $this->detail($request, $translator);
  69.         $params json_decode($request->request->get('form'), true);
  70.         $form $this->createForm(FilterMapForm::class);
  71.         $form->submit($params);
  72.         $scale $request->request->get('scale') ?? 0;
  73.         if($scale <= 8) {
  74.             $coordsRoundPrecision 2;
  75.         } else if($scale <= 14) {
  76.             $coordsRoundPrecision 3;
  77.         } else {
  78.             $coordsRoundPrecision 4;
  79.         }
  80.         $city $this->cityRepository->find($params['city_id']);
  81.         $profiles $this->profileList->listForMap(
  82.             $citynull$form->getData(), [new ProfileHasMapCoordinates()], truenull,
  83.             ProfileList::ORDER_NONE, [Genders::FEMALE], $coordsRoundPrecision,
  84.         );
  85.         $specs Spec::andX(
  86.             $this->features->free_profiles() ? new SaloonIsNotHidden() : new SaloonIsActive(),
  87.             new PossibleSaloonPlacementHiding(),
  88.             new PossibleSaloonAdBoardPlacement(),
  89.             new SaloonThumbnail(),
  90.             ProfileIsLocated::withinCity($city),
  91.             new ProfileHasMapCoordinates(),
  92.         );
  93.         $saloons $this->saloonRepository->listForMapMatchingSpec($specs$coordsRoundPrecision);
  94.         $out = [
  95.             'profiles' => array_map('array_values'$profiles),
  96.             'saloons' => array_map('array_values'$saloons),
  97.         ];
  98.         return $this->json($out);
  99.     }
  100.     public function detail(Request $requestTranslatorInterface $translator): Response
  101.     {
  102.         $services $this->serviceRepository->allIndexedById();
  103.         $profileIds json_decode($request->request->get('profiles'), true);
  104.         $saloonIds json_decode($request->request->get('saloons'), true);
  105.         $profileIds = [121705,25486];
  106.         $saloonIds = [126,123];
  107.         $result $this->profileRepository->fetchMapProfilesByIds(new ProfileIdINOrderedByINValues($profileIds));
  108.         $profiles = [];
  109.         foreach ($result as /** @var ProfileMapReadModel $profile */$profile) {
  110.             if(!$profile->mapLatitude || !$profile->mapLongitude)
  111.                 continue;
  112.             $path $profile->avatar['path'];
  113.             $path str_starts_with($path'/') ? $path substr($path6, -4);
  114.             $hasApartment $profile->apartmentOneHourPrice || $profile->apartmentTwoHoursPrice || $profile->apartmentNightPrice;
  115.             $hasTakeout $profile->takeOutOneHourPrice || $profile->takeOutTwoHoursPrice || $profile->takeOutNightPrice;
  116.             $tags = [];
  117.             if($hasApartment && !$hasTakeout)
  118.                 $tags[] = 1;
  119.             elseif(!$hasApartment && $hasTakeout)
  120.                 $tags[] = 2;
  121.             elseif ($hasApartment && $hasTakeout)
  122.                 $tags[] = 3;
  123.             foreach ($profile->services as $serviceId) {
  124.                 $serviceName mb_strtolower($services[$serviceId]->getName()->getTranslation('ru'));
  125.                 switch($serviceName) {
  126.                     case 'секс классический'$tags[] = 4; break;
  127.                     case 'секс анальный'$tags[] = 5; break;
  128.                     case 'минет без резинки'$tags[] = 6; break;
  129.                     case 'куннилингус'$tags[] = 7; break;
  130.                     case 'окончание в рот'$tags[] = 8; break;
  131.                     case 'массаж': if(false === in_array(9$tags)) $tags[] = 9; break;
  132.                 }
  133.             }
  134.             $profiles[] = [
  135.                 1,
  136.                 (float)rtrim(substr($profile->mapLatitude07), '0'),
  137.                 (float)rtrim(substr($profile->mapLongitude07), '0'),
  138.                 $profile->uriIdentity,
  139.                 $profile->name,
  140.                 $path//$profile->avatar['path'],
  141.                 //$profile->avatar['type'] ? 'avatar' : 'photo',
  142.                 str_replace(' '''$profile->phoneNumber),
  143.                 $profile->station ?? 0,
  144.                 $profile->apartmentOneHourPrice ?? $profile->takeOutOneHourPrice ?? 0,
  145.                 $profile->apartmentTwoHoursPrice ?? $profile->takeOutTwoHoursPrice ?? 0,
  146.                 $profile->apartmentNightPrice ?? $profile->takeOutNightPrice ?? 0,
  147.                 (int)$profile->isApproved,
  148.                 (int)$profile->isMasseur,
  149.                 (int)$profile->hasComments,
  150.                 (int)$profile->hasSelfies,
  151.                 (int)$profile->hasVideos,
  152.                 $profile->age ?? 0,
  153.                 $profile->breastSize ?? 0,
  154.                 $profile->height ?? 0,
  155.                 $profile->weight ?? 0,
  156.                 $tags,
  157.                 $profile->id,
  158.                 (int)$profile->isPaid,
  159.             ];
  160.         }
  161.         $result $this->saloonRepository->matchingSpecRaw(new ProfileIdINOrderedByINValues($saloonIds), nullfalse);
  162.         $saloons = [];
  163.         foreach ($result as /** @var Saloon $saloon */ $saloon) {
  164.             $photoPath null !== ($mainPhoto $saloon->getThumbnail()) ? $mainPhoto->getPath() : '';
  165.             $photoPath str_starts_with($photoPath'/') ? $photoPath str_replace(".jpg"""substr($photoPath6));
  166.             $saloons[] = [
  167.                 2,
  168.                 (float)rtrim(substr($saloon->getMapCoordinate()->getLatitude(), 07), '0'),
  169.                 (float)rtrim(substr($saloon->getMapCoordinate()->getLongitude(), 07), '0'),
  170.                 $saloon->getUriIdentity(),
  171.                 $translator->trans($saloon->getName()),
  172.                 $photoPath,
  173.                 //'thumb',
  174.                 str_replace(' '''$saloon->getPhoneNumber()),
  175.                 $saloon->getStations()->count() ? $saloon->getStations()->first()->getId() : 0,
  176.                 $saloon->getApartmentsPricing()->getOneHourPrice() ?? $saloon->getTakeOutPricing()->getOneHourPrice() ?? 0,
  177.                 $saloon->getApartmentsPricing()->getTwoHoursPrice() ?? $saloon->getTakeOutPricing()->getTwoHoursPrice() ?? 0,
  178.                 $saloon->getApartmentsPricing()->getNightPrice() ?? $saloon->getTakeOutPricing()->getNightPrice() ?? 0,
  179.                 //$saloon->getExpressPricing()->isProvided() ? $saloon->getExpressPricing()->getPrice() ?? 0 : 0,
  180.                 (int)($saloon?->getAdBoardPlacement() !== null),
  181.             ];
  182.         }
  183.                 
  184.         return new JsonResponse([
  185.             'profiles' => $profiles,
  186.             'saloons' => $saloons,
  187.         ]);
  188.     }
  189.     public function processProfileShows(Request $requestProfileRepository $profileRepository): JsonResponse
  190.     {
  191.         $id $request->query->get('id');
  192.         $profile $profileRepository->find($id);
  193.         if($profile) {
  194.             $this->eventDispatcher->dispatch(new ProfilesShownEvent([$profile->getId()], 'map'), ProfilesShownEvent::NAME);
  195.         }
  196.         return $this->json([]);
  197.     }
  198.     public function cachedMapProfilesResultByIds(ProfileIdINOrderedByINValues $specification)
  199.     {
  200.         $key sha1(self::MAP_PROFILES_CACHE_ITEM_NAME implode(','$specification->getIds()));
  201.         return $this->profilesFilterCache->get($key, function (ItemInterface $item) use ($specification) {
  202.             return $this->profileRepository->fetchMapProfilesByIds($specification);
  203.         });
  204.     }
  205. }