src/Controller/Account/AccountController.php line 74

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