src/Controller/ProfileBotHelperController.php line 32

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\Profile\Profile;
  6. use App\Service\ProfileAvatar;
  7. use App\Service\ProfileBotHelper;
  8. use App\Service\ResponsiveAssetsService;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\RequestStack;
  12. use Symfony\Component\HttpFoundation\Response;
  13. class ProfileBotHelperController extends AbstractController
  14. {
  15.     use ProfileMinPriceTrait;
  16.     private Request $request;
  17.     public function __construct(
  18.         private ProfileBotHelper        $profileBotHelper,
  19.         private ProfileAvatar           $profileAvatar,
  20.         private ResponsiveAssetsService $responsiveAssetsService,
  21.         RequestStack                    $requestStack,
  22.     )
  23.     {
  24.         $this->request $requestStack->getCurrentRequest();
  25.     }
  26.     public function getRecommendations(City $cityint $count 10string $imageSize '357x500'string $exclude ''): Response
  27.     {
  28.         $parameters = [];
  29.         $data $this->request->getContent();
  30.         $data json_decode($datatrue);
  31.         $viewedProfiles $data['viewed_profiles'] ?? [];
  32.         $viewedRecommendations $data['viewed_recommendations'] ?? [];
  33.         $this->profileBotHelper->setViewedProfiles($viewedProfiles);
  34.         if ($this->profileBotHelper->hasMinimumNeededViewedProfilesCount()) {
  35.             $exclude explode(','$exclude);
  36.             $profiles $this->profileBotHelper->getRecommendations($citynull$viewedProfiles$viewedRecommendations$exclude$countGenders::FEMALE);
  37.             $locale $this->request->getLocale() ?: 'ru';
  38.             $profiles array_map(function (Profile $profile) use ($city$imageSize$locale): array {
  39.                 $avatar $this->profileAvatar->getAvatar($profile);
  40.                 return [
  41.                     'id' => $profile->getId(),
  42.                     'name' => $profile->getName()->getTranslation('ru'),
  43.                     'url' => $this->generateUrl('profile_preview.page', ['city' => $city->getUriIdentity(), 'profile' => $profile->getUriIdentity()]),
  44.                     'image' => $avatar
  45.                         $this->responsiveAssetsService->getResponsiveImageUrl($this->profileAvatar->getAvatar($profile)->getPath(), 'profile_media'$imageSize'jpg')
  46.                         : '',
  47.                     'approved' => $profile->isApproved(),
  48.                     'station' => $profile->getPrimaryStation()?->getName()->getTranslation($locale),
  49.                     'age' => $profile->getPersonParameters()->getAge(),
  50.                     'phone' => $profile->getPhoneNumber(),
  51.                     'price' => $this->getMinPrice($profile->getApartmentsPricing(), $profile->getTakeOutPricing()),
  52.                 ];
  53.             }, $profiles);
  54.             $parameters['profiles'] = $profiles;
  55.             $parameters['coeffs_debug'] = $this->profileBotHelper->getCoeffsDataDebug();
  56.             $parameters['viewed_recommendations_debug'] = $this->profileBotHelper->getViewedRecommendationsDataDebug();
  57.         } else {
  58.             $parameters['viewed_profiles_count'] = $this->profileBotHelper->viewedProfilesCount();
  59.             $parameters['needed_viewed_profiles_count'] = $this->profileBotHelper->minimumNeededViewedProfilesCount();
  60.         }
  61.         // return $this->render('BotHelper/profile_bot_helper_debug.html.twig', $parameters);
  62.         return $this->json($parameters);
  63.     }
  64.     /**
  65.      * @deprecated хранение просмотренных анкет и рекомендаций вынесено в localStorage, соответственно и функционал
  66.      * startOver (сброс сохраненныъ просмотренных страниц анкет) вынесен туда
  67.      */
  68.     public function startOver(City $city): Response
  69.     {
  70.         return $this->forward('App\Controller\ProfileBotHelperController::getRecommendations', [
  71.             'city' => $city,
  72.         ]);
  73.     }
  74. }