src/Controller/MapController.php line 57

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