src/Controller/TinyKnightGames/UserProfileController.php line 245
<?php
namespace App\Controller\TinyKnightGames;
use App\Entity\CrateActionLog;
use App\Entity\Game;
use App\Entity\MarketItem;
use App\Entity\MarketOffer;
use App\Entity\NftHub;
use App\Entity\NftMetadata;
use App\Entity\PlayerRank;
use App\Entity\ThetaWallet;
use App\Entity\User;
use App\Entity\UserGear;
use App\Entity\UserRecord;
use App\Entity\WithdrawalLog;
use App\Form\UserProfileType;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class UserProfileController extends AbstractController
{
public function __construct(private ManagerRegistry $doctrine) {}
#[Route('/profile/settings', name: 'user_profile_settings', requirements: ['domain' => 'tinyknightgames.com|tinyknightgames.wip|tkgstage.com'], host: '{domain}')]
public function getUserProfileSettings(Request $request): Response
{
$user = $this->getUser();
$em = $this->doctrine->getManager();
$form = $this->createForm(UserProfileType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$user->setUserName($form->get('username')->getData());
$em->persist($user);
$em->flush();
}
return $this->render('user_profile/settings.html.twig', [
'user' => $user,
'form' => $form->createView(),
]);
}
#[Route('/profile/wallet/{walletAddress}', name: 'user_profile_wallet_address')]
public function getUserProfileByWalletAddress($walletAddress): Response
{
$em = $this->doctrine->getManager();
$thetaWallet = $em->getRepository(ThetaWallet::class)->findOneby(['address' => $walletAddress]);
if($thetaWallet !== null) {
$user = $thetaWallet->getUser();
return $this->redirectToRoute('user_profile', [
'userId' => $user->getId()
]);
}
return new Response('Wallet Address not found.');
}
#[Route('/profile/{userId}', name: 'user_profile', requirements: ['domain' => 'tinyknightgames.com|tinyknightgames.wip|tkgstage.com'], host: '{domain}')]
public function getUserProfile($userId): Response
{
$em = $this->doctrine->getManager();
$user = $em->getRepository(User::class)->findOneBy(array('id' => $userId));
$game = $em->getRepository(Game::class)->findOneBy(['id' => 1]);
$userGear = $em->getRepository(UserGear::class)->findBy(array('user' => $user));
$nftMetadatas = $em->getRepository(NftMetadata::class)->findAllByUser($user, array('fish', 'equipment', 'chest', 'promotional'), $game);
$marketListings = $em->getRepository(MarketItem::class)->findAllByUser($user, $isSold = false);
$userRecords = $em->getRepository(UserRecord::class)->getAllRecordsByUser($user);
$currentRank = $em->getRepository(PlayerRank::class)->findPlayerCurrentRank($user->getExperience());
return $this->render('user_profile/index.html.twig', [
'user' => $user,
'currentRank' => $currentRank,
'userGear' => $userGear,
'userRecords' => $userRecords,
'nftMetadatas' => $nftMetadatas,
'marketListings' => $marketListings,
]);
}
#[Route('/profile/{userId}/crates', name: 'user_profile_crates', requirements: ['domain' => 'tinyknightgames.com|tinyknightgames.wip|tkgstage.com'], host: '{domain}')]
public function getUserProfileCrates($userId): Response
{
$em = $this->doctrine->getManager();
$user = $em->getRepository(User::class)->findOneBy(array('id' => $userId));
$game = $em->getRepository(Game::class)->findOneBy(['id' => 1]); // 1 = Universal
$userGear = $em->getRepository(UserGear::class)->findBy(array('user' => $user));
$nftCrates = $em->getRepository(NftMetadata::class)->findAllByUser($user, array('crate'), $game);
$marketListings = $em->getRepository(MarketItem::class)->findAllByUser($user, $isSold = false);
$userRecords = $em->getRepository(UserRecord::class)->getAllRecordsByUser($user);
$currentRank = $em->getRepository(PlayerRank::class)->findPlayerCurrentRank($user->getExperience());
return $this->render('user_profile/crates.html.twig', [
'user' => $user,
'currentRank' => $currentRank,
'userGear' => $userGear,
'userRecords' => $userRecords,
'nftCrates' => $nftCrates,
'marketListings' => $marketListings,
]);
}
#[Route('/profile/{userId}/opened-crates', name: 'user_profile_opened_crates', requirements: ['domain' => 'tinyknightgames.com|tinyknightgames.wip|tkgstage.com'], host: '{domain}')]
public function getUserProfileOpenedCrates($userId): Response
{
$em = $this->doctrine->getManager();
$user = $em->getRepository(User::class)->findOneBy(array('id' => $userId));
$game = $em->getRepository(Game::class)->findOneBy(['id' => 1]); // 1 = Universal
$userGear = $em->getRepository(UserGear::class)->findBy(array('user' => $user));
$openedNftCrates = $em->getRepository(CrateActionLog::class)->findOpenedByUser($user);
$marketListings = $em->getRepository(MarketItem::class)->findAllByUser($user, $isSold = false);
$userRecords = $em->getRepository(UserRecord::class)->getAllRecordsByUser($user);
$currentRank = $em->getRepository(PlayerRank::class)->findPlayerCurrentRank($user->getExperience());
return $this->render('user_profile/opened-crates.html.twig', [
'user' => $user,
'currentRank' => $currentRank,
'userGear' => $userGear,
'userRecords' => $userRecords,
'openedNftCrates' => $openedNftCrates,
'marketListings' => $marketListings,
]);
}
#[Route('/profile/{userId}/active-listings', name: 'user_active_listings')]
public function getActiveListings($userId): Response
{
$em = $this->doctrine->getManager();
$user = $em->getRepository(User::class)->findOneBy(array('id' => $userId));
$game = $em->getRepository(Game::class)->findOneBy(['id' => 1]);
$userGear = $em->getRepository(UserGear::class)->findBy(array('user' => $user));
$nftMetadatas = $em->getRepository(NftMetadata::class)->findAllByUser($user, array('fish', 'equipment', 'chest', 'promotional'), $game);
$marketListings = $em->getRepository(MarketItem::class)->findAllByUser($user, $isSold = false);
$userRecords = $em->getRepository(UserRecord::class)->getAllRecordsByUser($user);
$currentRank = $em->getRepository(PlayerRank::class)->findPlayerCurrentRank($user->getExperience());
return $this->render('user_profile/active-listings.html.twig', [
'user' => $user,
'currentRank' => $currentRank,
'userGear' => $userGear,
'userRecords' => $userRecords,
'nftMetadatas' => $nftMetadatas,
'marketListings' => $marketListings,
]);
}
#[Route('/profile/{userId}/sold-listings', name: 'user_sold_listings')]
public function getSoldListings($userId): Response
{
$em = $this->doctrine->getManager();
$user = $em->getRepository(User::class)->findOneBy(array('id' => $userId));
$game = $em->getRepository(Game::class)->findOneBy(['id' => 1]);
$userGear = $em->getRepository(UserGear::class)->findBy(array('user' => $user));
$nftMetadatas = $em->getRepository(NftMetadata::class)->findAllByUser($user, array('fish', 'equipment', 'chest', 'promotional'), $game);
$marketListings = $em->getRepository(MarketItem::class)->findAllByUser($user, $isSold = true);
$userRecords = $em->getRepository(UserRecord::class)->getAllRecordsByUser($user);
$currentRank = $em->getRepository(PlayerRank::class)->findPlayerCurrentRank($user->getExperience());
return $this->render('user_profile/sold-listings.html.twig', [
'user' => $user,
'currentRank' => $currentRank,
'userGear' => $userGear,
'userRecords' => $userRecords,
'nftMetadatas' => $nftMetadatas,
'marketListings' => $marketListings,
]);
}
#[Route('/profile/{userId}/purchased-listings', name: 'user_purchased_listings')]
public function getUserPurchasedListings($userId): Response
{
$em = $this->doctrine->getManager();
$user = $em->getRepository(User::class)->findOneBy(array('id' => $userId));
$game = $em->getRepository(Game::class)->findOneBy(['id' => 1]);
$userGear = $em->getRepository(UserGear::class)->findBy(array('user' => $user));
$nftMetadatas = $em->getRepository(NftMetadata::class)->findAllByUser($user, array('fish', 'equipment', 'chest', 'promotional'), $game);
$marketListings = $em->getRepository(MarketItem::class)->findUserPurchased($user);
$userRecords = $em->getRepository(UserRecord::class)->getAllRecordsByUser($user);
$currentRank = $em->getRepository(PlayerRank::class)->findPlayerCurrentRank($user->getExperience());
return $this->render('user_profile/purchased-listings.html.twig', [
'user' => $user,
'currentRank' => $currentRank,
'userGear' => $userGear,
'userRecords' => $userRecords,
'nftMetadatas' => $nftMetadatas,
'marketListings' => $marketListings,
]);
}
#[Route('/user/records', name: 'user_records', requirements: ['domain' => 'tinyknightgames.com|tinyknightgames.wip|tkgstage.com'], host: '{domain}')]
public function index(): Response
{
$user = $this->getUser();
$em = $this->doctrine->getManager();
$userRecordCatchables = $em->getRepository(UserRecord::class)->findByUserSortTier($user);
return $this->render('user_records/index.html.twig', [
'userRecordCatchables' => $userRecordCatchables,
]);
}
#[Route('/profile/{userId}/withdrawal-history', name: 'user_withdrawal_history')]
public function getUserWithdrawalHistory($userId): Response
{
$em = $this->doctrine->getManager();
$user = $em->getRepository(User::class)->findOneBy(array('id' => $userId));
$activeWallet = $user->getActiveWallet();
$userGear = $em->getRepository(UserGear::class)->findBy(array('user' => $user));
$withdrawalLog = $em->getRepository(WithdrawalLog::class)->findBy(array('wallet' => $activeWallet), ['withdrawnAt' => 'DESC']);
// $nftMetadatas = $em->getRepository(NftMetadata::class)->findAllByUser($user, array('fish', 'equipment', 'chest', 'promotional'));
// $marketListings = $em->getRepository(MarketItem::class)->findAllByUser($user, $isSold = false);
$userRecords = $em->getRepository(UserRecord::class)->getAllRecordsByUser($user);
$currentRank = $em->getRepository(PlayerRank::class)->findPlayerCurrentRank($user->getExperience());
return $this->render('user_profile/withdrawal-history.html.twig', [
'user' => $user,
'currentRank' => $currentRank,
'withdrawalLog' => $withdrawalLog,
'userGear' => $userGear,
'userRecords' => $userRecords,
// 'nftMetadatas' => $nftMetadatas,
// 'marketListings' => $marketListings,
]);
}
#[Route('/profile/{userId}/sent-offers', name: 'user_sent_offers')]
public function getUserActiveOffers($userId): Response
{
$em = $this->doctrine->getManager();
$user = $em->getRepository(User::class)->findOneBy(array('id' => $userId));
$activeWallet = $user->getActiveWallet();
$userGear = $em->getRepository(UserGear::class)->findBy(array('user' => $user));
$sentOffers = $em->getRepository(MarketOffer::class)->findBy(array('bidder' => $activeWallet, 'isAccepted' => false));
$userRecords = $em->getRepository(UserRecord::class)->getAllRecordsByUser($user);
$currentRank = $em->getRepository(PlayerRank::class)->findPlayerCurrentRank($user->getExperience());
return $this->render('user_profile/sent-offers.html.twig', [
'user' => $user,
'currentRank' => $currentRank,
'sentOffers' => $sentOffers,
'userGear' => $userGear,
'userRecords' => $userRecords,
]);
}
#[Route('/profile/{userId}/received-offers', name: 'user_received_offers')]
public function getUserReceivedOffers($userId): Response
{
$em = $this->doctrine->getManager();
$user = $em->getRepository(User::class)->findOneBy(array('id' => $userId));
$activeWallet = $user->getActiveWallet();
$userGear = $em->getRepository(UserGear::class)->findBy(array('user' => $user));
$receivedOffers = $em->getRepository(NftMetadata::class)->findByUserWithOffer($activeWallet);
$userRecords = $em->getRepository(UserRecord::class)->getAllRecordsByUser($user);
$currentRank = $em->getRepository(PlayerRank::class)->findPlayerCurrentRank($user->getExperience());
return $this->render('user_profile/received-offers.html.twig', [
'user' => $user,
'currentRank' => $currentRank,
'receivedOffers' => $receivedOffers,
'userGear' => $userGear,
'userRecords' => $userRecords,
]);
}
#[Route('/profile/{userId}/accepted-offers', name: 'user_accepted_offers')]
public function getUserAcceptedOffers($userId): Response
{
$em = $this->doctrine->getManager();
$user = $em->getRepository(User::class)->findOneBy(array('id' => $userId));
$activeWallet = $user->getActiveWallet();
$userGear = $em->getRepository(UserGear::class)->findBy(array('user' => $user));
$acceptedOffers = $em->getRepository(MarketOffer::class)->findBy(array('bidder' => $activeWallet, 'isAccepted' => false));
$userRecords = $em->getRepository(UserRecord::class)->getAllRecordsByUser($user);
$currentRank = $em->getRepository(PlayerRank::class)->findPlayerCurrentRank($user->getExperience());
return $this->render('user_profile/active-offers.html.twig', [
'user' => $user,
'currentRank' => $currentRank,
'acceptedOffers' => $acceptedOffers,
'userGear' => $userGear,
'userRecords' => $userRecords,
]);
}
}