src/Bidcoz/Bundle/FrontendBundle/Controller/CampaignController.php line 34

Open in your IDE?
  1. <?php
  2. namespace Bidcoz\Bundle\FrontendBundle\Controller;
  3. use Bidcoz\Bundle\CoreBundle\Constants;
  4. use Bidcoz\Bundle\CoreBundle\Controller\CoreController;
  5. use Bidcoz\Bundle\CoreBundle\Entity\Auction\Auction;
  6. use Bidcoz\Bundle\CoreBundle\Entity\Auction\FundANeed;
  7. use Bidcoz\Bundle\CoreBundle\Entity\Auction\Shop;
  8. use Bidcoz\Bundle\CoreBundle\Entity\Campaign;
  9. use Bidcoz\Bundle\CoreBundle\Entity\Organization;
  10. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  11. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. # TODO: New authenticator behaves differently for @Security and @IsGranted
  15. # Issue: "Symfony\Component\Security\Core\Exception\AccessDeniedException: No user token or you forgot to put your controller behind a firewall while using a @Security tag
  16. # PR fixes this (still "Open"): https://github.com/sensiolabs/SensioFrameworkExtraBundle/pull/763
  17. # Docs: https://symfony.com/doc/5.2/security/experimental_authenticators.html#enabling-the-system
  18. # Notes: When PR gets merged, switch back to using the @Security tag: @Security("is_granted('VIEW', organization) and is_granted('FRONT_END', campaign)")
  19. /**
  20.  * @Route("/{orgSlug}/{campaignSlug}", requirements={"orgSlug" = Constants::RESERVED_SLUG_REGEX, "campaignSlug" = Constants::RESERVED_CAMPAIGN_SLUG_REGEX})
  21.  * @IsGranted("VIEW", subject="organization")
  22.  * @IsGranted("FRONT_END", subject="campaign")
  23.  */
  24. class CampaignController extends CoreController
  25. {
  26.     /**
  27.      * @Route("", name="campaign_home", methods={"GET"})
  28.      * @Route("/home", methods={"GET"})
  29.      */
  30.     public function indexAction(Organization $organizationCampaign $campaignAuction $auction nullShop $shop nullFundANeed $fund_a_need null)
  31.     {
  32.         $featuredItems $auction
  33.             $this->getRepository('Auction\Item')->findFeaturedItems($auction)
  34.             : [];
  35.         $shopItems $shop
  36.             $this->getRepository('Auction\Item')->findFeaturedItems($shop)
  37.             : [];
  38.         $fundANeedItems $fund_a_need
  39.             $this->getRepository('Auction\Item')->findFeaturedItems($fund_a_need)
  40.             : [];
  41.         // 2026 redesign: dispatch to a per-layout template based on the theme's
  42.         // themeName. Mirrors the template-side resolution in Layout/layout.html.twig
  43.         // (campaign theme first, then organization theme). 'centered-alt' (Boxed
  44.         // Width with Medium Logo) is an offered option that maps to the legacy
  45.         // index.html.twig. Legacy 'wide' (hidden from the picker) and any other
  46.         // unrecognized/null themeName fall back to Landing Page Hero, which most
  47.         // closely resembles the old banner layout, so existing campaigns keep
  48.         // working with a modern layout instead of the deprecated index.html.twig.
  49.         $theme $campaign->getTheme() ?: $organization->getTheme();
  50.         $themeName $theme $theme->getThemeName() : null;
  51.         $templatesByThemeName = [
  52.             'story-first'  => '@BidcozFrontend/Campaign/Templates/StoryFirst/index.html.twig',
  53.             'landing-hero' => '@BidcozFrontend/Campaign/Templates/LandingHero/index.html.twig',
  54.             'bold-split'   => '@BidcozFrontend/Campaign/Templates/BoldSplit/index.html.twig',
  55.             // Restored 4th picker option: renders the legacy boxed layout, not
  56.             // the Landing Page Hero fallback below.
  57.             'centered-alt' => '@BidcozFrontend/Campaign/index.html.twig',
  58.         ];
  59.         $template $templatesByThemeName[$themeName] ?? '@BidcozFrontend/Campaign/Templates/LandingHero/index.html.twig';
  60.         return $this->render($template, [
  61.             'organization'      => $organization,
  62.             'campaign'          => $campaign,
  63.             'auction'           => $auction,
  64.             'featuredItems'     => $featuredItems,
  65.             'shopItems'         => $shopItems,
  66.             'fundANeedItems'    => $fundANeedItems,
  67.         ]);
  68.     }
  69.     /**
  70.      * @Route("/details", name="campaign_details")
  71.      */
  72.     public function detailsAction(Organization $organizationCampaign $campaign)
  73.     {
  74.         return $this->render('@BidcozFrontend/Campaign/details.html.twig', [
  75.             'organization' => $organization,
  76.             'campaign'     => $campaign,
  77.         ]);
  78.     }
  79.     /**
  80.      * @Route("/rules", name="campaign_rules")
  81.      */
  82.     public function rulesAction(Organization $organizationCampaign $campaign)
  83.     {
  84.         $rules $this->getRepository('Rule')->findAll();
  85.         return $this->render('@BidcozFrontend/Campaign/rules.html.twig', [
  86.             'organization' => $organization,
  87.             'campaign'     => $campaign,
  88.             'rules'        => $rules,
  89.         ]);
  90.     }
  91.     /**
  92.      * @Route("/button/{component}", name="campaign_external_button")
  93.      */
  94.     public function buttonAction(Request $requestOrganization $organizationCampaign $campaign$component)
  95.     {
  96.         // If the button is for nvidia, set the host
  97.         if ('nvidia' === $organization->getSlug()) {
  98.             $context $this->getRouter()->getContext();
  99.             $context->setHost('nvidia.causepilot.com');
  100.         }
  101.         return $this->render('@BidcozFrontend/Campaign/Marketing/button.html.twig', [
  102.             'organization' => $organization,
  103.             'campaign'     => $campaign,
  104.             'component'    => $component,
  105.         ]);
  106.     }
  107.     /**
  108.      * @Route("/qr-code", name="campaign_external_qrcode")
  109.      */
  110.     public function qrCodeAction(Request $requestOrganization $organizationCampaign $campaign)
  111.     {
  112.         return $this->render('@BidcozFrontend/Campaign/Marketing/qrcode.html.twig', [
  113.             'organization' => $organization,
  114.             'campaign'     => $campaign,
  115.         ]);
  116.     }
  117. }