コード例 #1
0
ファイル: EmailModel.php プロジェクト: smotalima/mautic
 /**
  * Send an email to lead(s)
  *
  * @param       $email
  * @param       $users
  * @param mixed $lead
  * @param array $tokens
  * @param array $assetAttachments
  * @param bool  $saveStat
  *
  * @return mixed
  * @throws \Doctrine\ORM\ORMException
  */
 public function sendEmailToUser($email, $users, $lead = null, $tokens = array(), $assetAttachments = array(), $saveStat = true)
 {
     if (!($emailId = $email->getId())) {
         return false;
     }
     if (!is_array($users)) {
         $user = array('id' => $users);
         $users = array($user);
     }
     //get email settings
     $emailSettings = $this->getEmailSettings($email, false);
     //noone to send to so bail
     if (empty($users)) {
         return false;
     }
     $mailer = $this->factory->getMailer();
     $mailer->setLead($lead, true);
     $mailer->setTokens($tokens);
     $mailer->setEmail($email, false, $emailSettings[$emailId]['slots'], $assetAttachments, !$saveStat);
     $mailer->useMailerTokenization();
     foreach ($users as $user) {
         $idHash = uniqid();
         $mailer->setIdHash($idHash);
         if (!is_array($user)) {
             $id = $user;
             $user = array('id' => $id);
         } else {
             $id = $user['id'];
         }
         if (!isset($user['email'])) {
             /** @var \Mautic\UserBundle\Model\UserModel $model */
             $userModel = $this->factory->getModel('user');
             $userEntity = $userModel->getEntity($id);
             $user['email'] = $userEntity->getEmail();
             $user['firstname'] = $userEntity->getFirstName();
             $user['lastname'] = $userEntity->getLastName();
         }
         $mailer->setTo($user['email'], $user['firstname'] . ' ' . $user['lastname']);
         $mailer->queue(true);
         if ($saveStat) {
             //create a stat
             $stat = new Stat();
             $stat->setDateSent(new \DateTime());
             $stat->setEmailAddress($user['email']);
             $stat->setTrackingHash($idHash);
             if (!empty($source)) {
                 $stat->setSource($source[0]);
                 $stat->setSourceId($source[1]);
             }
             $stat->setCopy($mailer->getBody());
             $stat->setTokens($mailer->getTokens());
             $saveEntities[] = $stat;
         }
     }
     //flush the message
     $mailer->flushQueue();
     if (isset($saveEntities)) {
         $this->getStatRepository()->saveEntities($saveEntities);
     }
     //save some memory
     unset($mailer);
 }
コード例 #2
0
ファイル: MailHelper.php プロジェクト: Jandersolutions/mautic
 /**
  * Create an email stat
  */
 public function createLeadEmailStat()
 {
     if (!$this->lead) {
         return;
     }
     //create a stat
     $stat = new Stat();
     $stat->setDateSent(new \DateTime());
     $stat->setEmail($this->email);
     $stat->setLead($this->factory->getEntityManager()->getReference('MauticLeadBundle:Lead', $this->lead['id']));
     $stat->setEmailAddress($this->lead['email']);
     $stat->setTrackingHash($this->idHash);
     if (!empty($this->source)) {
         $stat->setSource($this->source[0]);
         $stat->setSourceId($this->source[1]);
     }
     $stat->setCopy($this->getBody());
     $stat->setTokens($this->getTokens());
     /** @var \Mautic\EmailBundle\Model\EmailModel $emailModel */
     $emailModel = $this->factory->getModel('email');
     $emailModel->getStatRepository()->saveEntity($stat);
 }
コード例 #3
0
ファイル: MailHelper.php プロジェクト: emtudo/mautic
 /**
  * Create an email stat
  *
  * @param bool|true   $persist
  * @param string|null $emailAddress
  * @param null        $listId
  *
  * @return Stat|void
  * @throws \Doctrine\ORM\ORMException
  */
 public function createEmailStat($persist = true, $emailAddress = null, $listId = null)
 {
     static $copies = array();
     //create a stat
     $stat = new Stat();
     $stat->setDateSent(new \DateTime());
     $stat->setEmail($this->email);
     // Note if a lead
     if (null !== $this->lead) {
         $stat->setLead($this->factory->getEntityManager()->getReference('MauticLeadBundle:Lead', $this->lead['id']));
         $emailAddress = $this->lead['email'];
     }
     // Find email if applicable
     if (null === $emailAddress) {
         // Use the last address set
         $emailAddresses = $this->message->getTo();
         if (count($emailAddresses)) {
             end($emailAddresses);
             $emailAddress = key($emailAddresses);
         }
     }
     $stat->setEmailAddress($emailAddress);
     // Note if sent from a lead list
     if (null !== $listId) {
         $stat->setList($this->factory->getEntityManager()->getReference('MauticLeadBundle:LeadList', $listId));
     }
     $stat->setTrackingHash($this->idHash);
     if (!empty($this->source)) {
         $stat->setSource($this->source[0]);
         $stat->setSourceId($this->source[1]);
     }
     $stat->setTokens($this->getTokens());
     /** @var \Mautic\EmailBundle\Model\EmailModel $emailModel */
     $emailModel = $this->factory->getModel('email');
     // Save a copy of the email - use email ID if available simply to prevent from having to rehash over and over
     $id = null !== $this->email ? $this->email->getId() : md5($this->subject . $this->body['content']);
     if (!isset($copies[$id])) {
         $hash = strlen($id) !== 32 ? md5($this->subject . $this->body['content']) : $id;
         $copy = $emailModel->getCopyRepository()->findByHash($hash);
         if (null === $copy) {
             // Create a copy entry
             $copy = new Copy();
             $copy->setId($hash)->setBody($this->body['content'])->setSubject($this->subject)->setDateCreated(new \DateTime())->setEmail($this->email);
             $emailModel->getCopyRepository()->saveEntity($copy);
         }
         $copies[$id] = $copy;
     }
     $stat->setStoredCopy($copies[$id]);
     if ($persist) {
         $emailModel->getStatRepository()->saveEntity($stat);
     }
     return $stat;
 }
コード例 #4
0
 /**
  * {@inheritDoc}
  */
 public function setSourceId($sourceId)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setSourceId', array($sourceId));
     return parent::setSourceId($sourceId);
 }