Exemple #1
0
 /**
  * {@inheritdoc}
  *
  * @param Page $entity
  * @param bool $unlock
  */
 public function saveEntity($entity, $unlock = true)
 {
     if (empty($this->inConversion)) {
         $alias = $entity->getAlias();
         if (empty($alias)) {
             $alias = $entity->getTitle();
         }
         $alias = $this->cleanAlias($alias, '', false, '-');
         //make sure alias is not already taken
         $repo = $this->getRepository();
         $testAlias = $alias;
         $count = $repo->checkUniqueAlias($testAlias, $entity);
         $aliasTag = $count;
         while ($count) {
             $testAlias = $alias . $aliasTag;
             $count = $repo->checkUniqueAlias($testAlias, $entity);
             $aliasTag++;
         }
         if ($testAlias != $alias) {
             $alias = $testAlias;
         }
         $entity->setAlias($alias);
     }
     $now = new DateTimeHelper();
     //set the author for new pages
     $isNew = $entity->isNew();
     if (!$isNew) {
         //increase the revision
         $revision = $entity->getRevision();
         $revision++;
         $entity->setRevision($revision);
     }
     // Reset the variant hit and start date if there are any changes and if this is an A/B test
     // Do it here in addition to the blanket resetVariants call so that it's available to the event listeners
     $changes = $entity->getChanges();
     $parent = $entity->getVariantParent();
     if ($parent !== null && !empty($changes) && empty($this->inConversion)) {
         $entity->setVariantHits(0);
         $entity->setVariantStartDate($now->getDateTime());
     }
     parent::saveEntity($entity, $unlock);
     // If parent, add this entity as a child of the parent so that it populates the list in the tab (due to Doctrine hanging on to entities in memory)
     if ($parent) {
         $parent->addVariantChild($entity);
     }
     if ($translationParent = $entity->getTranslationParent()) {
         $translationParent->addTranslationChild($entity);
     }
     // Reset associated variants if applicable due to changes
     if ($entity->isVariant() && !empty($changes) && empty($this->inConversion)) {
         $dateString = $now->toUtcString();
         $parentId = !empty($parent) ? $parent->getId() : $entity->getId();
         $this->getRepository()->resetVariants($parentId, $dateString);
         //if the parent was changed, then that parent/children must also be reset
         if (isset($changes['variantParent'])) {
             $this->getRepository()->resetVariants($changes['variantParent'][0], $dateString);
         }
     }
 }
