/** * Determine if this campaign applies * * @param $eventDetails * @param $event * * @return bool */ public static function validateEmailTrigger(Email $eventDetails = null, $event) { if ($eventDetails == null) { return false; } //check to see if the parent event is a "send email" event and that it matches the current email opened if (!empty($event['parent']) && $event['parent']['type'] == 'email.send') { return $eventDetails->getId() === (int) $event['parent']['properties']['email']; } return false; }
/** * @param ObjectManager $manager */ public function load(ObjectManager $manager) { $factory = $this->container->get('mautic.factory'); $model = $factory->getModel('email'); $repo = $model->getRepository(); $emails = CsvHelper::csv_to_array(__DIR__ . '/fakeemaildata.csv'); foreach ($emails as $count => $rows) { $email = new Email(); $email->setDateAdded(new \DateTime()); $key = $count + 1; foreach ($rows as $col => $val) { if ($val != 'NULL') { $setter = 'set' . ucfirst($col); if (in_array($col, ['content', 'variantSettings'])) { $val = unserialize(stripslashes($val)); } $email->{$setter}($val); } } $email->addList($this->getReference('lead-list')); $repo->saveEntity($email); $this->setReference('email-' . $key, $email); } }
/** * Gets template, stats, weights, etc for an email in preparation to be sent * * @param Email $email * @param bool $includeVariants * * @return array */ public function getEmailSettings(Email $email, $includeVariants = true) { static $emailSettings = array(); if (empty($emailSettings[$email->getId()])) { //used to house slots so they don't have to be fetched over and over for same template $slots = array(); $template = $email->getTemplate(); $slots[$template] = $this->factory->getTheme($template)->getSlots('email'); //store the settings of all the variants in order to properly disperse the emails //set the parent's settings $emailSettings = array($email->getId() => array('template' => $email->getTemplate(), 'slots' => $slots, 'sentCount' => $email->getSentCount(), 'variantCount' => $email->getVariantSentCount(), 'entity' => $email)); if ($includeVariants) { //get a list of variants for A/B testing $childrenVariant = $email->getVariantChildren(); if (count($childrenVariant)) { $variantWeight = 0; $totalSent = $email->getVariantSentCount(); foreach ($childrenVariant as $id => $child) { if ($child->isPublished()) { $template = $child->getTemplate(); if (isset($slots[$template])) { $useSlots = $slots[$template]; } else { $slots[$template] = $this->factory->getTheme($template)->getSlots('email'); $useSlots = $slots[$template]; } $variantSettings = $child->getVariantSettings(); $emailSettings[$child->getId()] = array('template' => $child->getTemplate(), 'slots' => $useSlots, 'sentCount' => $child->getSentCount(), 'variantCount' => $child->getVariantSentCount(), 'weight' => $variantSettings['weight'] / 100, 'entity' => $child); $variantWeight += $variantSettings['weight']; $totalSent += $emailSettings[$child->getId()]['sentCount']; } } //set parent weight $emailSettings[$email->getId()]['weight'] = (100 - $variantWeight) / 100; //now find what percentage of current leads should receive the variants foreach ($emailSettings as $eid => &$details) { $details['weight'] = $totalSent ? $details['weight'] - $details['variantCount'] / $totalSent + $details['weight'] : $details['weight']; } } else { $emailSettings[$email->getId()]['weight'] = 1; } } } return $emailSettings; }
/** * @param Email $email * @param bool $allowBcc Honor BCC if set in email * @param array $slots Slots configured in theme * @param array $assetAttachments Assets to send * @param bool $ignoreTrackingPixel Do not append tracking pixel HTML */ public function setEmail(Email $email, $allowBcc = true, $slots = array(), $assetAttachments = array(), $ignoreTrackingPixel = false) { $this->email = $email; $subject = $email->getSubject(); // Convert short codes to emoji $subject = EmojiHelper::toEmoji($subject, 'short'); // Set message settings from the email $this->setSubject($subject); $fromEmail = $email->getFromAddress(); $fromName = $email->getFromName(); if (!empty($fromEmail) && !empty($fromEmail)) { $this->setFrom($fromEmail, $fromName); } else { if (!empty($fromEmail)) { $this->setFrom($fromEmail, $this->from); } else { if (!empty($fromName)) { $this->setFrom(key($this->from), $fromName); } } } $replyTo = $email->getReplyToAddress(); if (!empty($replyTo)) { $this->setReplyTo($replyTo); } if ($allowBcc) { $bccAddress = $email->getBccAddress(); if (!empty($bccAddress)) { $this->addBcc($bccAddress); } } if ($plainText = $email->getPlainText()) { $this->setPlainText($plainText); } $template = $email->getTemplate(); if (!empty($template)) { if (empty($slots)) { $template = $email->getTemplate(); $slots = $this->factory->getTheme($template)->getSlots('email'); } if (isset($slots[$template])) { $slots = $slots[$template]; } $customHtml = $this->setTemplate('MauticEmailBundle::public.html.php', array('slots' => $slots, 'content' => $email->getContent(), 'email' => $email, 'template' => $template), true); } else { // Tak on the tracking pixel token $customHtml = $email->getCustomHtml(); } // Convert short codes to emoji $customHtml = EmojiHelper::toEmoji($customHtml, 'short'); $this->setBody($customHtml, 'text/html', null, $ignoreTrackingPixel); // Reset attachments $this->assets = $this->attachedAssets = array(); if (empty($assetAttachments)) { if ($assets = $email->getAssetAttachments()) { foreach ($assets as $asset) { $this->attachAsset($asset); } } } else { foreach ($assetAttachments as $asset) { $this->attachAsset($asset); } } }
/** * @deprecated 2.1 - use $entity->getVariants() instead; to be removed in 3.0 * * @param Page $entity * * @return array */ public function getVariants(Email $entity) { return $entity->getVariants(); }
/** * PreProcess page slots for public view. * * @param array $slots * @param Email $entity */ private function processSlots($slots, $entity) { /** @var \Mautic\CoreBundle\Templating\Helper\SlotsHelper $slotsHelper */ $slotsHelper = $this->factory->getHelper('template.slots'); /** @var \Mautic\CoreBundle\Templating\Helper\TranslatorHelper $translatorHelper */ $translatorHelper = $this->factory->getHelper('template.translator'); $content = $entity->getContent(); //Set the slots foreach ($slots as $slot => $slotConfig) { //support previous format where email slots are not defined with config array if (is_numeric($slot)) { $slot = $slotConfig; $slotConfig = []; } $value = isset($content[$slot]) ? $content[$slot] : ''; $placeholder = isset($slotConfig['placeholder']) ? $slotConfig['placeholder'] : 'mautic.page.builder.addcontent'; $slotsHelper->set($slot, "<div data-slot=\"text\" id=\"slot-{$slot}\">{$value}</div>"); } //add builder toolbar $slotsHelper->start('builder'); ?> <input type="hidden" id="builder_entity_id" value="<?php echo $entity->getSessionId(); ?> "/> <?php $slotsHelper->stop(); }
/** * @param $slots * @param Email $entity */ public function processSlots($slots, $entity) { /** @var \Mautic\CoreBundle\Templating\Helper\SlotsHelper $slotsHelper */ $slotsHelper = $this->factory->getHelper('template.slots'); $content = $entity->getContent(); foreach ($slots as $slot => $slotConfig) { if (is_numeric($slot)) { $slot = $slotConfig; $slotConfig = []; } $value = isset($content[$slot]) ? $content[$slot] : ''; $slotsHelper->set($slot, $value); } }
/** * {@inheritDoc} */ public function __toString() { $this->__initializer__ && $this->__initializer__->__invoke($this, '__toString', array()); return parent::__toString(); }