Example #1
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);
 }
Example #2
0
 /**
  * Determines the winner of A/B test based on dwell time rates
  *
  * @param MauticFactory $factory
  * @param Page          $parent
  * @param               $children
  *
  * @return array
  */
 public static function determineDwellTimeTestWinner($factory, $parent)
 {
     //find the hits that did not go any further
     $repo = $factory->getEntityManager()->getRepository('MauticPageBundle:Hit');
     $pageIds = $parent->getRelatedEntityIds();
     $startDate = $parent->getVariantStartDate();
     if ($startDate != null && !empty($pageIds)) {
         //get their bounce rates
         $counts = $repo->getDwellTimesForPages($pageIds, ['fromDate' => $startDate]);
         $translator = $factory->getTranslator();
         $support = [];
         if ($counts) {
             //in order to get a fair grade, we have to compare the averages here since a page that is only shown
             //25% of the time will have a significantly lower sum than a page shown 75% of the time
             $avgs = [];
             $support['data'] = [];
             $support['labels'] = [];
             foreach ($counts as $pid => $stats) {
                 $avgs[$pid] = $stats['average'];
                 $support['data'][$translator->trans('mautic.page.abtest.label.dewlltime.average')][] = $stats['average'];
                 $support['labels'][] = $pid . ':' . $stats['title'];
             }
             //set max for scales
             $max = max($avgs);
             $support['step_width'] = ceil($max / 10) * 10;
             //get the page ids with the greatest average dwell time
             $winners = $max > 0 ? array_keys($avgs, $max) : [];
             return ['winners' => $winners, 'support' => $support, 'basedOn' => 'page.dwelltime', 'supportTemplate' => 'MauticPageBundle:SubscribedEvents\\AbTest:bargraph.html.php'];
         }
     }
     return ['winners' => [], 'support' => [], 'basedOn' => 'page.dwelltime'];
 }