/** * Get hit count per day for last 30 days * * @param integer $assetId * @param integer $amount of units * @param char $unit: php.net/manual/en/dateinterval.construct.php#refsect1-dateinterval.construct-parameters * * @return array * @throws \Doctrine\ORM\NoResultException * @throws \Doctrine\ORM\NonUniqueResultException */ public function getDownloads($assetId, $amount = 30, $unit = 'D') { $data = GraphHelper::prepareDatetimeLineGraphData($amount, $unit, array('downloaded')); $query = $this->createQueryBuilder('d'); $query->select('IDENTITY(d.asset), d.dateDownload')->where($query->expr()->eq('IDENTITY(d.asset)', (int) $assetId))->andwhere($query->expr()->gte('d.dateDownload', ':date'))->setParameter('date', $data['fromDate']); $downloads = $query->getQuery()->getArrayResult(); return GraphHelper::mergeLineGraphData($data, $downloads, $unit, 0, 'dateDownload'); }
public function getSubmissionsSince($formId, $amount = 30, $unit = 'D') { $data = GraphHelper::prepareDatetimeLineGraphData($amount, $unit, array('submissions')); $submissions = $this->getSubmissions(array('id' => $formId, 'fromDate' => $data['fromDate'])); return GraphHelper::mergeLineGraphData($data, $submissions, $unit, 0, 'dateSubmitted'); }
/** * Get pie graph data for Sent, Read and Failed email count * * @param QueryBuilder $query * @param array $args * * @return array * @throws \Doctrine\ORM\NoResultException * @throws \Doctrine\ORM\NonUniqueResultException */ public function getIgnoredReadFailed($query = null, $args = array()) { if (!$query) { $query = $this->_em->getConnection()->createQueryBuilder()->from(MAUTIC_TABLE_PREFIX . 'email_stats', 'es')->leftJoin('es', MAUTIC_TABLE_PREFIX . 'emails', 'e', 'es.email_id = e.id'); } $query->select('count(es.id) as sent, count(CASE WHEN es.is_read THEN 1 ELSE null END) as "read", count(CASE WHEN es.is_failed THEN 1 ELSE null END) as failed'); if (isset($args['source'])) { $query->andWhere($query->expr()->eq('es.source', $query->expr()->literal($args['source']))); } if (isset($args['source_id'])) { $query->andWhere($query->expr()->eq('es.source_id', (int) $args['source_id'])); } $results = $query->execute()->fetch(); $results['ignored'] = $results['sent'] - $results['read'] - $results['failed']; unset($results['sent']); return GraphHelper::preparePieGraphData($results); }
/** * Initialize the QueryBuilder object to generate reports from * * @param ReportGeneratorEvent $event * * @return void */ public function onReportGraphGenerate(ReportGraphEvent $event) { // Context check, we only want to fire for Lead reports if (!$event->checkContext('email.stats')) { return; } $graphs = $event->getRequestedGraphs(); $qb = $event->getQueryBuilder(); $statRepo = $this->factory->getEntityManager()->getRepository('MauticEmailBundle:Stat'); foreach ($graphs as $g) { $options = $event->getOptions($g); $queryBuilder = clone $qb; switch ($g) { case 'mautic.email.graph.line.stats': // Generate data for Stats line graph $unit = 'D'; $amount = 30; if (isset($options['amount'])) { $amount = $options['amount']; } if (isset($options['unit'])) { $unit = $options['unit']; } $timeStats = GraphHelper::prepareDatetimeLineGraphData($amount, $unit, array('sent', 'read', 'failed')); $queryBuilder->select('es.email_id as email, es.date_sent as "dateSent", es.date_read as "dateRead", es.is_failed'); $queryBuilder->andwhere($queryBuilder->expr()->gte('es.date_sent', ':date'))->setParameter('date', $timeStats['fromDate']->format('Y-m-d H:i:s')); $stats = $queryBuilder->execute()->fetchAll(); $timeStats = GraphHelper::mergeLineGraphData($timeStats, $stats, $unit, 0, 'dateSent'); $timeStats = GraphHelper::mergeLineGraphData($timeStats, $stats, $unit, 1, 'dateRead'); $timeStats = GraphHelper::mergeLineGraphData($timeStats, $stats, $unit, 2, 'dateSent', 'is_failed'); $timeStats['name'] = 'mautic.email.graph.line.stats'; $event->setGraph($g, $timeStats); break; case 'mautic.email.graph.pie.ignored.read.failed': $items = $statRepo->getIgnoredReadFailed($queryBuilder); $graphData = array(); $graphData['data'] = $items; $graphData['name'] = 'mautic.email.graph.pie.ignored.read.failed'; $graphData['iconClass'] = 'fa-flag-checkered'; $event->setGraph($g, $graphData); break; case 'mautic.email.table.most.emails.sent': $queryBuilder->select('e.id, e.subject as title, count(es.id) as sent')->groupBy('e.id, e.subject')->orderBy('sent', 'DESC'); $limit = 10; $offset = 0; $items = $statRepo->getMostEmails($queryBuilder, $limit, $offset); $graphData = array(); $graphData['data'] = $items; $graphData['name'] = 'mautic.email.table.most.emails.sent'; $graphData['iconClass'] = 'fa-paper-plane-o'; $graphData['link'] = 'mautic_email_action'; $event->setGraph($g, $graphData); break; case 'mautic.email.table.most.emails.read': $queryBuilder->select('e.id, e.subject as title, count(CASE WHEN es.is_read THEN 1 ELSE null END) as "read"')->groupBy('e.id, e.subject')->orderBy('"read"', 'DESC'); $limit = 10; $offset = 0; $items = $statRepo->getMostEmails($queryBuilder, $limit, $offset); $graphData = array(); $graphData['data'] = $items; $graphData['name'] = 'mautic.email.table.most.emails.read'; $graphData['iconClass'] = 'fa-eye'; $graphData['link'] = 'mautic_email_action'; $event->setGraph($g, $graphData); break; case 'mautic.email.table.most.emails.failed': $queryBuilder->select('e.id, e.subject as title, count(CASE WHEN es.is_failed THEN 1 ELSE null END) as failed')->having('count(CASE WHEN es.is_failed THEN 1 ELSE null END) > 0')->groupBy('e.id, e.subject')->orderBy('failed', 'DESC'); $limit = 10; $offset = 0; $items = $statRepo->getMostEmails($queryBuilder, $limit, $offset); $graphData = array(); $graphData['data'] = $items; $graphData['name'] = 'mautic.email.table.most.emails.failed'; $graphData['iconClass'] = 'fa-exclamation-triangle'; $graphData['link'] = 'mautic_email_action'; $event->setGraph($g, $graphData); break; case 'mautic.email.table.most.emails.read.percent': $queryBuilder->select('e.id, e.subject as title, round(e.read_count / e.sent_count * 100) as ratio')->groupBy('e.id, e.subject')->orderBy('ratio', 'DESC'); $limit = 10; $offset = 0; $items = $statRepo->getMostEmails($queryBuilder, $limit, $offset); $graphData = array(); $graphData['data'] = $items; $graphData['name'] = 'mautic.email.table.most.emails.read.percent'; $graphData['iconClass'] = 'fa-tachometer'; $graphData['link'] = 'mautic_email_action'; $event->setGraph($g, $graphData); break; } unset($queryBuilder); } }
/** * Initialize the QueryBuilder object to generate reports from * * @param ReportGraphEvent $event * * @return void */ public function onReportGraphGenerate(ReportGraphEvent $event) { // Context check, we only want to fire for Lead reports if (!$event->checkContext(array('leads', 'lead.pointlog'))) { return; } $graphs = $event->getRequestedGraphs(); $qb = $event->getQueryBuilder(); $pointLogRepo = $this->factory->getEntityManager()->getRepository('MauticLeadBundle:PointsChangeLog'); foreach ($graphs as $g) { $options = $event->getOptions($g); $queryBuilder = clone $qb; switch ($g) { case 'mautic.lead.graph.line.leads': // Generate data for leads line graph $unit = 'D'; $amount = 30; if (isset($options['amount'])) { $amount = $options['amount']; } if (isset($options['unit'])) { $unit = $options['unit']; } $timeStats = GraphHelper::prepareDatetimeLineGraphData($amount, $unit, array('leads', 'emails')); $queryBuilder->select('l.id as lead, l.date_added as "dateAdded", LENGTH(l.email) > 0 as email'); $queryBuilder->andwhere($queryBuilder->expr()->gte('l.date_added', ':date'))->setParameter('date', $timeStats['fromDate']->format('Y-m-d H:i:s')); $leads = $queryBuilder->execute()->fetchAll(); $timeStats = GraphHelper::mergeLineGraphData($timeStats, $leads, $unit, 0, 'dateAdded'); $timeStats = GraphHelper::mergeLineGraphData($timeStats, $leads, $unit, 1, 'dateAdded', 'email'); $timeStats['name'] = 'mautic.lead.graph.line.leads'; $event->setGraph($g, $timeStats); break; case 'mautic.lead.graph.line.points': // Generate data for points line graph $unit = 'D'; $amount = 30; if (isset($options['amount'])) { $amount = $options['amount']; } if (isset($options['unit'])) { $unit = $options['unit']; } $timeStats = GraphHelper::prepareDatetimeLineGraphData($amount, $unit, array('points')); $queryBuilder->select('lp.lead_id as lead, lp.date_added as dateAdded, lp.delta'); $queryBuilder->andwhere($queryBuilder->expr()->gte('lp.date_added', ':date'))->setParameter('date', $timeStats['fromDate']->format('Y-m-d H:i:s')); $points = $queryBuilder->execute()->fetchAll(); $timeStats = GraphHelper::mergeLineGraphData($timeStats, $points, $unit, 0, 'dateAdded', 'delta'); $timeStats['name'] = 'mautic.lead.graph.line.points'; $event->setGraph($g, $timeStats); break; case 'mautic.lead.table.most.points': $queryBuilder->select('l.id, l.email as title, sum(lp.delta) as points')->groupBy('l.id, l.email')->orderBy('points', 'DESC'); $limit = 10; $offset = 0; $items = $pointLogRepo->getMostPoints($queryBuilder, $limit, $offset); $graphData = array(); $graphData['data'] = $items; $graphData['name'] = 'mautic.lead.table.most.points'; $graphData['iconClass'] = 'fa-asterisk'; $graphData['link'] = 'mautic_lead_action'; $event->setGraph($g, $graphData); break; case 'mautic.lead.table.top.countries': $queryBuilder->select('l.country as title, count(l.country) as quantity')->groupBy('l.country')->orderBy('quantity', 'DESC'); $limit = 10; $offset = 0; $items = $pointLogRepo->getMostLeads($queryBuilder, $limit, $offset); $graphData = array(); $graphData['data'] = $items; $graphData['name'] = 'mautic.lead.table.top.countries'; $graphData['iconClass'] = 'fa-globe'; $event->setGraph($g, $graphData); break; case 'mautic.lead.table.top.cities': $queryBuilder->select('l.city as title, count(l.city) as quantity')->groupBy('l.city')->orderBy('quantity', 'DESC'); $limit = 10; $offset = 0; $items = $pointLogRepo->getMostLeads($queryBuilder, $limit, $offset); $graphData = array(); $graphData['data'] = $items; $graphData['name'] = 'mautic.lead.table.top.cities'; $graphData['iconClass'] = 'fa-university'; $event->setGraph($g, $graphData); break; case 'mautic.lead.table.top.events': $queryBuilder->select('lp.event_name as title, count(lp.event_name) as events')->groupBy('lp.event_name')->orderBy('events', 'DESC'); $limit = 10; $offset = 0; $items = $pointLogRepo->getMostPoints($queryBuilder, $limit, $offset); $graphData = array(); $graphData['data'] = $items; $graphData['name'] = 'mautic.lead.table.top.events'; $graphData['iconClass'] = 'fa-calendar'; $event->setGraph($g, $graphData); break; case 'mautic.lead.table.top.actions': $queryBuilder->select('lp.action_name as title, count(lp.action_name) as actions')->groupBy('lp.action_name')->orderBy('actions', 'DESC'); $limit = 10; $offset = 0; $items = $pointLogRepo->getMostPoints($queryBuilder, $limit, $offset); $graphData = array(); $graphData['data'] = $items; $graphData['name'] = 'mautic.lead.table.top.actions'; $graphData['iconClass'] = 'fa-bolt'; $event->setGraph($g, $graphData); break; } unset($queryBuilder); } }
/** * @param int|Notification $notification * @param int $amount * @param string $unit * * @return array */ public function getNotificationGeneralStats($notification, $amount = 30, $unit = 'D') { if (!$notification instanceof Notification) { $notification = $this->getEntity($notification); } $notificationIds = array($notification->getId()); /** @var \Mautic\NotificationBundle\Entity\StatRepository $statRepo */ $statRepo = $this->em->getRepository('MauticNotificationBundle:Stat'); $graphData = GraphHelper::prepareDatetimeLineGraphData($amount, $unit, array($this->translator->trans('mautic.notification.stat.sent'), $this->translator->trans('mautic.notification.stat.read'))); $fromDate = $graphData['fromDate']; $sentData = $statRepo->getNotificationStats($notificationIds, $fromDate, 'sent'); $graphData = GraphHelper::mergeLineGraphData($graphData, $sentData, $unit, 0, 'date', 'data'); $readData = $statRepo->getNotificationStats($notificationIds, $fromDate, 'read'); $graphData = GraphHelper::mergeLineGraphData($graphData, $readData, $unit, 1, 'date', 'data'); return $graphData; }
/** * Initialize the QueryBuilder object to generate reports from * * @param ReportGeneratorEvent $event * * @return void */ public function onReportGraphGenerate(ReportGraphEvent $event) { // Context check, we only want to fire for Lead reports if (!$event->checkContext('form.submissions')) { return; } $graphs = $event->getRequestedGraphs(); $qb = $event->getQueryBuilder(); $submissionRepo = $this->factory->getEntityManager()->getRepository('MauticFormBundle:Submission'); foreach ($graphs as $g) { $options = $event->getOptions($g); $queryBuilder = clone $qb; switch ($g) { case 'mautic.form.graph.line.submissions': // Generate data for submissions line graph $unit = 'D'; $amount = 30; if (isset($options['amount'])) { $amount = $options['amount']; } if (isset($options['unit'])) { $unit = $options['unit']; } $data = GraphHelper::prepareDatetimeLineGraphData($amount, $unit, array('submissions')); $queryBuilder->select('fs.form_id as form, fs.date_submitted as "dateSubmitted"'); $queryBuilder->andwhere($queryBuilder->expr()->gte('fs.date_submitted', ':date'))->setParameter('date', $data['fromDate']->format('Y-m-d H:i:s')); $submissions = $queryBuilder->execute()->fetchAll(); $timeStats = GraphHelper::mergeLineGraphData($data, $submissions, $unit, 0, 'dateSubmitted'); $timeStats['name'] = 'mautic.form.graph.line.submissions'; $event->setGraph($g, $timeStats); break; case 'mautic.form.table.top.referrers': $limit = 10; $offset = 0; $items = $submissionRepo->getTopReferrers($queryBuilder, $limit, $offset); $graphData = array(); $graphData['data'] = $items; $graphData['name'] = 'mautic.form.table.top.referrers'; $graphData['iconClass'] = 'fa-sign-in'; $graphData['link'] = 'mautic_form_action'; $event->setGraph($g, $graphData); break; case 'mautic.form.table.most.submitted': $limit = 10; $offset = 0; $items = $submissionRepo->getMostSubmitted($queryBuilder, $limit, $offset); $graphData = array(); $graphData['data'] = $items; $graphData['name'] = 'mautic.form.table.most.submitted'; $graphData['iconClass'] = 'fa-check-square-o'; $graphData['link'] = 'mautic_form_action'; $event->setGraph($g, $graphData); break; } unset($queryBuilder); } }
/** * Prepare data structure for New vs Returning graph * * @param array $languages * * @return array */ public function getLaguageGraphData($languages) { return GraphHelper::preparePieGraphData($languages); }
/** * Get a stats for email by list * * @param Email|int $email * @param bool $includeVariants * * @return array */ public function getEmailListStats($email, $includeVariants = false) { if (!$email instanceof Email) { $email = $this->getEntity($email); } if ($includeVariants && $email->isVariant()) { $parent = $email->getVariantParent(); if ($parent) { // $email is a variant of another $children = $parent->getVariantChildren(); $emailIds = $children->getKeys(); $emailIds[] = $parent->getId(); } else { $children = $email->getVariantChildren(); $emailIds = $children->getKeys(); $emailIds[] = $email->getId(); } } else { $emailIds = array($email->getId()); } $lists = $email->getLists(); $listCount = count($lists); $combined = $this->translator->trans('mautic.email.lists.combined'); $datasets = array($combined => array(0, 0, 0)); $labels = array($this->translator->trans('mautic.email.sent'), $this->translator->trans('mautic.email.read'), $this->translator->trans('mautic.email.failed')); if ($listCount) { /** @var \Mautic\EmailBundle\Entity\StatRepository $statRepo */ $statRepo = $this->em->getRepository('MauticEmailBundle:Stat'); foreach ($lists as $l) { $name = $l->getName(); $sentCount = $statRepo->getSentCount($emailIds, $l->getId()); $datasets[$combined][0] += $sentCount; $readCount = $statRepo->getReadCount($emailIds, $l->getId()); $datasets[$combined][1] += $readCount; $failedCount = $statRepo->getFailedCount($emailIds, $l->getId()); $datasets[$combined][2] += $failedCount; $datasets[$name] = array(); $datasets[$name] = array($sentCount, $readCount, $failedCount); $datasets[$name]['datasetKey'] = $l->getId(); } } if ($listCount === 1) { unset($datasets[$combined]); } $data = GraphHelper::prepareBarGraphData($labels, $datasets); return $data; }
/** * Initialize the QueryBuilder object to generate reports from * * @param ReportGraphEvent $event * * @return void */ public function onReportGraphGenerate(ReportGraphEvent $event) { // Context check, we only want to fire for Lead reports if (!$event->checkContext('page.hits')) { return; } $graphs = $event->getRequestedGraphs(); $qb = $event->getQueryBuilder(); $hitRepo = $this->factory->getEntityManager()->getRepository('MauticPageBundle:Hit'); foreach ($graphs as $g) { $options = $event->getOptions($g); $queryBuilder = clone $qb; switch ($g) { case 'mautic.page.graph.line.hits': // Generate data for Downloads line graph $unit = 'D'; $amount = 30; if (isset($options['amount'])) { $amount = $options['amount']; } if (isset($options['unit'])) { $unit = $options['unit']; } $data = GraphHelper::prepareDatetimeLineGraphData($amount, $unit, array('dateHit')); $queryBuilder->select('ph.page_id as page, ph.date_hit as "dateHit"'); $queryBuilder->andwhere($queryBuilder->expr()->gte('ph.date_hit', ':date'))->setParameter('date', $data['fromDate']->format('Y-m-d H:i:s')); $hits = $queryBuilder->execute()->fetchAll(); $timeStats = GraphHelper::mergeLineGraphData($data, $hits, $unit, 0, 'dateHit'); $timeStats['name'] = 'mautic.page.graph.line.hits'; $event->setGraph($g, $timeStats); break; case 'mautic.page.graph.line.time.on.site': // Generate data for Downloads line graph $unit = 'D'; $amount = 30; if (isset($options['amount'])) { $amount = $options['amount']; } if (isset($options['unit'])) { $unit = $options['unit']; } $data = GraphHelper::prepareDatetimeLineGraphData($amount, $unit, array('dateHit')); $queryBuilder->select('ph.page_id as page, ph.date_hit as "dateHit", ph.date_left as "dateLeft"'); $queryBuilder->andwhere($queryBuilder->expr()->gte('ph.date_hit', ':date'))->setParameter('date', $data['fromDate']->format('Y-m-d H:i:s')); $hits = $queryBuilder->execute()->fetchAll(); // Count time on site foreach ($hits as $key => $hit) { if ($hit['dateLeft']) { $dateHit = new \DateTime($hit['dateHit']); $dateLeft = new \DateTime($hit['dateLeft']); $hits[$key]['timeOnSite'] = $dateLeft->getTimestamp() - $dateHit->getTimestamp(); $hits[$key]['timeOnSiteDate'] = $hit['dateHit']; } else { $hits[$key]['timeOnSite'] = 0; $hits[$key]['timeOnSiteDate'] = $hit['dateHit']; } unset($hits[$key]['dateLeft']); } $timeStats = GraphHelper::mergeLineGraphData($data, $hits, $unit, 0, 'dateHit', 'timeOnSite', true); $timeStats['name'] = 'mautic.page.graph.line.time.on.site'; $event->setGraph($g, $timeStats); break; case 'mautic.page.graph.pie.time.on.site': $hitStats = $hitRepo->getDwellTimes(array(), $queryBuilder); $graphData = array(); $graphData['data'] = $hitStats['timesOnSite']; $graphData['name'] = 'mautic.page.graph.pie.time.on.site'; $graphData['iconClass'] = 'fa-clock-o'; $event->setGraph($g, $graphData); break; case 'mautic.page.graph.pie.new.vs.returning': if (!isset($hitstats)) { $hitStats = $hitRepo->getDwellTimes(array(), $queryBuilder); } $graphData = array(); $graphData['data'] = $hitStats['newVsReturning']; $graphData['name'] = 'mautic.page.graph.pie.new.vs.returning'; $graphData['iconClass'] = 'fa-bookmark-o'; $event->setGraph($g, $graphData); break; case 'mautic.page.graph.pie.languages': if (!isset($hitstats)) { $hitStats = $hitRepo->getDwellTimes(array(), $queryBuilder); } $graphData = array(); $graphData['data'] = $hitStats['languages']; $graphData['name'] = 'mautic.page.graph.pie.languages'; $graphData['iconClass'] = 'fa-globe'; $event->setGraph($g, $graphData); break; case 'mautic.page.table.referrers': $limit = 10; $offset = 0; $items = $hitRepo->getReferers($queryBuilder, $limit, $offset); $graphData = array(); $graphData['data'] = $items; $graphData['name'] = 'mautic.page.table.referrers'; $graphData['iconClass'] = 'fa-sign-in'; $event->setGraph($g, $graphData); break; case 'mautic.page.table.most.visited': $limit = 10; $offset = 0; $items = $hitRepo->getMostVisited($queryBuilder, $limit, $offset); $graphData = array(); $graphData['data'] = $items; $graphData['name'] = 'mautic.page.table.most.visited'; $graphData['iconClass'] = 'fa-eye'; $graphData['link'] = 'mautic_page_action'; $event->setGraph($g, $graphData); break; case 'mautic.page.table.most.visited.unique': $limit = 10; $offset = 0; $items = $hitRepo->getMostVisited($queryBuilder, $limit, $offset, 'p.unique_hits', 'sessions'); $graphData = array(); $graphData['data'] = $items; $graphData['name'] = 'mautic.page.table.most.visited.unique'; $graphData['iconClass'] = 'fa-eye'; $graphData['link'] = 'mautic_page_action'; $event->setGraph($g, $graphData); break; } unset($queryBuilder); } }
<?php /** * @package Mautic * @copyright 2014 Mautic Contributors. All rights reserved. * @author Mautic * @link http://mautic.org * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html */ $support = $results['support']; $label = $view['translator']->trans($variants['criteria'][$results['basedOn']]['label']); $barData = \Mautic\CoreBundle\Helper\GraphHelper::prepareBarGraphData($support['labels'], $support['data']); ?> <div class="panel ovf-h bg-auto bg-light-xs abtest-bar-chart"> <div class="panel-body box-layout"> <div class="col-xs-8 va-m"> <h5 class="text-white dark-md fw-sb mb-xs"> <?php echo $label; ?> </h5> </div> <div class="col-xs-4 va-t text-right"> <h3 class="text-white dark-sm"><span class="fa fa-bar-chart"></span></h3> </div> </div> <div class="row"> <div class="col-sm-7"> <canvas id="abtest-bar-chart" height="300"></canvas> </div> <div class="col-sm-5">
/** * Initialize the QueryBuilder object to generate reports from * * @param ReportGraphEvent $event * * @return void */ public function onReportGraphGenerate(ReportGraphEvent $event) { // Context check, we only want to fire for Lead reports if (!$event->checkContext('asset.downloads')) { return; } $graphs = $event->getRequestedGraphs(); $qb = $event->getQueryBuilder(); $downloadRepo = $this->factory->getEntityManager()->getRepository('MauticAssetBundle:Download'); foreach ($graphs as $g) { $options = $event->getOptions($g); $queryBuilder = clone $qb; switch ($g) { case 'mautic.asset.graph.line.downloads': // Generate data for Downloads line graph $unit = 'D'; $amount = 30; if (isset($options['amount'])) { $amount = $options['amount']; } if (isset($options['unit'])) { $unit = $options['unit']; } $data = GraphHelper::prepareDatetimeLineGraphData($amount, $unit, array('downloaded')); $queryBuilder->select('ad.asset_id as asset, ad.date_download as "dateDownload"'); $queryBuilder->andwhere($queryBuilder->expr()->gte('ad.date_download', ':date'))->setParameter('date', $data['fromDate']->format('Y-m-d H:i:s')); $downloads = $queryBuilder->execute()->fetchAll(); $timeStats = GraphHelper::mergeLineGraphData($data, $downloads, $unit, 0, 'dateDownload'); $timeStats['name'] = 'mautic.asset.graph.line.downloads'; $event->setGraph($g, $timeStats); break; case 'mautic.asset.table.most.downloaded': $limit = 10; $offset = 0; $items = $downloadRepo->getMostDownloaded($queryBuilder, $limit, $offset); $graphData = array(); $graphData['data'] = $items; $graphData['name'] = 'mautic.asset.table.most.downloaded'; $graphData['iconClass'] = 'fa-download'; $graphData['link'] = 'mautic_asset_action'; $event->setGraph($g, $graphData); break; case 'mautic.asset.table.top.referrers': $limit = 10; $offset = 0; $items = $downloadRepo->getTopReferrers($queryBuilder, $limit, $offset); $graphData = array(); $graphData['data'] = $items; $graphData['name'] = 'mautic.asset.table.top.referrers'; $graphData['iconClass'] = 'fa-download'; $graphData['link'] = 'mautic_asset_action'; $event->setGraph($g, $graphData); break; case 'mautic.asset.graph.pie.statuses': $items = $downloadRepo->getHttpStatuses($queryBuilder); $graphData = array(); $graphData['data'] = $items; $graphData['name'] = 'mautic.asset.graph.pie.statuses'; $graphData['iconClass'] = 'fa-globe'; $event->setGraph($g, $graphData); break; } unset($queryBuilder); } }
/** * @param int $emailId * @param int $amount * @param string $unit * * @return array */ public function getEmailGeneralStats($emailId, $amount = 30, $unit = 'D') { $statRepo = $this->em->getRepository('MauticEmailBundle:Stat'); $graphData = GraphHelper::prepareDatetimeLineGraphData($amount, $unit, array($this->translator->trans('mautic.email.stat.sent'), $this->translator->trans('mautic.email.stat.read'), $this->translator->trans('mautic.email.stat.failed'))); $fromDate = $graphData['fromDate']; $sentData = $statRepo->getEmailStats($emailId, $fromDate, 'sent'); $graphData = GraphHelper::mergeLineGraphData($graphData, $sentData, $unit, 0, 'date', 'data'); $readData = $statRepo->getEmailStats($emailId, $fromDate, 'read'); $graphData = GraphHelper::mergeLineGraphData($graphData, $readData, $unit, 1, 'date', 'data'); $failedData = $statRepo->getEmailStats($emailId, $fromDate, 'failed'); $graphData = GraphHelper::mergeLineGraphData($graphData, $failedData, $unit, 2, 'date', 'data'); return $graphData; }
/** * Fetch Lead stats for some period of time. * * @param integer $quantity of units * @param string $unit of time php.net/manual/en/class.dateinterval.php#dateinterval.props * @param array $options * * @return mixed * @throws \Doctrine\ORM\NoResultException * @throws \Doctrine\ORM\NonUniqueResultException */ public function getLeadStats($quantity, $unit, $options = array()) { $graphData = GraphHelper::prepareDatetimeLineGraphData($quantity, $unit, array('viewed')); // Load points for selected period $q = $this->_em->getConnection()->createQueryBuilder(); $q->select('cl.date_added')->from(MAUTIC_TABLE_PREFIX . 'campaign_leads', 'cl'); $utc = new \DateTimeZone('UTC'); $graphData['fromDate']->setTimezone($utc); $q->andwhere($q->expr()->andX($q->expr()->gte('cl.date_added', ':date'), $q->expr()->eq('cl.manually_removed', ':false')))->setParameter('date', $graphData['fromDate']->format('Y-m-d H:i:s'))->setParameter('false', false, 'boolean')->orderBy('cl.date_added', 'ASC'); if (isset($options['campaign_id'])) { $q->andwhere($q->expr()->gte('cl.campaign_id', (int) $options['campaign_id'])); } $leads = $q->execute()->fetchAll(); $total = false; if (isset($options['total']) && $options['total']) { // Count total until date $q->select('count(cl.lead_id) as total'); $total = $q->execute()->fetchAll(); $total = (int) $total[0]['total']; } return GraphHelper::mergeLineGraphData($graphData, $leads, $unit, 0, 'date_added', null, false, $total); }
/** * Loads a specific lead into the detailed panel * * @param $objectId * * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response */ public function viewAction($objectId) { /** @var \Mautic\LeadBundle\Model\LeadModel $model */ $model = $this->factory->getModel('lead.lead'); /** @var \Mautic\LeadBundle\Entity\Lead $lead */ $lead = $model->getEntity($objectId); //set the page we came from $page = $this->factory->getSession()->get('mautic.lead.page', 1); //set some permissions $permissions = $this->factory->getSecurity()->isGranted(array('lead:leads:viewown', 'lead:leads:viewother', 'lead:leads:create', 'lead:leads:editown', 'lead:leads:editother', 'lead:leads:deleteown', 'lead:leads:deleteother'), "RETURN_ARRAY"); if ($lead === null) { //set the return URL $returnUrl = $this->generateUrl('mautic_lead_index', array('page' => $page)); return $this->postActionRedirect(array('returnUrl' => $returnUrl, 'viewParameters' => array('page' => $page), 'contentTemplate' => 'MauticLeadBundle:Lead:index', 'passthroughVars' => array('activeLink' => '#mautic_lead_index', 'mauticContent' => 'lead'), 'flashes' => array(array('type' => 'error', 'msg' => 'mautic.lead.lead.error.notfound', 'msgVars' => array('%id%' => $objectId))))); } if (!$this->factory->getSecurity()->hasEntityAccess('lead:leads:viewown', 'lead:leads:viewother', $lead->getOwner())) { return $this->accessDenied(); } $filters = $this->factory->getSession()->get('mautic.lead.' . $lead->getId() . '.timeline.filters', array('search' => '', 'includeEvents' => array(), 'excludeEvents' => array())); // Trigger the TIMELINE_ON_GENERATE event to fetch the timeline events from subscribed bundles $dispatcher = $this->factory->getDispatcher(); $event = new LeadTimelineEvent($lead, $filters); $dispatcher->dispatch(LeadEvents::TIMELINE_ON_GENERATE, $event); $eventsByDate = $event->getEvents(true); $eventTypes = $event->getEventTypes(); // Get an engagement count $translator = $this->factory->getTranslator(); $graphData = GraphHelper::prepareDatetimeLineGraphData(6, 'M', array($translator->trans('mautic.lead.graph.line.all_engagements'), $translator->trans('mautic.lead.graph.line.points'))); $fromDate = $graphData['fromDate']; $allEngagements = array(); $total = 0; $events = array(); foreach ($eventsByDate as $eventDate => $dateEvents) { $datetime = \DateTime::createFromFormat('Y-m-d H:i:s', $eventDate); if ($datetime > $fromDate) { $total++; $allEngagements[] = array('date' => $datetime, 'data' => 1); } $events = array_merge($events, array_reverse($dateEvents)); } $graphData = GraphHelper::mergeLineGraphData($graphData, $allEngagements, 'M', 0, 'date', 'data', false, false); /** @var \Mautic\LeadBundle\Entity\PointChangeLogRepository $pointsLogRepository */ $pointsLogRepository = $this->factory->getEntityManager()->getRepository('MauticLeadBundle:PointsChangeLog'); $pointStats = $pointsLogRepository->getLeadPoints($fromDate, array('lead_id' => $lead->getId())); $engagementGraphData = GraphHelper::mergeLineGraphData($graphData, $pointStats, 'M', 1, 'date', 'data', false, false); // Upcoming events from Campaign Bundle /** @var \Mautic\CampaignBundle\Entity\LeadEventLogRepository $leadEventLogRepository */ $leadEventLogRepository = $this->factory->getEntityManager()->getRepository('MauticCampaignBundle:LeadEventLog'); $upcomingEvents = $leadEventLogRepository->getUpcomingEvents(array('lead' => $lead, 'scheduled' => 1, 'eventType' => 'action')); $fields = $lead->getFields(); $integrationHelper = $this->factory->getHelper('integration'); $socialProfiles = $integrationHelper->getUserProfiles($lead, $fields); $socialProfileUrls = $integrationHelper->getSocialProfileUrlRegex(false); $event = new IconEvent($this->factory->getSecurity()); $this->factory->getDispatcher()->dispatch(CoreEvents::FETCH_ICONS, $event); $icons = $event->getIcons(); // We need the EmailRepository to check if a lead is flagged as do not contact /** @var \Mautic\EmailBundle\Entity\EmailRepository $emailRepo */ $emailRepo = $this->factory->getModel('email')->getRepository(); return $this->delegateView(array('viewParameters' => array('lead' => $lead, 'fields' => $fields, 'socialProfiles' => $socialProfiles, 'socialProfileUrls' => $socialProfileUrls, 'security' => $this->factory->getSecurity(), 'permissions' => $permissions, 'events' => $events, 'eventTypes' => $eventTypes, 'eventFilters' => $filters, 'upcomingEvents' => $upcomingEvents, 'icons' => $icons, 'engagementData' => $engagementGraphData, 'noteCount' => $this->factory->getModel('lead.note')->getNoteCount($lead, true), 'doNotContact' => $emailRepo->checkDoNotEmail($fields['core']['email']['value']), 'leadNotes' => $this->forward('MauticLeadBundle:Note:index', array('leadId' => $lead->getId(), 'ignoreAjax' => 1))->getContent()), 'contentTemplate' => 'MauticLeadBundle:Lead:lead.html.php', 'passthroughVars' => array('activeLink' => '#mautic_lead_index', 'mauticContent' => 'lead', 'route' => $this->generateUrl('mautic_lead_action', array('objectAction' => 'view', 'objectId' => $lead->getId()))))); }
/** * Fetch Lead stats for some period of time. * * @param integer $quantity of units * @param string $unit of time php.net/manual/en/class.dateinterval.php#dateinterval.props * @param array $options * * @return mixed * @throws \Doctrine\ORM\NoResultException * @throws \Doctrine\ORM\NonUniqueResultException */ public function getLeadStats($quantity, $unit, $options = array()) { $graphData = GraphHelper::prepareDatetimeLineGraphData($quantity, $unit, array('viewed')); // Load points for selected period $q = $this->getEntityManager()->getConnection()->createQueryBuilder(); $q->select(sprintf('count(*) as count, DATE(cl.date_added) as date_added'))->from(MAUTIC_TABLE_PREFIX . 'campaign_leads', 'cl'); $utc = new \DateTimeZone('UTC'); $graphData['fromDate']->setTimezone($utc); $q->andwhere($q->expr()->andX($q->expr()->gte('cl.date_added', ':date'), $q->expr()->eq('cl.manually_removed', ':false')))->setParameter('date', $graphData['fromDate']->format('Y-m-d H:i:s'))->setParameter('false', false, 'boolean')->groupBy('DATE(cl.date_added)')->orderBy('date_added', 'ASC'); if (isset($options['campaign_id'])) { $q->andwhere($q->expr()->gte('cl.campaign_id', (int) $options['campaign_id'])); } $datesAdded = $q->execute()->fetchAll(); $format = GraphHelper::getDateLabelFormat($unit); $formattedDates = array(); $dt = new DateTimeHelper(); foreach ($datesAdded as &$date) { $dt->setDateTime($date['date_added'], 'Y-m-d', 'utc'); $key = $dt->getDateTime()->format($format); $formattedDates[$key] = (int) $date['count']; } foreach ($graphData['labels'] as $key => $label) { $graphData['datasets'][0]['data'][$key] = isset($formattedDates[$label]) ? $formattedDates[$label] : 0; } unset($graphData['fromDate']); return $graphData; }
/** * @param int|Email $email * @param bool $includeVariants * @param int $amount * @param string $unit * * @return array */ public function getEmailGeneralStats($email, $includeVariants = false, $amount = 30, $unit = 'D') { if (!$email instanceof Email) { $email = $this->getEntity($email); } if ($includeVariants && $email->isVariant()) { $parent = $email->getVariantParent(); if ($parent) { // $email is a variant of another $children = $parent->getVariantChildren(); $emailIds = $children->getKeys(); $emailIds[] = $parent->getId(); } else { $children = $email->getVariantChildren(); $emailIds = $children->getKeys(); $emailIds[] = $email->getId(); } } else { $emailIds = array($email->getId()); } /** @var \Mautic\EmailBundle\Entity\StatRepository $statRepo */ $statRepo = $this->em->getRepository('MauticEmailBundle:Stat'); $graphData = GraphHelper::prepareDatetimeLineGraphData($amount, $unit, array($this->translator->trans('mautic.email.stat.sent'), $this->translator->trans('mautic.email.stat.read'), $this->translator->trans('mautic.email.stat.failed'))); $fromDate = $graphData['fromDate']; $sentData = $statRepo->getEmailStats($emailIds, $fromDate, 'sent'); $graphData = GraphHelper::mergeLineGraphData($graphData, $sentData, $unit, 0, 'date', 'data'); $readData = $statRepo->getEmailStats($emailIds, $fromDate, 'read'); $graphData = GraphHelper::mergeLineGraphData($graphData, $readData, $unit, 1, 'date', 'data'); $failedData = $statRepo->getEmailStats($emailIds, $fromDate, 'failed'); $graphData = GraphHelper::mergeLineGraphData($graphData, $failedData, $unit, 2, 'date', 'data'); return $graphData; }
/** * @param int|Sms $sms * @param int $amount * @param string $unit * * @return array */ public function getSmsGeneralStats($sms, $amount = 30, $unit = 'D') { if (!$sms instanceof Sms) { $sms = $this->getEntity($sms); } $smsIds = array($sms->getId()); /** @var \Mautic\SmsBundle\Entity\StatRepository $statRepo */ $statRepo = $this->em->getRepository('MauticSmsBundle:Stat'); $graphData = GraphHelper::prepareDatetimeLineGraphData($amount, $unit, array($this->translator->trans('mautic.sms.stat.sent'))); $fromDate = $graphData['fromDate']; $sentData = $statRepo->getSmsStats($smsIds, $fromDate, 'sent'); $graphData = GraphHelper::mergeLineGraphData($graphData, $sentData, $unit, 0, 'date', 'data'); return $graphData; }