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.         return $this->render('@BidcozFrontend/Campaign/index.html.twig', [
  42.             'organization'      => $organization,
  43.             'campaign'          => $campaign,
  44.             'auction'           => $auction,
  45.             'featuredItems'     => $featuredItems,
  46.             'shopItems'         => $shopItems,
  47.             'fundANeedItems'    => $fundANeedItems,
  48.         ]);
  49.     }
  50.     /**
  51.      * @Route("/details", name="campaign_details")
  52.      */
  53.     public function detailsAction(Organization $organizationCampaign $campaign)
  54.     {
  55.         return $this->render('@BidcozFrontend/Campaign/details.html.twig', [
  56.             'organization' => $organization,
  57.             'campaign'     => $campaign,
  58.         ]);
  59.     }
  60.     /**
  61.      * @Route("/rules", name="campaign_rules")
  62.      */
  63.     public function rulesAction(Organization $organizationCampaign $campaign)
  64.     {
  65.         $rules $this->getRepository('Rule')->findAll();
  66.         return $this->render('@BidcozFrontend/Campaign/rules.html.twig', [
  67.             'organization' => $organization,
  68.             'campaign'     => $campaign,
  69.             'rules'        => $rules,
  70.         ]);
  71.     }
  72.     /**
  73.      * @Route("/button/{component}", name="campaign_external_button")
  74.      */
  75.     public function buttonAction(Request $requestOrganization $organizationCampaign $campaign$component)
  76.     {
  77.         // If the button is for nvidia, set the host
  78.         if ('nvidia' === $organization->getSlug()) {
  79.             $context $this->getRouter()->getContext();
  80.             $context->setHost('nvidia.causepilot.com');
  81.         }
  82.         return $this->render('@BidcozFrontend/Campaign/Marketing/button.html.twig', [
  83.             'organization' => $organization,
  84.             'campaign'     => $campaign,
  85.             'component'    => $component,
  86.         ]);
  87.     }
  88.     /**
  89.      * @Route("/qr-code", name="campaign_external_qrcode")
  90.      */
  91.     public function qrCodeAction(Request $requestOrganization $organizationCampaign $campaign)
  92.     {
  93.         return $this->render('@BidcozFrontend/Campaign/Marketing/qrcode.html.twig', [
  94.             'organization' => $organization,
  95.             'campaign'     => $campaign,
  96.         ]);
  97.     }
  98. }