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.         $params json_decode($request->request->get('form'), true);
  69.         $form $this->createForm(FilterMapForm::class);
  70.         $form->submit($params);
  71.         $scale $request->request->get('scale') ?? 0;
  72.         if($scale <= 8) {
  73.             $coordsRoundPrecision 2;
  74.         } else if($scale <= 14) {
  75.             $coordsRoundPrecision 3;
  76.         } else {
  77.             $coordsRoundPrecision 4;
  78.         }
  79.         $city $this->cityRepository->find($params['city_id']);
  80.         $profiles $this->profileList->listForMap(
  81.             $citynull$form->getData(), [new ProfileHasMapCoordinates()], truenull,
  82.             ProfileList::ORDER_NONE, [Genders::FEMALE], $coordsRoundPrecision,
  83.         );
  84.         $specs Spec::andX(
  85.             $this->features->free_profiles() ? new SaloonIsNotHidden() : new SaloonIsActive(),
  86.             new PossibleSaloonPlacementHiding(),
  87.             new PossibleSaloonAdBoardPlacement(),
  88.             new SaloonThumbnail(),
  89.             ProfileIsLocated::withinCity($city),
  90.             new ProfileHasMapCoordinates(),
  91.         );
  92.         $saloons $this->saloonRepository->listForMapMatchingSpec($specs$coordsRoundPrecision);
  93.         $rowConverter = function($row) {
  94.             $row array_values($row);
  95.             $row[0] = array_map('intval'explode(','$row[0]));
  96.             $row[2] = array_map('intval'explode(','$row[2]));
  97.             return $row;
  98.         };
  99.         $out = [
  100.             'profiles' => array_map($rowConverter$profiles),
  101.             'saloons' => array_map($rowConverter$saloons),
  102.         ];
  103.         return $this->json($out);
  104.     }
  105.     public function detail(Request $requestTranslatorInterface $translator): Response
  106.     {
  107.         $services $this->serviceRepository->allIndexedById();
  108.         $profileIds = ($requestedProfiles $request->request->get('profiles')) ? explode(','$requestedProfiles) : [];
  109.         $saloonIds = ($requestedSaloons $request->request->get('saloons')) ? explode(','$requestedSaloons) : [];
  110.         $result = !empty($profileIds) ? $this->profileRepository->fetchMapProfilesByIds(new ProfileIdINOrderedByINValues($profileIds)) : [];
  111.         $profiles = [];
  112.         foreach ($result as /** @var ProfileMapReadModel $profile */$profile) {
  113.             if(!$profile->mapLatitude || !$profile->mapLongitude)
  114.                 continue;
  115.             $path $profile->avatar['path'];
  116.             $path str_starts_with($path'/') ? $path substr($path6, -4);
  117.             $hasApartment $profile->apartmentOneHourPrice || $profile->apartmentTwoHoursPrice || $profile->apartmentNightPrice;
  118.             $hasTakeout $profile->takeOutOneHourPrice || $profile->takeOutTwoHoursPrice || $profile->takeOutNightPrice;
  119.             $tags = [];
  120.             if($hasApartment && !$hasTakeout)
  121.                 $tags[] = 1;
  122.             elseif(!$hasApartment && $hasTakeout)
  123.                 $tags[] = 2;
  124.             elseif ($hasApartment && $hasTakeout)
  125.                 $tags[] = 3;
  126.             foreach ($profile->services as $serviceId) {
  127.                 $serviceName mb_strtolower($services[$serviceId]->getName()->getTranslation('ru'));
  128.                 switch($serviceName) {
  129.                     case 'секс классический'$tags[] = 4; break;
  130.                     case 'секс анальный'$tags[] = 5; break;
  131.                     case 'минет без резинки'$tags[] = 6; break;
  132.                     case 'куннилингус'$tags[] = 7; break;
  133.                     case 'окончание в рот'$tags[] = 8; break;
  134.                     case 'массаж': if(false === in_array(9$tags)) $tags[] = 9; break;
  135.                 }
  136.             }
  137.             $profiles[] = [
  138.                 1,
  139.                 (float)rtrim(substr($profile->mapLatitude07), '0'),
  140.                 (float)rtrim(substr($profile->mapLongitude07), '0'),
  141.                 $profile->uriIdentity,
  142.                 $profile->name,
  143.                 $path//$profile->avatar['path'],
  144.                 //$profile->avatar['type'] ? 'avatar' : 'photo',
  145.                 str_replace(' '''$profile->phoneNumber),
  146.                 $profile->station ?? 0,
  147.                 $profile->apartmentOneHourPrice ?? $profile->takeOutOneHourPrice ?? 0,
  148.                 $profile->apartmentTwoHoursPrice ?? $profile->takeOutTwoHoursPrice ?? 0,
  149.                 $profile->apartmentNightPrice ?? $profile->takeOutNightPrice ?? 0,
  150.                 (int)$profile->isApproved,
  151.                 (int)$profile->isMasseur,
  152.                 (int)$profile->hasComments,
  153.                 (int)$profile->hasSelfies,
  154.                 (int)$profile->hasVideos,
  155.                 $profile->age ?? 0,
  156.                 $profile->breastSize ?? 0,
  157.                 $profile->height ?? 0,
  158.                 $profile->weight ?? 0,
  159.                 $tags,
  160.                 $profile->id,
  161.                 (int)$profile->isPaid ?? 0,
  162.             ];
  163.         }
  164.         $saloonIds = [1,2];
  165.         $result = !empty($saloonIds) ? $this->saloonRepository->matchingSpecRaw(new ProfileIdINOrderedByINValues($saloonIds), nullfalse) : [];
  166.         $saloons = [];
  167.         foreach ($result as /** @var Saloon $saloon */ $saloon) {
  168.             $photoPath null !== ($mainPhoto $saloon->getThumbnail()) ? $mainPhoto->getPath() : '';
  169.             $photoPath str_starts_with($photoPath'/') ? $photoPath str_replace(".jpg"""substr($photoPath6));
  170.             $saloons[] = [
  171.                 2,
  172.                 (float)rtrim(substr($saloon->getMapCoordinate()->getLatitude(), 07), '0'),
  173.                 (float)rtrim(substr($saloon->getMapCoordinate()->getLongitude(), 07), '0'),
  174.                 $saloon->getUriIdentity(),
  175.                 $translator->trans($saloon->getName()),
  176.                 $photoPath,
  177.                 //'thumb',
  178.                 str_replace(' '''$saloon->getPhoneNumber()),
  179.                 $saloon->getStations()->count() ? $saloon->getStations()->first()->getId() : 0,
  180.                 $saloon->getApartmentsPricing()->getOneHourPrice() ?? $saloon->getTakeOutPricing()->getOneHourPrice() ?? 0,
  181.                 $saloon->getApartmentsPricing()->getTwoHoursPrice() ?? $saloon->getTakeOutPricing()->getTwoHoursPrice() ?? 0,
  182.                 $saloon->getApartmentsPricing()->getNightPrice() ?? $saloon->getTakeOutPricing()->getNightPrice() ?? 0,
  183.                 //$saloon->getExpressPricing()->isProvided() ? $saloon->getExpressPricing()->getPrice() ?? 0 : 0,
  184.                 (int)($saloon?->getAdBoardPlacement() !== null),
  185.             ];
  186.         }
  187.         return new JsonResponse([
  188.             'profiles' => $profiles,
  189.             'saloons' => $saloons,
  190.         ]);
  191.     }
  192.     public function processProfileShows(Request $requestProfileRepository $profileRepository): JsonResponse
  193.     {
  194.         $id $request->query->get('id');
  195.         $profile $profileRepository->find($id);
  196.         if($profile) {
  197.             $this->eventDispatcher->dispatch(new ProfilesShownEvent([$profile->getId()], 'map'), ProfilesShownEvent::NAME);
  198.         }
  199.         return $this->json([]);
  200.     }
  201.     public function cachedMapProfilesResultByIds(ProfileIdINOrderedByINValues $specification)
  202.     {
  203.         $key sha1(self::MAP_PROFILES_CACHE_ITEM_NAME implode(','$specification->getIds()));
  204.         return $this->profilesFilterCache->get($key, function (ItemInterface $item) use ($specification) {
  205.             return $this->profileRepository->fetchMapProfilesByIds($specification);
  206.         });
  207.     }
  208. }