Exemple #2
0
 /**
  * PreProcess page slots for public view.
  *
  * @deprecated - to be removed in 3.0
  *
  * @param array $slots
  * @param Page  $entity
  */
 private function processSlots($slots, $entity)
 {
     /** @var \Mautic\CoreBundle\Templating\Helper\AssetsHelper $assetsHelper */
     $assetsHelper = $this->factory->getHelper('template.assets');
     /** @var \Mautic\CoreBundle\Templating\Helper\SlotsHelper $slotsHelper */
     $slotsHelper = $this->factory->getHelper('template.slots');
     $content = $entity->getContent();
     foreach ($slots as $slot => $slotConfig) {
         // backward compatibility - if slotConfig array does not exist
         if (is_numeric($slot)) {
             $slot = $slotConfig;
             $slotConfig = [];
         }
         if (isset($slotConfig['type']) && $slotConfig['type'] == 'slideshow') {
             if (isset($content[$slot])) {
                 $options = json_decode($content[$slot], true);
             } else {
                 $options = ['width' => '100%', 'height' => '250px', 'background_color' => 'transparent', 'arrow_navigation' => false, 'dot_navigation' => true, 'interval' => 5000, 'pause' => 'hover', 'wrap' => true, 'keyboard' => true];
             }
             // Create sample slides for first time or if all slides were deleted
             if (empty($options['slides'])) {
                 $options['slides'] = [['order' => 0, 'background-image' => $assetsHelper->getUrl('media/images/mautic_logo_lb200.png'), 'captionheader' => 'Caption 1'], ['order' => 1, 'background-image' => $assetsHelper->getUrl('media/images/mautic_logo_db200.png'), 'captionheader' => 'Caption 2']];
             }
             // Order slides
             usort($options['slides'], function ($a, $b) {
                 return strcmp($a['order'], $b['order']);
             });
             $options['slot'] = $slot;
             $options['public'] = true;
             $renderingEngine = $this->container->get('templating')->getEngine('MauticPageBundle:Page:Slots/slideshow.html.php');
             $slotsHelper->set($slot, $renderingEngine->render('MauticPageBundle:Page:Slots/slideshow.html.php', $options));
         } elseif (isset($slotConfig['type']) && $slotConfig['type'] == 'textarea') {
             $value = isset($content[$slot]) ? nl2br($content[$slot]) : "";
             $slotsHelper->set($slot, $value);
         } else {
             // Fallback for other types like html, text, textarea and all unknown
             $value = isset($content[$slot]) ? $content[$slot] : "";
             $slotsHelper->set($slot, $value);
         }
     }
     $parentVariant = $entity->getVariantParent();
     $title = !empty($parentVariant) ? $parentVariant->getTitle() : $entity->getTitle();
     $slotsHelper->set('pageTitle', $title);
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  *
  * @param Page $entity
  * @param bool $unlock
  */
 public function saveEntity($entity, $unlock = true)
 {
     if (empty($this->inConversion)) {
         $alias = $entity->getAlias();
         if (empty($alias)) {
             $alias = $entity->getTitle();
         }
         $alias = $this->cleanAlias($alias, '', false, '-');
         //make sure alias is not already taken
         $repo = $this->getRepository();
         $testAlias = $alias;
         $count = $repo->checkUniqueAlias($testAlias, $entity);
         $aliasTag = $count;
         while ($count) {
             $testAlias = $alias . $aliasTag;
             $count = $repo->checkUniqueAlias($testAlias, $entity);
             $aliasTag++;
         }
         if ($testAlias != $alias) {
             $alias = $testAlias;
         }
         $entity->setAlias($alias);
     }
     $now = new \DateTime();
     //set the author for new pages
     if (!$entity->isNew()) {
         //increase the revision
         $revision = $entity->getRevision();
         $revision++;
         $entity->setRevision($revision);
         //reset the variant hit and start date if there are any changes
         $changes = $entity->getChanges();
         $isVariant = $entity->getVariantStartDate();
         if ($isVariant !== null && !empty($changes) && empty($this->inConversion)) {
             $entity->setVariantHits(0);
             $entity->setVariantStartDate($now);
         }
     }
     parent::saveEntity($entity, $unlock);
     //also reset variants if applicable due to changes
     if (!empty($changes) && empty($this->inConversion)) {
         $parent = $entity->getVariantParent();
         $children = !empty($parent) ? $parent->getVariantChildren() : $entity->getVariantChildren();
         $variants = array();
         if (!empty($parent)) {
             $parent->setVariantHits(0);
             $parent->setVariantStartDate($now);
             $variants[] = $parent;
         }
         if (count($children)) {
             foreach ($children as $child) {
                 $child->setVariantHits(0);
                 $child->setVariantStartDate($now);
                 $variants[] = $child;
             }
         }
         //if the parent was changed, then that parent/children must also be reset
         if (isset($changes['variantParent'])) {
             $parent = $this->getEntity($changes['variantParent'][0]);
             if (!empty($parent)) {
                 $parent->setVariantHits(0);
                 $parent->setVariantStartDate($now);
                 $variants[] = $parent;
                 $children = $parent->getVariantChildren();
                 if (count($children)) {
                     foreach ($children as $child) {
                         $child->setVariantHits(0);
                         $child->setVariantStartDate($now);
                         $variants[] = $child;
                     }
                 }
             }
         }
         if (!empty($variants)) {
             $this->saveEntities($variants, false);
         }
     }
 }
 /**
  * Determines the winner of A/B test based on number of asset downloads
  *
  * @param MauticFactory $factory
  * @param Page          $parent
  * @param               $children
  *
  * @return array
  */
 public static function determineDownloadWinner($factory, $parent, $children)
 {
     $repo = $factory->getEntityManager()->getRepository('MauticAssetBundle:Download');
     //if this is an email A/B test, then link email to page to form submission
     //if it is a page A/B test, then link form submission to page
     $type = $parent instanceof Email ? 'email' : 'page';
     $ids = array($parent->getId());
     foreach ($children as $c) {
         if ($c->isPublished()) {
             $id = $c->getId();
             $ids[] = $id;
         }
     }
     $startDate = $parent->getVariantStartDate();
     if ($startDate != null && !empty($ids)) {
         $counts = $type == 'page' ? $repo->getDownloadCountsByPage($ids, $startDate) : $repo->getDownloadCountsByEmail($ids, $startDate);
         $translator = $factory->getTranslator();
         if ($counts) {
             $downloads = $support = $data = array();
             $hasResults = array();
             $downloadsLabel = $translator->trans('mautic.asset.abtest.label.downloads');
             $hitsLabel = $type == 'page' ? $translator->trans('mautic.asset.abtest.label.hits') : $translator->trans('mautic.asset.abtest.label.sentemils');
             foreach ($counts as $stats) {
                 $rate = $stats['total'] ? round($stats['count'] / $stats['total'] * 100, 2) : 0;
                 $downloads[$stats['id']] = $rate;
                 $data[$downloadsLabel][] = $stats['count'];
                 $data[$hitsLabel][] = $stats['total'];
                 $support['labels'][] = $stats['id'] . ':' . $stats['name'] . ' (' . $rate . '%)';
                 $hasResults[] = $stats['id'];
             }
             //make sure that parent and published children are included
             if (!in_array($parent->getId(), $hasResults)) {
                 $data[$downloadsLabel][] = 0;
                 $data[$hitsLabel][] = 0;
                 $support['labels'][] = $parent->getId() . ':' . ($type == 'page' ? $parent->getTitle() : $parent->getName()) . ' (0%)';
             }
             foreach ($children as $c) {
                 if ($c->isPublished()) {
                     if (!in_array($c->getId(), $hasResults)) {
                         $data[$downloadsLabel][] = 0;
                         $data[$hitsLabel][] = 0;
                         $support['labels'][] = $c->getId() . ':' . ($type == 'page' ? $c->getTitle() : $c->getName()) . ' (0%)';
                     }
                 }
             }
             $support['data'] = $data;
             //set max for scales
             $maxes = array();
             foreach ($support['data'] as $label => $data) {
                 $maxes[] = max($data);
             }
             $top = max($maxes);
             $support['step_width'] = ceil($top / 10) * 10;
             //put in order from least to greatest just because
             asort($downloads);
             //who's the winner?
             $max = max($downloads);
             //get the page ids with the most number of downloads
             $winners = $max > 0 ? array_keys($downloads, $max) : array();
             return array('winners' => $winners, 'support' => $support, 'basedOn' => 'asset.downloads', 'supportTemplate' => 'MauticPageBundle:SubscribedEvents\\AbTest:bargraph.html.php');
         }
     }
     return array('winners' => array(), 'support' => array(), 'basedOn' => 'asset.downloads');
 }
Exemple #5
0
 /**
  * {@inheritdoc}
  *
  * @param Page $entity
  * @param bool $unlock
  */
 public function saveEntity($entity, $unlock = true)
 {
     $pageIds = $entity->getRelatedEntityIds();
     if (empty($this->inConversion)) {
         $alias = $entity->getAlias();
         if (empty($alias)) {
             $alias = $entity->getTitle();
         }
         $alias = $this->cleanAlias($alias, '', false, '-');
         //make sure alias is not already taken
         $repo = $this->getRepository();
         $testAlias = $alias;
         $count = $repo->checkPageUniqueAlias($testAlias, $pageIds);
         $aliasTag = 1;
         while ($count) {
             $testAlias = $alias . $aliasTag;
             $count = $repo->checkPageUniqueAlias($testAlias, $pageIds);
             ++$aliasTag;
         }
         if ($testAlias != $alias) {
             $alias = $testAlias;
         }
         $entity->setAlias($alias);
     }
     // Set the author for new pages
     $isNew = $entity->isNew();
     if (!$isNew) {
         //increase the revision
         $revision = $entity->getRevision();
         ++$revision;
         $entity->setRevision($revision);
     }
     // Reset a/b test if applicable
     $variantStartDate = new \DateTime();
     $resetVariants = $this->preVariantSaveEntity($entity, ['setVariantHits'], $variantStartDate);
     parent::saveEntity($entity, $unlock);
     $this->postVariantSaveEntity($entity, $resetVariants, $pageIds, $variantStartDate);
     $this->postTranslationEntitySave($entity);
 }
 /**
  * {@inheritDoc}
  */
 public function getTitle()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getTitle', array());
     return parent::getTitle();
 }