/** * Determines the winner of A/B test based on bounce rates * * @param $factory * @param Page $parent * @param Page[] $children * * @return array */ public static function determineBounceTestWinner($factory, $parent, $children) { //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->getBounces($pageIds, $startDate, true); if ($counts) { // Group by translation $combined = [$parent->getId() => $counts[$parent->getId()]]; if ($parent->hasTranslations()) { $translations = $parent->getTranslationChildren()->getKeys(); foreach ($translations as $translation) { $combined[$parent->getId()]['bounces'] += $counts[$translation]['bounces']; $combined[$parent->getId()]['totalHits'] += $counts[$translation]['totalHits']; $combined[$parent->getId()]['rate'] = $counts[$parent->getId()]['totalHits'] ? round($counts[$parent->getId()]['bounces'] / $counts[$parent->getId()]['totalHits'] * 100, 2) : 0; } } foreach ($children as $child) { if ($child->hasTranslations()) { $combined[$child->getId()] = $counts[$child->getId()]; $translations = $child->getTranslationChildren()->getKeys(); foreach ($translations as $translation) { $combined[$child->getId()]['bounces'] += $counts[$translation]['bounces']; $combined[$child->getId()]['totalHits'] += $counts[$translation]['totalHits']; $combined[$child->getId()]['rate'] = $counts[$child->getId()]['totalHits'] ? round($counts[$child->getId()]['bounces'] / $counts[$child->getId()]['totalHits'] * 100, 2) : 0; } } } unset($counts); //let's arrange by rate $rates = []; $support['data'] = []; $support['labels'] = []; $bounceLabel = $factory->getTranslator()->trans('mautic.page.abtest.label.bounces'); foreach ($combined as $pid => $stats) { $rates[$pid] = $stats['rate']; $support['data'][$bounceLabel][] = $rates[$pid]; $support['labels'][] = $pid . ':' . $stats['title']; } $max = max($rates); $support['step_width'] = ceil($max / 10) * 10; //get the page ids with the greatest average dwell time $winners = $max > 0 ? array_keys($rates, $max) : []; return ['winners' => $winners, 'support' => $support, 'basedOn' => 'page.bouncerate', 'supportTemplate' => 'MauticPageBundle:SubscribedEvents\\AbTest:bargraph.html.php']; } } return ['winners' => [], 'support' => [], 'basedOn' => 'page.bouncerate']; }
/** * @param string $alias * @param Page $entity * * @return mixed */ public function checkUniqueAlias($alias, $entity = null) { $q = $this->createQueryBuilder('e')->select('count(e.id) as alias_count')->where('e.alias = :alias'); $q->setParameter('alias', $alias); if (!empty($entity)) { $parent = $entity->getTranslationParent(); $children = $entity->getTranslationChildren(); if ($parent || count($children)) { //allow same alias among language group $ids = array(); if (!empty($parent)) { $children = $parent->getTranslationChildren(); $ids[] = $parent->getId(); } foreach ($children as $child) { if ($child->getId() != $entity->getId()) { $ids[] = $child->getId(); } } $q->andWhere($q->expr()->notIn('e.id', $ids)); } $parent = $entity->getVariantParent(); $children = $entity->getVariantChildren(); if ($parent || count($children)) { //allow same alias among language group $ids = array(); if (!empty($parent)) { $children = $parent->getVariantChildren(); $ids[] = $parent->getId(); } foreach ($children as $child) { if ($child->getId() != $entity->getId()) { $ids[] = $child->getId(); } } $q->andWhere($q->expr()->notIn('e.id', $ids)); } if ($entity->getId()) { $q->andWhere('e.id != :id'); $q->setParameter('id', $entity->getId()); } } $results = $q->getQuery()->getSingleResult(); return $results['alias_count']; }
/** * Get translation parent/children * * @param Page $page * * @return array */ public function getTranslations(Page $page) { $parent = $page->getTranslationParent(); if (!empty($parent)) { $children = $parent->getTranslationChildren(); } else { $parent = $page; $children = $page->getTranslationChildren(); } if (empty($children)) { $children = false; } return array($parent, $children); }
/** * {@inheritDoc} */ public function getTranslationChildren() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getTranslationChildren', array()); return parent::getTranslationChildren(); }