Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function getPath()
 {
     $controller = str_replace('\\', '/', $this->get('controller'));
     if (!empty($this->themeOverride)) {
         try {
             $theme = $this->themeHelper->getTheme($this->themeOverride);
             $themeDir = $theme->getThemePath();
         } catch (\Exception $e) {
         }
     } else {
         $theme = $this->themeHelper->getTheme();
         $themeDir = $theme->getThemePath();
     }
     $fileName = $this->get('name') . '.' . $this->get('format') . '.' . $this->get('engine');
     $path = (empty($controller) ? '' : $controller . '/') . $fileName;
     if (!empty($this->parameters['bundle'])) {
         $bundleRoot = $this->pathsHelper->getSystemPath('bundles', true);
         $pluginRoot = $this->pathsHelper->getSystemPath('plugins', true);
         // Check for a system-wide override
         $themePath = $this->pathsHelper->getSystemPath('themes', true);
         $systemTemplate = $themePath . '/system/' . $this->parameters['bundle'] . '/' . $path;
         if (file_exists($systemTemplate)) {
             $template = $systemTemplate;
         } else {
             //check for an override and load it if there is
             if (!empty($themeDir) && file_exists($themeDir . '/html/' . $this->parameters['bundle'] . '/' . $path)) {
                 // Theme override
                 $template = $themeDir . '/html/' . $this->parameters['bundle'] . '/' . $path;
             } else {
                 preg_match('/Mautic(.*?)Bundle/', $this->parameters['bundle'], $match);
                 if (!empty($match[1]) && file_exists($bundleRoot . '/' . $match[1] . 'Bundle/Views/' . $path) || file_exists($pluginRoot . '/' . $this->parameters['bundle'] . '/Views/' . $path)) {
                     // Mautic core template
                     $template = '@' . $this->get('bundle') . '/Views/' . $path;
                 }
             }
         }
     } else {
         $themes = $this->themeHelper->getInstalledThemes();
         if (isset($themes[$controller])) {
             //this is a file in a specific Mautic theme folder
             $theme = $this->themeHelper->getTheme($controller);
             $template = $theme->getThemePath() . '/html/' . $fileName;
         }
     }
     if (empty($template)) {
         //try the parent
         return parent::getPath();
     }
     return $template;
 }
Exemplo n.º 2
0
 /**
  * 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)
 {
     if (empty($this->emailSettings[$email->getId()])) {
         //used to house slots so they don't have to be fetched over and over for same template
         // BC for Mautic v1 templates
         $slots = [];
         if ($template = $email->getTemplate()) {
             $slots[$template] = $this->themeHelper->getTheme($template)->getSlots('email');
         }
         //store the settings of all the variants in order to properly disperse the emails
         //set the parent's settings
         $emailSettings = [$email->getId() => ['template' => $email->getTemplate(), 'slots' => $slots, 'sentCount' => $email->getSentCount(), 'variantCount' => $email->getVariantSentCount(), 'isVariant' => null !== $email->getVariantStartDate(), 'entity' => $email, 'translations' => $email->getTranslations(true), 'languages' => ['default' => $email->getId()]]];
         if ($emailSettings[$email->getId()]['translations']) {
             // Add in the sent counts for translations of this email
             /** @var Email $translation */
             foreach ($emailSettings[$email->getId()]['translations'] as $translation) {
                 if ($translation->isPublished()) {
                     $emailSettings[$email->getId()]['sentCount'] += $translation->getSentCount();
                     $emailSettings[$email->getId()]['variantCount'] += $translation->getVariantSentCount();
                     // Prevent empty key due to misconfiguration - pretty much ignored
                     if (!($language = $translation->getLanguage())) {
                         $language = 'unknown';
                     }
                     $core = $this->getTranslationLocaleCore($language);
                     if (!isset($emailSettings[$email->getId()]['languages'][$core])) {
                         $emailSettings[$email->getId()]['languages'][$core] = [];
                     }
                     $emailSettings[$email->getId()]['languages'][$core][$language] = $translation->getId();
                 }
             }
         }
         if ($includeVariants && $email->isVariant()) {
             //get a list of variants for A/B testing
             $childrenVariant = $email->getVariantChildren();
             if (count($childrenVariant)) {
                 $variantWeight = 0;
                 $totalSent = $emailSettings[$email->getId()]['variantCount'];
                 foreach ($childrenVariant as $id => $child) {
                     if ($child->isPublished()) {
                         $useSlots = [];
                         if ($template = $child->getTemplate()) {
                             if (isset($slots[$template])) {
                                 $useSlots = $slots[$template];
                             } else {
                                 $slots[$template] = $this->themeHelper->getTheme($template)->getSlots('email');
                                 $useSlots = $slots[$template];
                             }
                         }
                         $variantSettings = $child->getVariantSettings();
                         $emailSettings[$child->getId()] = ['template' => $child->getTemplate(), 'slots' => $useSlots, 'sentCount' => $child->getSentCount(), 'variantCount' => $child->getVariantSentCount(), 'isVariant' => null !== $email->getVariantStartDate(), 'weight' => $variantSettings['weight'] / 100, 'entity' => $child, 'translations' => $child->getTranslations(true), 'languages' => ['default' => $child->getId()]];
                         $variantWeight += $variantSettings['weight'];
                         if ($emailSettings[$child->getId()]['translations']) {
                             // Add in the sent counts for translations of this email
                             /** @var Email $translation */
                             foreach ($emailSettings[$child->getId()]['translations'] as $translation) {
                                 if ($translation->isPublished()) {
                                     $emailSettings[$child->getId()]['sentCount'] += $translation->getSentCount();
                                     $emailSettings[$child->getId()]['variantCount'] += $translation->getVariantSentCount();
                                     // Prevent empty key due to misconfiguration - pretty much ignored
                                     if (!($language = $translation->getLanguage())) {
                                         $language = 'unknown';
                                     }
                                     $core = $this->getTranslationLocaleCore($language);
                                     if (!isset($emailSettings[$child->getId()]['languages'][$core])) {
                                         $emailSettings[$child->getId()]['languages'][$core] = [];
                                     }
                                     $emailSettings[$child->getId()]['languages'][$core][$language] = $translation->getId();
                                 }
                             }
                         }
                         $totalSent += $emailSettings[$child->getId()]['variantCount'];
                     }
                 }
                 //set parent weight
                 $emailSettings[$email->getId()]['weight'] = (100 - $variantWeight) / 100;
             } else {
                 $emailSettings[$email->getId()]['weight'] = 1;
             }
         }
         $this->emailSettings[$email->getId()] = $emailSettings;
     }
     if ($includeVariants && $email->isVariant()) {
         //now find what percentage of current leads should receive the variants
         if (!isset($totalSent)) {
             $totalSent = 0;
             foreach ($this->emailSettings[$email->getId()] as $eid => $details) {
                 $totalSent += $details['variantCount'];
             }
         }
         foreach ($this->emailSettings[$email->getId()] as $eid => &$details) {
             // Determine the deficit for email ordering
             if ($totalSent) {
                 $details['weight_deficit'] = $details['weight'] - $details['variantCount'] / $totalSent;
                 $details['send_weight'] = $details['weight'] - $details['variantCount'] / $totalSent + $details['weight'];
             } else {
                 $details['weight_deficit'] = $details['weight'];
                 $details['send_weight'] = $details['weight'];
             }
         }
         // Reorder according to send_weight so that campaigns which currently send one at a time alternate
         uasort($this->emailSettings[$email->getId()], function ($a, $b) {
             if ($a['weight_deficit'] === $b['weight_deficit']) {
                 if ($a['variantCount'] === $b['variantCount']) {
                     return 0;
                 }
                 // if weight is the same - sort by least number sent
                 return $a['variantCount'] < $b['variantCount'] ? -1 : 1;
             }
             // sort by the one with the greatest deficit first
             return $a['weight_deficit'] > $b['weight_deficit'] ? -1 : 1;
         });
     }
     return $this->emailSettings[$email->getId()];
 }
