/** * @Secure(roles={"ROLE_CA"}) */ public function sendTestAction(CampaignMailing $campaign) { $form = $this->createForm('enigmatic_crm_campaign_mailing_test', array('email' => $this->get('security.token_storage')->getToken()->getUser()->getEmail())); $form->handleRequest($this->get('request')); if ($form->isSubmitted() && $form->isValid()) { $data = $form->getData(); $mail = $this->get('enigmatic_mailer'); $i = 1; if (count($campaign->getFiles())) { foreach ($campaign->getFiles() as $file) { $mail->addAttach($file->getAbsolutePath(), 'pj' . $i . '.' . substr(strrchr($file->getPath(), '.'), 1)); $i++; } } $mail->sendMail($data['email'], $this->renderView('EnigmaticCRMBundle:CampaignMailing:Email/mailing.html.twig', array('subject' => $campaign->getEmailSubject(), 'content' => $campaign->getEmailBody()))); $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('enigmatic.crm.campaign_mailing.message.send_test')); return $this->redirect($this->generateUrl('enigmatic_crm_campaign_mailing_view', array('campaign' => $campaign->getId()))); } return $this->get('enigmatic.render')->render($this->renderView('EnigmaticCRMBundle:CampaignMailing:sendTest.html.twig', array('campaign' => $campaign, 'form' => $form->createView()))); }
public function grantCampaignMailing(CampaignMailing $campaignMailing) { $grant = false; if ($this->authorizationChecker->isGranted('ROLE_RS')) { $grant = true; } elseif ($this->authorizationChecker->isGranted('ROLE_RCA')) { $agency = $this->userManager->getCurrent()->getAgency(); foreach ($campaignMailing->getOwner()->getAgencies() as $histoAgence) { if ($agency == $histoAgence->getAgency()) { if ($histoAgence->getDateCreated() <= $campaignMailing->getDateCreated()) { if ($histoAgence->getEnd()) { if ($histoAgence->getEnd()->getDateEnd() > $campaignMailing->getDateCreated()) { $grant = true; } } else { $grant = true; } } } } } elseif ($this->authorizationChecker->isGranted('ROLE_CA')) { $agency = $this->userManager->getCurrent()->getAgency(); foreach ($campaignMailing->getOwner()->getAgencies() as $histoAgence) { if ($agency == $histoAgence->getAgency()) { if ($histoAgence->getDateCreated() <= $campaignMailing->getDateCreated()) { if ($histoAgence->getEnd() == null) { $grant = true; } } } } if ($grant) { $grant = false; if ($campaignMailing->getOwner() == $this->userManager->getCurrent()) { $grant = true; } } } return $grant; }