src/Bidcoz/Bundle/FrontendBundle/Controller/ContactUsController.php line 61

Open in your IDE?
  1. <?php
  2. namespace Bidcoz\Bundle\FrontendBundle\Controller;
  3. use Bidcoz\Bundle\CoreBundle\Controller\CoreController;
  4. use Bidcoz\Bundle\CoreBundle\Entity\Campaign;
  5. use Bidcoz\Bundle\CoreBundle\Entity\Organization;
  6. use Bidcoz\Bundle\FrontendBundle\Form\Type\ContactUsType;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. /**
  12.  * @Route("/{orgSlug}")
  13.  */
  14. class ContactUsController extends CoreController
  15. {
  16.     /**
  17.      * @Route("/contact", name="org_contact")
  18.      * @IsGranted("VIEW", subject="organization")
  19.      */
  20.     public function organizationAction(Request $requestOrganization $organization)
  21.     {
  22.         $form $this->getContactForm();
  23.         if (!$user $this->getUser()) {
  24.             $this->addFlash('danger''You must log in to contact the site admins');
  25.         }
  26.         if ('POST' === $request->getMethod()) {
  27.             $form->handleRequest($request);
  28.             if ($user && $form->isSubmitted() && $form->isValid()) {
  29.                 $data $form->getData();
  30.                 $this->getEmailManager()->sendEmailToAdmins($organization'contact-us', [
  31.                     'message'  => $data['message'],
  32.                     'fromUser' => $user,
  33.                 ]);
  34.                 $this->getEntityManager()->flush();
  35.                 $this->addFlash('success''Your message was sent');
  36.                 return $this->redirectToRoute('org_contact', [
  37.                     'orgSlug' => $organization->getSlug(),
  38.                 ]);
  39.             }
  40.         }
  41.         return $this->render('@BidcozFrontend/Contact/organization.html.twig', [
  42.             'organization' => $organization,
  43.             'form'         => $form->createView(),
  44.         ]);
  45.     }
  46.     /**
  47.      * @Route("/{campaignSlug}/contact", name="campaign_contact")
  48.      * @IsGranted("VIEW", subject="organization")
  49.      * @IsGranted("FRONT_END", subject="campaign")
  50.      */
  51.     public function campaignAction(Request $requestOrganization $organizationCampaign $campaign)
  52.     {
  53.         $form $this->getContactForm();
  54.         if (!$user $this->getUser()) {
  55.             $this->addFlash('danger''You must log in to contact the site admins');
  56.         }
  57.         if ('POST' === $request->getMethod()) {
  58.             $form->handleRequest($request);
  59.             if ($user && $form->isSubmitted() && $form->isValid()) {
  60.                 $data $form->getData();
  61.                 $this->getEmailManager()->sendEmailToAdmins($campaign'contact-us', [
  62.                     'message'  => $data['message'],
  63.                     'fromUser' => $user,
  64.                 ]);
  65.                 $this->getEntityManager()->flush();
  66.                 $this->addFlash('success''Your message was sent');
  67.                 return $this->redirectToRoute('campaign_contact', [
  68.                     'orgSlug'      => $organization->getSlug(),
  69.                     'campaignSlug' => $campaign->getSlug(),
  70.                 ]);
  71.             }
  72.         }
  73.         return $this->render('@BidcozFrontend/Contact/campaign.html.twig', [
  74.             'organization' => $organization,
  75.             'campaign'     => $campaign,
  76.             'form'         => $form->createView(),
  77.         ]);
  78.     }
  79.     protected function getContactForm()
  80.     {
  81.         return $this->createForm(ContactUsType::class);
  82.     }
  83. }