Exemplo n.º 3
0
 /**
  * Generate the form's html.
  *
  * @param Form $entity
  * @param bool $persist
  *
  * @return string
  */
 public function generateHtml(Form $entity, $persist = true)
 {
     //generate cached HTML
     $theme = $entity->getTemplate();
     $submissions = null;
     $lead = $this->leadModel->getCurrentLead();
     $style = '';
     if (!empty($theme)) {
         $theme .= '|';
     }
     if ($entity->usesProgressiveProfiling()) {
         $submissions = $this->getRepository()->getFormResults($entity, ['leadId' => $lead->getId(), 'limit' => 200]);
     }
     if ($entity->getRenderStyle()) {
         $templating = $this->templatingHelper->getTemplating();
         $styleTheme = $theme . 'MauticFormBundle:Builder:style.html.php';
         $style = $templating->render($this->themeHelper->checkForTwigTemplate($styleTheme));
     }
     // Determine pages
     $fields = $entity->getFields()->toArray();
     // Ensure the correct order in case this is generated right after a form save with new fields
     uasort($fields, function ($a, $b) {
         if ($a->getOrder() === $b->getOrder()) {
             return 0;
         }
         return $a->getOrder() < $b->getOrder() ? -1 : 1;
     });
     $pages = ['open' => [], 'close' => []];
     $openFieldId = $closeFieldId = $previousId = $lastPage = false;
     $pageCount = 1;
     foreach ($fields as $fieldId => $field) {
         if ('pagebreak' == $field->getType() && $openFieldId) {
             // Open the page
             $pages['open'][$openFieldId] = $pageCount;
             $openFieldId = false;
             $lastPage = $fieldId;
             // Close the page at the next page break
             if ($previousId) {
                 $pages['close'][$previousId] = $pageCount;
                 ++$pageCount;
             }
         } else {
             if (!$openFieldId) {
                 $openFieldId = $fieldId;
             }
         }
         $previousId = $fieldId;
     }
     if (!empty($pages)) {
         if ($openFieldId) {
             $pages['open'][$openFieldId] = $pageCount;
         }
         if ($previousId !== $lastPage) {
             $pages['close'][$previousId] = $pageCount;
         }
     }
     $html = $this->templatingHelper->getTemplating()->render($theme . 'MauticFormBundle:Builder:form.html.php', ['fieldSettings' => $this->getCustomComponents()['fields'], 'fields' => $fields, 'contactFields' => $this->leadFieldModel->getFieldListWithProperties(), 'form' => $entity, 'theme' => $theme, 'submissions' => $submissions, 'lead' => $lead, 'formPages' => $pages, 'lastFormPage' => $lastPage, 'style' => $style]);
     if (!$entity->usesProgressiveProfiling()) {
         $entity->setCachedHtml($html);
         if ($persist) {
             //bypass model function as events aren't needed for this
             $this->getRepository()->saveEntity($entity);
         }
     }
     return $html;
 }
Exemplo n.º 4
0
 /**
  * AssetType constructor.
  *
  * @param TranslatorInterface $translator
  * @param ThemeHelper         $themeHelper
  * @param AssetModel          $assetModel
  */
 public function __construct(TranslatorInterface $translator, ThemeHelper $themeHelper, AssetModel $assetModel)
 {
     $this->translator = $translator;
     $this->themes = $themeHelper->getInstalledThemes('asset');
     $this->assetModel = $assetModel;
 }