src/Controller/Account/AccountController.php line 187

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