src/Controller/TinyKnightGames/UserProfileController.php line 160

  1. <?php
  2. namespace App\Controller\TinyKnightGames;
  3. use App\Entity\CrateActionLog;
  4. use App\Entity\Game;
  5. use App\Entity\MarketItem;
  6. use App\Entity\MarketOffer;
  7. use App\Entity\NftHub;
  8. use App\Entity\NftMetadata;
  9. use App\Entity\PlayerRank;
  10. use App\Entity\ThetaWallet;
  11. use App\Entity\User;
  12. use App\Entity\UserGear;
  13. use App\Entity\UserRecord;
  14. use App\Entity\WithdrawalLog;
  15. use App\Form\UserProfileType;
  16. use Doctrine\Persistence\ManagerRegistry;
  17. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\HttpFoundation\Response;
  20. use Symfony\Component\Routing\Annotation\Route;
  21. class UserProfileController extends AbstractController
  22. {
  23.     public function __construct(private ManagerRegistry $doctrine) {}
  24.     #[Route('/profile/settings'name'user_profile_settings'requirements: ['domain' => 'tinyknightgames.com|tinyknightgames.wip|tkgstage.com'], host'{domain}')]
  25.     public function getUserProfileSettings(Request $request): Response
  26.     {
  27.         $user $this->getUser();
  28.         $em $this->doctrine->getManager();
  29.         $form $this->createForm(UserProfileType::class, $user);
  30.         $form->handleRequest($request);
  31.         if ($form->isSubmitted() && $form->isValid()) {
  32.             $user->setUserName($form->get('username')->getData());
  33.             $em->persist($user);
  34.             $em->flush();
  35.         }
  36.         return $this->render('user_profile/settings.html.twig', [
  37.             'user' => $user,
  38.             'form' => $form->createView(),
  39.         ]);
  40.     }
  41.     #[Route('/profile/wallet/{walletAddress}'name'user_profile_wallet_address')]
  42.     public function getUserProfileByWalletAddress($walletAddress): Response
  43.     {
  44.         $em $this->doctrine->getManager();
  45.         $thetaWallet $em->getRepository(ThetaWallet::class)->findOneby(['address' => $walletAddress]);
  46.         if($thetaWallet !== null) {
  47.             $user $thetaWallet->getUser();
  48.             return $this->redirectToRoute('user_profile', [
  49.                 'userId' => $user->getId()
  50.             ]);
  51.         }
  52.         return new Response('Wallet Address not found.');
  53.     }
  54.     #[Route('/profile/{userId}'name'user_profile'requirements: ['domain' => 'tinyknightgames.com|tinyknightgames.wip|tkgstage.com'], host'{domain}')]
  55.     public function getUserProfile($userId): Response
  56.     {
  57.         $em $this->doctrine->getManager();
  58.         $user $em->getRepository(User::class)->findOneBy(array('id' => $userId));
  59.         $game $em->getRepository(Game::class)->findOneBy(['id' => 1]);
  60.         $userGear $em->getRepository(UserGear::class)->findBy(array('user' => $user));
  61.         $nftMetadatas $em->getRepository(NftMetadata::class)->findAllByUser($user, array('fish''equipment''chest''promotional'), $game);
  62.         $marketListings $em->getRepository(MarketItem::class)->findAllByUser($user$isSold false);
  63.         $userRecords $em->getRepository(UserRecord::class)->getAllRecordsByUser($user);
  64.         $currentRank $em->getRepository(PlayerRank::class)->findPlayerCurrentRank($user->getExperience());
  65.         return $this->render('user_profile/index.html.twig', [
  66.             'user' => $user,
  67.             'currentRank' => $currentRank,
  68.             'userGear' => $userGear,
  69.             'userRecords' => $userRecords,
  70.             'nftMetadatas' => $nftMetadatas,
  71.             'marketListings' => $marketListings,
  72.         ]);
  73.     }
  74.     #[Route('/profile/{userId}/crates'name'user_profile_crates'requirements: ['domain' => 'tinyknightgames.com|tinyknightgames.wip|tkgstage.com'], host'{domain}')]
  75.     public function getUserProfileCrates($userId): Response
  76.     {
  77.         $em $this->doctrine->getManager();
  78.         $user $em->getRepository(User::class)->findOneBy(array('id' => $userId));
  79.         $game $em->getRepository(Game::class)->findOneBy(['id' => 1]); // 1 = Universal
  80.         $userGear $em->getRepository(UserGear::class)->findBy(array('user' => $user));
  81.         $nftCrates $em->getRepository(NftMetadata::class)->findAllByUser($user, array('crate'), $game);
  82.         $marketListings $em->getRepository(MarketItem::class)->findAllByUser($user$isSold false);
  83.         $userRecords $em->getRepository(UserRecord::class)->getAllRecordsByUser($user);
  84.         $currentRank $em->getRepository(PlayerRank::class)->findPlayerCurrentRank($user->getExperience());
  85.         return $this->render('user_profile/crates.html.twig', [
  86.             'user' => $user,
  87.             'currentRank' => $currentRank,
  88.             'userGear' => $userGear,
  89.             'userRecords' => $userRecords,
  90.             'nftCrates' => $nftCrates,
  91.             'marketListings' => $marketListings,
  92.         ]);
  93.     }
  94.     #[Route('/profile/{userId}/opened-crates'name'user_profile_opened_crates'requirements: ['domain' => 'tinyknightgames.com|tinyknightgames.wip|tkgstage.com'], host'{domain}')]
  95.     public function getUserProfileOpenedCrates($userId): Response
  96.     {
  97.         $em $this->doctrine->getManager();
  98.         $user $em->getRepository(User::class)->findOneBy(array('id' => $userId));
  99.         $game $em->getRepository(Game::class)->findOneBy(['id' => 1]); // 1 = Universal
  100.         $userGear $em->getRepository(UserGear::class)->findBy(array('user' => $user));
  101.         $openedNftCrates $em->getRepository(CrateActionLog::class)->findOpenedByUser($user);
  102.         $marketListings $em->getRepository(MarketItem::class)->findAllByUser($user$isSold false);
  103.         $userRecords $em->getRepository(UserRecord::class)->getAllRecordsByUser($user);
  104.         $currentRank $em->getRepository(PlayerRank::class)->findPlayerCurrentRank($user->getExperience());
  105.         return $this->render('user_profile/opened-crates.html.twig', [
  106.             'user' => $user,
  107.             'currentRank' => $currentRank,
  108.             'userGear' => $userGear,
  109.             'userRecords' => $userRecords,
  110.             'openedNftCrates' => $openedNftCrates,
  111.             'marketListings' => $marketListings,
  112.         ]);
  113.     }
  114.     #[Route('/profile/{userId}/active-listings'name'user_active_listings')]
  115.     public function getActiveListings($userId): Response
  116.     {
  117.         $em $this->doctrine->getManager();
  118.         $user $em->getRepository(User::class)->findOneBy(array('id' => $userId));
  119.         $game $em->getRepository(Game::class)->findOneBy(['id' => 1]);
  120.         $userGear $em->getRepository(UserGear::class)->findBy(array('user' => $user));
  121.         $nftMetadatas $em->getRepository(NftMetadata::class)->findAllByUser($user, array('fish''equipment''chest''promotional'), $game);
  122.         $marketListings $em->getRepository(MarketItem::class)->findAllByUser($user$isSold false);
  123.         $userRecords $em->getRepository(UserRecord::class)->getAllRecordsByUser($user);
  124.         $currentRank $em->getRepository(PlayerRank::class)->findPlayerCurrentRank($user->getExperience());
  125.         return $this->render('user_profile/active-listings.html.twig', [
  126.             'user' => $user,
  127.             'currentRank' => $currentRank,
  128.             'userGear' => $userGear,
  129.             'userRecords' => $userRecords,
  130.             'nftMetadatas' => $nftMetadatas,
  131.             'marketListings' => $marketListings,
  132.         ]);
  133.     }
  134.     #[Route('/profile/{userId}/sold-listings'name'user_sold_listings')]
  135.     public function getSoldListings($userId): Response
  136.     {
  137.         $em $this->doctrine->getManager();
  138.         $user $em->getRepository(User::class)->findOneBy(array('id' => $userId));
  139.         $game $em->getRepository(Game::class)->findOneBy(['id' => 1]);
  140.         $userGear $em->getRepository(UserGear::class)->findBy(array('user' => $user));
  141.         $nftMetadatas $em->getRepository(NftMetadata::class)->findAllByUser($user, array('fish''equipment''chest''promotional'), $game);
  142.         $marketListings $em->getRepository(MarketItem::class)->findAllByUser($user$isSold true);
  143.         $userRecords $em->getRepository(UserRecord::class)->getAllRecordsByUser($user);
  144.         $currentRank $em->getRepository(PlayerRank::class)->findPlayerCurrentRank($user->getExperience());
  145.         return $this->render('user_profile/sold-listings.html.twig', [
  146.             'user' => $user,
  147.             'currentRank' => $currentRank,
  148.             'userGear' => $userGear,
  149.             'userRecords' => $userRecords,
  150.             'nftMetadatas' => $nftMetadatas,
  151.             'marketListings' => $marketListings,
  152.         ]);
  153.     }
  154.     #[Route('/profile/{userId}/purchased-listings'name'user_purchased_listings')]
  155.     public function getUserPurchasedListings($userId): Response
  156.     {
  157.         $em $this->doctrine->getManager();
  158.         $user $em->getRepository(User::class)->findOneBy(array('id' => $userId));
  159.         $game $em->getRepository(Game::class)->findOneBy(['id' => 1]);
  160.         $userGear $em->getRepository(UserGear::class)->findBy(array('user' => $user));
  161.         $nftMetadatas $em->getRepository(NftMetadata::class)->findAllByUser($user, array('fish''equipment''chest''promotional'), $game);
  162.         $marketListings $em->getRepository(MarketItem::class)->findUserPurchased($user);
  163.         $userRecords $em->getRepository(UserRecord::class)->getAllRecordsByUser($user);
  164.         $currentRank $em->getRepository(PlayerRank::class)->findPlayerCurrentRank($user->getExperience());
  165.         return $this->render('user_profile/purchased-listings.html.twig', [
  166.             'user' => $user,
  167.             'currentRank' => $currentRank,
  168.             'userGear' => $userGear,
  169.             'userRecords' => $userRecords,
  170.             'nftMetadatas' => $nftMetadatas,
  171.             'marketListings' => $marketListings,
  172.         ]);
  173.     }
  174.     #[Route('/user/records'name'user_records'requirements: ['domain' => 'tinyknightgames.com|tinyknightgames.wip|tkgstage.com'], host'{domain}')]
  175.     public function index(): Response
  176.     {
  177.         $user $this->getUser();
  178.         $em $this->doctrine->getManager();
  179.         $userRecordCatchables $em->getRepository(UserRecord::class)->findByUserSortTier($user);
  180.         return $this->render('user_records/index.html.twig', [
  181.             'userRecordCatchables' => $userRecordCatchables,
  182.         ]);
  183.     }
  184.     #[Route('/profile/{userId}/withdrawal-history'name'user_withdrawal_history')]
  185.     public function getUserWithdrawalHistory($userId): Response
  186.     {
  187.         $em $this->doctrine->getManager();
  188.         $user $em->getRepository(User::class)->findOneBy(array('id' => $userId));
  189.         $activeWallet $user->getActiveWallet();
  190.         $userGear $em->getRepository(UserGear::class)->findBy(array('user' => $user));
  191.         $withdrawalLog $em->getRepository(WithdrawalLog::class)->findBy(array('wallet' => $activeWallet), ['withdrawnAt' => 'DESC']);
  192. //        $nftMetadatas = $em->getRepository(NftMetadata::class)->findAllByUser($user, array('fish', 'equipment', 'chest', 'promotional'));
  193. //        $marketListings = $em->getRepository(MarketItem::class)->findAllByUser($user, $isSold = false);
  194.         $userRecords $em->getRepository(UserRecord::class)->getAllRecordsByUser($user);
  195.         $currentRank $em->getRepository(PlayerRank::class)->findPlayerCurrentRank($user->getExperience());
  196.         return $this->render('user_profile/withdrawal-history.html.twig', [
  197.             'user' => $user,
  198.             'currentRank' => $currentRank,
  199.             'withdrawalLog' => $withdrawalLog,
  200.             'userGear' => $userGear,
  201.             'userRecords' => $userRecords,
  202. //            'nftMetadatas' => $nftMetadatas,
  203. //            'marketListings' => $marketListings,
  204.         ]);
  205.     }
  206.     #[Route('/profile/{userId}/sent-offers'name'user_sent_offers')]
  207.     public function getUserActiveOffers($userId): Response
  208.     {
  209.         $em $this->doctrine->getManager();
  210.         $user $em->getRepository(User::class)->findOneBy(array('id' => $userId));
  211.         $activeWallet $user->getActiveWallet();
  212.         $userGear $em->getRepository(UserGear::class)->findBy(array('user' => $user));
  213.         $sentOffers $em->getRepository(MarketOffer::class)->findBy(array('bidder' => $activeWallet'isAccepted' => false));
  214.         $userRecords $em->getRepository(UserRecord::class)->getAllRecordsByUser($user);
  215.         $currentRank $em->getRepository(PlayerRank::class)->findPlayerCurrentRank($user->getExperience());
  216.         return $this->render('user_profile/sent-offers.html.twig', [
  217.             'user' => $user,
  218.             'currentRank' => $currentRank,
  219.             'sentOffers' => $sentOffers,
  220.             'userGear' => $userGear,
  221.             'userRecords' => $userRecords,
  222.         ]);
  223.     }
  224.     #[Route('/profile/{userId}/received-offers'name'user_received_offers')]
  225.     public function getUserReceivedOffers($userId): Response
  226.     {
  227.         $em $this->doctrine->getManager();
  228.         $user $em->getRepository(User::class)->findOneBy(array('id' => $userId));
  229.         $activeWallet $user->getActiveWallet();
  230.         $userGear $em->getRepository(UserGear::class)->findBy(array('user' => $user));
  231.         $receivedOffers $em->getRepository(NftMetadata::class)->findByUserWithOffer($activeWallet);
  232.         $userRecords $em->getRepository(UserRecord::class)->getAllRecordsByUser($user);
  233.         $currentRank $em->getRepository(PlayerRank::class)->findPlayerCurrentRank($user->getExperience());
  234.         return $this->render('user_profile/received-offers.html.twig', [
  235.             'user' => $user,
  236.             'currentRank' => $currentRank,
  237.             'receivedOffers' => $receivedOffers,
  238.             'userGear' => $userGear,
  239.             'userRecords' => $userRecords,
  240.         ]);
  241.     }
  242.     #[Route('/profile/{userId}/accepted-offers'name'user_accepted_offers')]
  243.     public function getUserAcceptedOffers($userId): Response
  244.     {
  245.         $em $this->doctrine->getManager();
  246.         $user $em->getRepository(User::class)->findOneBy(array('id' => $userId));
  247.         $activeWallet $user->getActiveWallet();
  248.         $userGear $em->getRepository(UserGear::class)->findBy(array('user' => $user));
  249.         $acceptedOffers $em->getRepository(MarketOffer::class)->findBy(array('bidder' => $activeWallet'isAccepted' => false));
  250.         $userRecords $em->getRepository(UserRecord::class)->getAllRecordsByUser($user);
  251.         $currentRank $em->getRepository(PlayerRank::class)->findPlayerCurrentRank($user->getExperience());
  252.         return $this->render('user_profile/active-offers.html.twig', [
  253.             'user' => $user,
  254.             'currentRank' => $currentRank,
  255.             'acceptedOffers' => $acceptedOffers,
  256.             'userGear' => $userGear,
  257.             'userRecords' => $userRecords,
  258.         ]);
  259.     }
  260. }