src/Controller/TinyKnightGames/ExplorerController.php line 24
<?php
namespace App\Controller\TinyKnightGames;
use App\Entity\MarketItem;
use App\Entity\MarketOffer;
use App\Entity\NftCollection;
use App\Entity\NftHub;
use App\Entity\NftMetadata;
use App\Entity\NftTransfer;
use App\Entity\Template;
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;
use WhiteOctober\BreadcrumbsBundle\Model\Breadcrumbs;
class ExplorerController extends AbstractController
{
public function __construct(private ManagerRegistry $doctrine) {}
#[Route('/explorer', name: 'explorer', requirements: ['domain' => 'tinyknightgames.com|tinyknightgames.wip|tkgstage.com'], host: '{domain}')]
public function index(Breadcrumbs $breadcrumbs): Response
{
$em = $this->doctrine->getManager();
// Example without URL
$breadcrumbs->addItem("Explorer");
$nftCollections = $em->getRepository(NftCollection::class)->findAll();
// TODO: Show all NFT Collections on the main page
return $this->render('explorer/index.html.twig', [
'nftCollections' => $nftCollections
]);
}
#[Route('/explorer/collection/{nftCollectionId}', name: 'explorer_collection_templates')]
public function showCollectionTemplates($nftCollectionId, Breadcrumbs $breadcrumbs): Response
{
$em = $this->doctrine->getManager();
$nftCollection = $em->getRepository(NftCollection::class)->findOneBy(array('id' => $nftCollectionId));
if($nftCollection->getId() === 5) { // 5 = Ancient Crate Series 1
$nftCollectionTemplates = $em->getRepository(NftMetadata::class)->findAllByCollection($nftCollectionId);
} else {
$nftCollectionTemplates = $em->getRepository(NftMetadata::class)->findDistinctByCollection($nftCollectionId);
}
// Breadcrumbs
$breadcrumbs->addRouteItem('Explorer', 'explorer', ['domain' => $this->getParameter('app.domain')]);
$breadcrumbs->addItem($nftCollection->getName() . " Series " . $nftCollection->getSeries());
// TODO: Show all NFTs in selected Collection
return $this->render('explorer/collection.html.twig', [
'nftCollection' => $nftCollection,
'nftCollectionTemplates' => $nftCollectionTemplates
]);
}
#[Route('/explorer/collection/{nftCollectionId}/template/{templateId}', name: 'explorer_collection_template_nfts')]
public function showCollectionTemplateNfts($nftCollectionId, $templateId, Breadcrumbs $breadcrumbs): Response
{
$em = $this->doctrine->getManager();
$nftCollection = $em->getRepository(NftCollection::class)->findOneBy(array('id' => $nftCollectionId));
$template = $em->getRepository(Template::class)->findOneBy(array('id' => $templateId));
$templateNfts = $em->getRepository(NftMetadata::class)->findNftsByTemplate($nftCollectionId, $templateId);
// Breadcrumbs
$breadcrumbs->addRouteItem("Explorer", "explorer", ['domain' => $this->getParameter('app.domain')]);
$breadcrumbs->addRouteItem($nftCollection->getName() . " Series " . $nftCollection->getSeries(), "explorer_collection_templates", ['nftCollectionId' => $nftCollectionId]);
$breadcrumbs->addItem($template->getName());
// TODO: Show all NFTs in selected Collection
return $this->render('explorer/collection-template-nfts.html.twig', [
'nftCollection' => $nftCollection,
'templateNfts' => $templateNfts
]);
}
#[Route('/explorer/asset/{id}', name: 'explorer_asset_detail')]
public function assetDetail(Request $request, $id, Breadcrumbs $breadcrumbs): Response
{
$em = $this->doctrine->getManager();
$assetHub = $em->getRepository(NftHub::class)->findOneBy(array('id' => $id));
$assetMetadata = $assetHub->getNftMetadata();
$assetTransferHistory = $em->getRepository(NftTransfer::class)->findBy(array('nftHub' => $assetHub->getId()), array('id' => 'DESC', 'timestamp' => 'DESC'), 10);
$assetMarketHistory = $em->getRepository(MarketItem::class)->findBy(array('nftHub' => $assetHub->getId(), 'isSold' => 1), array('updatedAt' => 'DESC'), 10);
$totalMinted = $em->getRepository(NftMetadata::class)->getTotalMinted($assetMetadata->getTemplate()->getId(), $assetMetadata->getNftCollection()->getId());
// $marketItem = $em->getRepository(MarketItem::class)->findOneBy(array('nftHub' => $assetHub->getId(), 'isSold' => false));
// $marketOffers = $em->getRepository(MarketOffer::class)->findBy(array('nftHub' => $assetHub->getId(), 'isAccepted' => false));
$nftMinMaxStats = $em->getRepository(NftMetadata::class)->getNftMinMaxStats($assetHub->getNftMetadata()->getTemplate());
// Breadcrumbs
$breadcrumbs->addRouteItem("Explorer", "explorer", ['domain' => $this->getParameter('app.domain')]);
$breadcrumbs->addRouteItem($assetMetadata->getNftCollection()->getName() . " Series " . $assetMetadata->getNftCollection()->getSeries(), "explorer_collection_templates", ['nftCollectionId' => $assetMetadata->getNftCollection()->getId()]);
$breadcrumbs->addRouteItem($assetMetadata->getTemplate()->getName(), "explorer_collection_template_nfts", ['nftCollectionId' => $assetMetadata->getNftCollection()->getId(), 'templateId' => $assetMetadata->getTemplate()->getId()]);
$breadcrumbs->addItem("Asset Details");
return $this->render('explorer/asset-detail.html.twig', [
'assetHub' => $assetHub,
'assetMetadata' => $assetMetadata,
'assetTransferHistory' => $assetTransferHistory,
'assetMarketHistory' => $assetMarketHistory,
'assetType' => 'catchable',
'totalMinted' => $totalMinted,
// 'marketItem' => $marketItem,
// 'marketOffers' => $marketOffers,
'nftMinMaxStats' => $nftMinMaxStats,
]);
// TODO Redirect to custom 404
return $this->redirectToRoute('default');
}
}