public function testValidateNoErrors()
 {
     $this->context->expects($this->never())->method('addViolation');
     $email = new Email();
     $email->setTo(['*****@*****.**'])->setCc(['*****@*****.**'])->setBcc(['*****@*****.**']);
     $this->getValidator()->validate($email, $this->constraint);
 }
 /**
  * {@inheritdoc}
  */
 public function process(Email $model)
 {
     $issue_contexts = array_filter($model->getContexts(), function ($context) {
         return $context instanceof Issue;
     });
     /* @var $issue Issue */
     $issue = array_pop($issue_contexts);
     if ($this->request->getMethod() === 'GET') {
         $tos = $model->getTo();
         $tos[] = $issue->getReporter()->getEmail();
         $model->setTo($tos);
         $model->setSubject(sprintf('%s %s', $issue->getCode(), $issue->getSummary()));
     }
     parent::process($model);
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 protected function executeAction($context)
 {
     $type = 'txt';
     $emailModel = new Email();
     $emailModel->setFrom($this->getEmailAddress($context, $this->options['from']));
     $to = [];
     foreach ($this->options['to'] as $email) {
         if ($email) {
             $to[] = $this->getEmailAddress($context, $email);
         }
     }
     $emailModel->setTo($to);
     $emailModel->setSubject($this->contextAccessor->getValue($context, $this->options['subject']));
     $emailModel->setBody($this->contextAccessor->getValue($context, $this->options['body']));
     if (array_key_exists('type', $this->options) && in_array($this->options['type'], ['txt', 'html'], true)) {
         $type = $this->options['type'];
     }
     $emailModel->setType($type);
     $emailUser = $this->emailProcessor->process($emailModel);
     if (array_key_exists('attribute', $this->options)) {
         $this->contextAccessor->setValue($context, $this->options['attribute'], $emailUser->getEmail());
     }
 }
示例#4
0
 /**
  * @param EmailModel $emailModel
  */
 protected function applyRecipients(EmailModel $emailModel)
 {
     $emailModel->setTo(array_merge($emailModel->getTo(), $this->getRecipients($emailModel, EmailRecipient::TO, true)));
     $emailModel->setCc(array_merge($emailModel->getCc(), $this->getRecipients($emailModel, EmailRecipient::CC)));
     $emailModel->setBcc(array_merge($emailModel->getBcc(), $this->getRecipients($emailModel, EmailRecipient::BCC)));
 }
 /**
  * {@inheritdoc}
  */
 protected function executeAction($context)
 {
     $emailModel = new Email();
     $from = $this->getEmailAddress($context, $this->options['from']);
     $this->validateAddress($from);
     $emailModel->setFrom($from);
     $to = [];
     foreach ($this->options['to'] as $email) {
         if ($email) {
             $address = $this->getEmailAddress($context, $email);
             $this->validateAddress($address);
             $to[] = $this->getEmailAddress($context, $address);
         }
     }
     $emailModel->setTo($to);
     $entity = $this->contextAccessor->getValue($context, $this->options['entity']);
     $template = $this->contextAccessor->getValue($context, $this->options['template']);
     $emailTemplate = $this->objectManager->getRepository('OroEmailBundle:EmailTemplate')->findByName($template);
     if (!$emailTemplate) {
         $errorMessage = sprintf('Template "%s" not found.', $template);
         $this->logger->error('Workflow send email action.' . $errorMessage);
         throw new EntityNotFoundException($errorMessage);
     }
     $templateData = $this->renderer->compileMessage($emailTemplate, ['entity' => $entity]);
     $type = $emailTemplate->getType() == 'txt' ? 'text/plain' : 'text/html';
     list($subjectRendered, $templateRendered) = $templateData;
     $emailModel->setSubject($subjectRendered);
     $emailModel->setBody($templateRendered);
     $emailModel->setType($type);
     $emailUser = $this->emailProcessor->process($emailModel);
     if (array_key_exists('attribute', $this->options)) {
         $this->contextAccessor->setValue($context, $this->options['attribute'], $emailUser->getEmail());
     }
 }
 /**
  * Populate a model with initial data.
  * This method is used to load an initial data from a query string
  *
  * @param Email $model
  */
 protected function initModel(Email $model)
 {
     if ($this->request->query->has('gridName')) {
         $model->setGridName($this->request->query->get('gridName'));
     }
     if ($this->request->query->has('from')) {
         $from = $this->request->query->get('from');
         if (!empty($from)) {
             $this->preciseFullEmailAddress($from);
         }
         $model->setFrom($from);
     } else {
         $user = $this->getUser();
         if ($user) {
             $model->setFrom(EmailUtil::buildFullEmailAddress($user->getEmail(), $this->nameFormatter->format($user)));
         }
     }
     if ($this->request->query->has('to')) {
         $to = trim($this->request->query->get('to'));
         if (!empty($to)) {
             $this->preciseFullEmailAddress($to);
         }
         $model->setTo(array($to));
     }
     if ($this->request->query->has('subject')) {
         $subject = trim($this->request->query->get('subject'));
         $model->setSubject($subject);
     }
 }
示例#7
0
 /**
  * Populate a model with initial data.
  * This method is used to load an initial data from a query string
  *
  * @param Email $model
  */
 protected function initModel(Email $model)
 {
     if ($this->request->query->has('gridName')) {
         $model->setGridName($this->request->query->get('gridName'));
     }
     if ($this->request->query->has('entityClass')) {
         $model->setEntityClass($this->entityRoutingHelper->decodeClassName($this->request->query->get('entityClass')));
     }
     if ($this->request->query->has('entityId')) {
         $model->setEntityId($this->request->query->get('entityId'));
     }
     if ($this->request->query->has('from')) {
         $from = $this->request->query->get('from');
         if (!empty($from)) {
             $this->preciseFullEmailAddress($from);
         }
         $model->setFrom($from);
     } else {
         $user = $this->getUser();
         if ($user) {
             $model->setFrom($this->emailAddressHelper->buildFullEmailAddress($user->getEmail(), $this->nameFormatter->format($user)));
         }
     }
     if ($this->request->query->has('to')) {
         $to = trim($this->request->query->get('to'));
         if (!empty($to)) {
             $this->preciseFullEmailAddress($to, $model->getEntityClass(), $model->getEntityId());
         }
         $model->setTo(array($to));
     }
     if ($this->request->query->has('subject')) {
         $subject = trim($this->request->query->get('subject'));
         $model->setSubject($subject);
     }
 }
示例#8
0
 /**
  * {@inheritdoc}
  */
 protected function executeAction($context)
 {
     $emailModel = new Email();
     $emailModel->setFrom($this->getEmailAddress($context, $this->options['from']));
     $to = array();
     foreach ($this->options['to'] as $email) {
         if ($email) {
             $to[] = $this->getEmailAddress($context, $email);
         }
     }
     $emailModel->setTo($to);
     $emailModel->setSubject($this->contextAccessor->getValue($context, $this->options['subject']));
     $emailModel->setBody($this->contextAccessor->getValue($context, $this->options['body']));
     $email = $this->emailProcessor->process($emailModel);
     if (array_key_exists('attribute', $this->options)) {
         $this->contextAccessor->setValue($context, $this->options['attribute'], $email);
     }
 }