src/Controller/Account/AccountController.php line 184

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Account;
  3. use AngelGamez\PorpaginasBundle\Controller\PaginationTrait;
  4. use App\Entity\Account\Customer;
  5. use App\Entity\User;
  6. use App\Form\BulkActionForm;
  7. use App\Form\ChangeAccountPasswordForm;
  8. use App\Form\ChangeAccountInformationForm;
  9. use App\Repository\ProfileRepository;
  10. use App\Repository\SaloonRepository;
  11. use App\Service\AccountChargesDurationEstimator;
  12. use App\Service\AccountChargesDurationPresenter;
  13. use App\Service\BulkQueueService;
  14. use App\Service\DynamicPlacementPriceResolver;
  15. use App\Service\Features;
  16. use App\Service\ProfileCtrService;
  17. use App\Service\UserService;
  18. use Doctrine\ORM\EntityManagerInterface;
  19. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  20. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  21. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  22. use Symfony\Component\HttpFoundation\JsonResponse;
  23. use Symfony\Component\HttpFoundation\RedirectResponse;
  24. use Symfony\Component\HttpFoundation\Request;
  25. use Symfony\Component\HttpFoundation\RequestStack;
  26. use Symfony\Component\HttpFoundation\Response;
  27. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  28. use Symfony\Component\HttpKernel\KernelInterface;
  29. use Symfony\Component\Routing\Annotation\Route;
  30. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  31. class AccountController extends AbstractController
  32. {
  33.     use PaginationTrait;
  34.     use AccountListFilterTrait;
  35.     private const STEP_TURN_ON_PROFILE 0;
  36.     private const STEP_ENTER_PHONE 1;
  37.     private const STEP_SEND_CODE 2;
  38.     private const STEP_CONNECT_PROFILES 3;
  39.     private const STEP_REPEAT_CALL 4;
  40.     public const ACTION_ACTIVATE 1;
  41.     public const ACTION_DEACTIVATE 2;
  42.     const LEGACY_MASSEUR_LIST_PARAM 'massagers';
  43.     const AVAILABLE_CTR_PERIODS = ['today''yesterday''week''month''all_time'];
  44.     const AVAILABLE_PROFILE_PLACEMENT_TYPES = ['all''paid''free''ultra-vip''vip''standard''hidden'];
  45.     private KernelInterface $kernel;
  46.     private Features $features;
  47.     function __construct(
  48.         RequestStack $requestStackSessionInterface $sessionParameterBagInterface $parameterBag,
  49.         KernelInterface $kernelFeatures $featuresProfileRepository $profileRepository
  50.     )
  51.     {
  52.         $this->request $requestStack->getCurrentRequest();
  53.         $this->session $session;
  54.         $this->parameterBag $parameterBag;
  55.         $this->availablePlacementTypeFilters self::AVAILABLE_PROFILE_PLACEMENT_TYPES;
  56.         $this->kernel $kernel;
  57.         $this->profileRepository $profileRepository;
  58.         $this->features $features;
  59.     }
  60.     /**
  61.      * @throws \Doctrine\ORM\NoResultException
  62.      * @throws \Doctrine\ORM\NonUniqueResultException
  63.      */
  64.     #[Route(path'/'name'account'options: ['expose' => true])]
  65.     #[Route(path'/page{page<\d+>}/'name'account._pagination'options: ['expose' => true])]
  66.     #[Security("is_granted('ROLE_ADVERTISER') or is_granted('ROLE_CUSTOMER')")]
  67.     public function homepage(ProfileRepository $profileRepositorySaloonRepository $saloonRepository,
  68.         Request $requestParameterBagInterface $parameterBagSessionInterface $sessionProfileCtrService $profileCtrService,
  69.         BulkQueueService $bulkQueueService): Response
  70.     {
  71.         $user $this->getUser();
  72.         if($user instanceof Customer) {
  73.             return $this->redirectToRoute('account.preferred_profiles.list');
  74.         }
  75.         if($this->features->account_main_is_profiles()) {
  76.             return $this->redirectToRoute('account_girls');
  77.         }
  78.         list(
  79.             'per_page' => $perPage'placement_type_filter' => $placementTypeFilter'name_filter' =>  $nameFilter,
  80.             'sort' =>  $sort'sort_direction' =>  $sortDirection'ctr_period' => $ctrPeriod,
  81.             ) = $this->processListRequestData($requesttrue);
  82.         $profilesCtr $profileCtrService->getCtrByOwner($user$ctrPeriod);
  83.         $profileIdsWaitingAction $bulkQueueService->getProfilesWaitingAction($user);
  84.         $isMasseur $this->features->non_masseur_on_account_profile_list() ? false null;
  85.         $profiles $this->getFilteredAndSortedProfiles(
  86.             $user$perPage$sort$sortDirection$placementTypeFilter$nameFilter$profilesCtr$isMasseur
  87.         );
  88.         $templateParameters = [
  89.             'is_masseur_list' => null,
  90.             'profiles' => $profiles,
  91.             'all_profiles_ids' => $this->showDebugData() ? $this->getProfileIdsByFilter($user$placementTypeFilter$nameFilternull) : [],
  92.             'profiles_ctr' => $profilesCtr,
  93.             'ctr_period' => $ctrPeriod,
  94.             'per_page' => $perPage == 99999 ? -$perPage,
  95.             'placement_type_filter' => $placementTypeFilter,
  96.             'name_filter' => $nameFilter,
  97.             'sort' => $sort,
  98.             'sort_direction' => $sortDirection,
  99.             'profiles_waiting_action' => $profileIdsWaitingAction,
  100.         ];
  101.         if($request->isXmlHttpRequest()) {
  102.             return $this->render('account/advertiser/account.profiles.html.twig'$templateParameters);
  103.         } else {
  104.             if(null !== ($redirectResponse $this->redirectToRouteWithoutPaginationIfNeeded($profiles)))
  105.                 return $redirectResponse;
  106.             $bulkAction $this->createForm(BulkActionForm::class, null, [
  107.                 'action' => $this->generateUrl('account.profile_management.bulk_action'),
  108.                 'method' => 'post',
  109.                 'data' => [
  110.                     'entity_repository' => $profileRepository,
  111.                 ],
  112.             ]);
  113.             return $this->render('account/advertiser/account.html.twig'array_merge($templateParameters, [
  114.                 'user' => $user,
  115.                 'profiles_active_count' => $profileRepository->countActiveOfOwner($user$this->features->non_masseur_on_account_profile_list() ? false null),
  116.                 'profiles_all_count' => $profileRepository->countAllOfOwnerNotDeleted($user$this->features->non_masseur_on_account_profile_list() ? false null),
  117.                 'masseurs_active_count' => $profileRepository->countActiveOfOwner($usertrue),
  118.                 'masseurs_all_count' => $profileRepository->countAllOfOwnerNotDeleted($usertrue),
  119.                 'saloons_active_count' => $saloonRepository->countActiveOfOwner($user),
  120.                 'saloons_all_count' => $saloonRepository->countAllOfOwner($user),
  121.                 'bulk_form' => $bulkAction->createView(),
  122.                 'per_page_variants' => explode(','$parameterBag->get('account.setting.advertiser_profile_list_per_page.variants')),
  123.                 'ctr_periods' => AccountController::AVAILABLE_CTR_PERIODS,
  124.                 'placement_type_filter_variants' => self::AVAILABLE_PROFILE_PLACEMENT_TYPES,
  125.             ]));
  126.         }
  127.     }
  128.     #[Route(path'/profile/'name'account.settings')]
  129.     #[Security("is_granted('ROLE_ADVERTISER') or is_granted('ROLE_CUSTOMER')")]
  130.     public function accountProfileEdit(Request $requestUserService $userServiceParameterBagInterface $parameterBag): RedirectResponse|Response
  131.     {
  132.         /** @var User $user */
  133.         $user $this->getUser();
  134.         $form $this->createForm(ChangeAccountInformationForm::class, $user);
  135.         $form->handleRequest($request);
  136.         $passwordForm $this->createForm(ChangeAccountPasswordForm::class);
  137.         $passwordForm->handleRequest($request);
  138.         if ($form->isSubmitted() && $form->isValid()) {
  139.             $userService->edit($form->getData());
  140.             $this->addFlash('success''Profile settings updated.');
  141.             return $this->redirectToRoute('account.settings');
  142.         } elseif ($passwordForm->isSubmitted() && $passwordForm->isValid()) {
  143.             $newPassword $passwordForm->get('new_password')->getData();
  144.             $userService->changePassword($user$newPassword);
  145.             $this->addFlash('success''Profile password updated.');
  146.             return $this->redirectToRoute('account.settings');
  147.         }
  148.         return $this->render('account/profile.html.twig', [
  149.             'user' => $user,
  150.             'form' => $form->createView(),
  151.             'password_form' => $passwordForm->createView(),
  152.             'approval_media_upload_domain' => $parameterBag->get('app.approval_media_upload_domain'),
  153.         ]);
  154.     }
  155.     #[Route(path'/top/'name'account.profile.top_placement')]
  156.     #[Route(path'/top/page{page<\d+>}/'name'account.profile.top_placement._pagination'options: ['expose' => true])]
  157.     #[IsGranted('ROLE_ADVERTISER')]
  158.     public function topPlacement(
  159.          ProfileRepository $profileRepository,
  160.          DynamicPlacementPriceResolver $dynamicPlacementPriceResolver,
  161.          Request $requestParameterBagInterface $parameterBag): Response
  162.     {
  163.         /** @var User $user */
  164.         $user $this->getUser();
  165.         $result $profileRepository->ofOwnerPaged($user);
  166.         $profiles $this->takePage($result$parameterBag->get('advertiser.profiles.per_page'));
  167.         $topPlacementHourlyPrice $dynamicPlacementPriceResolver->resolveTopHourlyPrice($user, new \DateTimeImmutable('now'));
  168.         if($request->isXmlHttpRequest()) {
  169.             return $this->render('account/profile_top/top_placement.profiles.html.twig', [
  170.                 'profiles' => $profiles,
  171.             ]);
  172.         } else {
  173.             return $this->render('account/profile_top/top_placement.html.twig', [
  174.                 'profiles' => $profiles,
  175.                 'profile_top_placement_hourly_price' => $topPlacementHourlyPrice,
  176.             ]);
  177.         }
  178.     }
  179.     /**
  180.      * @deprecated ?
  181.      */
  182.     #[Route(path'/settings/profile-list/per-page/{count}/'name'account.settings.advertiser_profile_list_per_page')]
  183.     #[Route(path'/settings/saloon-list/per-page/{count}/'name'account.settings.advertiser_saloon_list_per_page')]
  184.     #[IsGranted('ROLE_ADVERTISER')]
  185.     public function settingsPerPage(int $countSessionInterface $sessionRequest $requestParameterBagInterface $parameterBag): Response
  186.     {
  187.         $route $request->attributes->get('_route');
  188.         $isProfileSetting = ("account.settings.advertiser_profile_list_per_page" == $route);
  189.         $variants $isProfileSetting
  190.             $parameterBag->get('account.setting.advertiser_profile_list_per_page.variants')
  191.             : $parameterBag->get('account.setting.advertiser_saloon_list_per_page.variants');
  192.         $variants explode(','$variants);
  193.         if(false === array_search($count$variants)) {
  194.             throw new \LogicException(sprintf('Count must be one of %s'implode(','$variants)));
  195.         }
  196.         $isProfileSetting
  197.            $session->set($parameterBag->get('account.setting.advertiser_profile_list_per_page.name'), $count)
  198.            : $session->set($parameterBag->get('account.setting.advertiser_saloon_list_per_page.name'), $count);
  199.         $referer $request->headers->get('referer');
  200.         return $referer $this->redirect($request->headers->get('referer')) : $this->redirectToRoute('account');
  201.     }
  202.     #[Route(path'/settings/profile-list/ctr-period/{period}/'name'account.settings.advertiser_profile_list_ctr_period')]
  203.     #[IsGranted('ROLE_ADVERTISER')]
  204.     public function settingsCtrPeriod(string $periodSessionInterface $sessionRequest $requestParameterBagInterface $parameterBagProfileCtrService $profileCtrService): Response
  205.     {
  206.         if(false === array_search($periodself::AVAILABLE_CTR_PERIODS)) {
  207.             throw new \LogicException(sprintf('Ctr period must be one of %s'implode(','self::AVAILABLE_CTR_PERIODS)));
  208.         }
  209.         $session->set($parameterBag->get('account.setting.advertiser_profile_list_ctr_period.name'), $period);
  210.         if($request->isXmlHttpRequest()) {
  211.             return $this->json([
  212.                 'success' => true,
  213.                 'profiles_ctr' => $profileCtrService->getCtrByOwner($this->getUser(), $period),
  214.                 'period' => $period,
  215.             ]);
  216.         } else {
  217.             $referer $request->headers->get('referer');
  218.             return $referer $this->redirect($request->headers->get('referer')) : $this->redirectToRoute('account');
  219.         }
  220.     }
  221.     
  222.     #[Route(path'/rules/'name'account.rules')]
  223.     public function rules(): Response
  224.     {
  225.         return $this->render('account/static/rules.html.twig');
  226.     }
  227.     #[Route(path'/charges/duration/'name'account.charges_duration'options: ['expose' => true])]
  228.     #[Security("is_granted('ROLE_ADVERTISER') or is_granted('ROLE_CUSTOMER')")]
  229.     public function chargesDuration(
  230.         AccountChargesDurationEstimator $accountChargesDurationEstimator,
  231.         AccountChargesDurationPresenter $accountChargesDurationPresenter
  232.     ): JsonResponse
  233.     {
  234.         $user $this->getUser();
  235.         if (!$user instanceof User) {
  236.             return $this->json(['success' => false'duration' => null], 401);
  237.         }
  238.         $estimate $accountChargesDurationEstimator->estimate($user);
  239.         return $this->json([
  240.             'success' => true,
  241.             'duration' => $accountChargesDurationPresenter->present($estimate),
  242.         ]);
  243.     }
  244.     #[Route(path'/hide-offer-bar/'name'account.offer_bar.hide')]
  245.     public function hideOfferBar(EntityManagerInterface $entityManager): Response
  246.     {
  247.         /** @var User $user */
  248.         $user $this->getUser();
  249.         $user->setOfferBarHidden();
  250.         $entityManager->flush();
  251.         return $this->json(['status' => 1]);
  252.     }
  253.     private function showDebugData(): bool
  254.     {
  255.         return $this->kernel->getEnvironment() == 'dev' || $this->kernel->getEnvironment() == 'review';
  256.     }
  257. }