src/Controller/TinyKnightGames/ExplorerController.php line 84

  1. <?php
  2. namespace App\Controller\TinyKnightGames;
  3. use App\Entity\MarketItem;
  4. use App\Entity\MarketOffer;
  5. use App\Entity\NftCollection;
  6. use App\Entity\NftHub;
  7. use App\Entity\NftMetadata;
  8. use App\Entity\NftTransfer;
  9. use App\Entity\Template;
  10. use Doctrine\Persistence\ManagerRegistry;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. use WhiteOctober\BreadcrumbsBundle\Model\Breadcrumbs;
  16. class ExplorerController extends AbstractController
  17. {
  18.     public function __construct(private ManagerRegistry $doctrine) {}
  19.     #[Route('/explorer'name'explorer'requirements: ['domain' => 'tinyknightgames.com|tinyknightgames.wip|tkgstage.com'], host'{domain}')]
  20.     public function index(Breadcrumbs $breadcrumbs): Response
  21.     {
  22.         $em $this->doctrine->getManager();
  23.         // Example without URL
  24.         $breadcrumbs->addItem("Explorer");
  25.         $nftCollections $em->getRepository(NftCollection::class)->findAll();
  26.         // TODO: Show all NFT Collections on the main page
  27.         return $this->render('explorer/index.html.twig', [
  28.             'nftCollections' => $nftCollections
  29.         ]);
  30.     }
  31.     #[Route('/explorer/collection/{nftCollectionId}'name'explorer_collection_templates')]
  32.     public function showCollectionTemplates($nftCollectionIdBreadcrumbs $breadcrumbs): Response
  33.     {
  34.         $em $this->doctrine->getManager();
  35.         $nftCollection $em->getRepository(NftCollection::class)->findOneBy(array('id' => $nftCollectionId));
  36.         if($nftCollection->getId() === 5) { // 5 = Ancient Crate Series 1
  37.             $nftCollectionTemplates $em->getRepository(NftMetadata::class)->findAllByCollection($nftCollectionId);
  38.         } else {
  39.             $nftCollectionTemplates $em->getRepository(NftMetadata::class)->findDistinctByCollection($nftCollectionId);
  40.         }
  41.         // Breadcrumbs
  42.         $breadcrumbs->addRouteItem('Explorer''explorer', ['domain' => $this->getParameter('app.domain')]);
  43.         $breadcrumbs->addItem($nftCollection->getName() . " Series " $nftCollection->getSeries());
  44.         // TODO: Show all NFTs in selected Collection
  45.         return $this->render('explorer/collection.html.twig', [
  46.             'nftCollection' => $nftCollection,
  47.             'nftCollectionTemplates' => $nftCollectionTemplates
  48.         ]);
  49.     }
  50.     #[Route('/explorer/collection/{nftCollectionId}/template/{templateId}'name'explorer_collection_template_nfts')]
  51.     public function showCollectionTemplateNfts($nftCollectionId$templateIdBreadcrumbs $breadcrumbs): Response
  52.     {
  53.         $em $this->doctrine->getManager();
  54.         $nftCollection $em->getRepository(NftCollection::class)->findOneBy(array('id' => $nftCollectionId));
  55.         $template $em->getRepository(Template::class)->findOneBy(array('id' => $templateId));
  56.         $templateNfts $em->getRepository(NftMetadata::class)->findNftsByTemplate($nftCollectionId$templateId);
  57.         // Breadcrumbs
  58.         $breadcrumbs->addRouteItem("Explorer""explorer", ['domain' => $this->getParameter('app.domain')]);
  59.         $breadcrumbs->addRouteItem($nftCollection->getName() . " Series " $nftCollection->getSeries(), "explorer_collection_templates", ['nftCollectionId' => $nftCollectionId]);
  60.         $breadcrumbs->addItem($template->getName());
  61.         // TODO: Show all NFTs in selected Collection
  62.         return $this->render('explorer/collection-template-nfts.html.twig', [
  63.             'nftCollection' => $nftCollection,
  64.             'templateNfts' => $templateNfts
  65.         ]);
  66.     }
  67.     #[Route('/explorer/asset/{id}'name'explorer_asset_detail')]
  68.     public function assetDetail(Request $request$idBreadcrumbs $breadcrumbs): Response
  69.     {
  70.         $em $this->doctrine->getManager();
  71.         $assetHub $em->getRepository(NftHub::class)->findOneBy(array('id' => $id));
  72.         $assetMetadata $assetHub->getNftMetadata();
  73.         $assetTransferHistory $em->getRepository(NftTransfer::class)->findBy(array('nftHub' => $assetHub->getId()), array('id' => 'DESC''timestamp' => 'DESC'), 10);
  74.         $assetMarketHistory $em->getRepository(MarketItem::class)->findBy(array('nftHub' => $assetHub->getId(), 'isSold' => 1), array('updatedAt' => 'DESC'), 10);
  75.         $totalMinted $em->getRepository(NftMetadata::class)->getTotalMinted($assetMetadata->getTemplate()->getId(), $assetMetadata->getNftCollection()->getId());
  76. //        $marketItem = $em->getRepository(MarketItem::class)->findOneBy(array('nftHub' => $assetHub->getId(), 'isSold' => false));
  77. //        $marketOffers = $em->getRepository(MarketOffer::class)->findBy(array('nftHub' => $assetHub->getId(), 'isAccepted' => false));
  78.         $nftMinMaxStats $em->getRepository(NftMetadata::class)->getNftMinMaxStats($assetHub->getNftMetadata()->getTemplate());
  79.         // Breadcrumbs
  80.         $breadcrumbs->addRouteItem("Explorer""explorer", ['domain' => $this->getParameter('app.domain')]);
  81.         $breadcrumbs->addRouteItem($assetMetadata->getNftCollection()->getName() . " Series " $assetMetadata->getNftCollection()->getSeries(), "explorer_collection_templates", ['nftCollectionId' => $assetMetadata->getNftCollection()->getId()]);
  82.         $breadcrumbs->addRouteItem($assetMetadata->getTemplate()->getName(), "explorer_collection_template_nfts", ['nftCollectionId' => $assetMetadata->getNftCollection()->getId(), 'templateId' => $assetMetadata->getTemplate()->getId()]);
  83.         $breadcrumbs->addItem("Asset Details");
  84.         return $this->render('explorer/asset-detail.html.twig', [
  85.             'assetHub' => $assetHub,
  86.             'assetMetadata' => $assetMetadata,
  87.             'assetTransferHistory' => $assetTransferHistory,
  88.             'assetMarketHistory' => $assetMarketHistory,
  89.             'assetType' => 'catchable',
  90.             'totalMinted' => $totalMinted,
  91. //            'marketItem' => $marketItem,
  92. //            'marketOffers' => $marketOffers,
  93.             'nftMinMaxStats' => $nftMinMaxStats,
  94.         ]);
  95.         // TODO Redirect to custom 404
  96.         return $this->redirectToRoute('default');
  97.     }
  98. }