Exemplo n.º 1
0
 /**
  * Initialize the QueryBuilder object to generate reports from.
  *
  * @param ReportGraphEvent $event
  */
 public function onReportGraphGenerate(ReportGraphEvent $event)
 {
     // Context check, we only want to fire for Lead reports
     if (!$event->checkContext(['leads', 'lead.pointlog', 'contact.attribution.multi'])) {
         return;
     }
     $graphs = $event->getRequestedGraphs();
     $qb = $event->getQueryBuilder();
     $pointLogRepo = $this->leadModel->getPointLogRepository();
     foreach ($graphs as $g) {
         $queryBuilder = clone $qb;
         $options = $event->getOptions($g);
         /** @var ChartQuery $chartQuery */
         $chartQuery = clone $options['chartQuery'];
         $attributionQb = clone $queryBuilder;
         $chartQuery->applyDateFilters($queryBuilder, 'date_added', 'l');
         switch ($g) {
             case 'mautic.lead.graph.pie.attribution_stages':
             case 'mautic.lead.graph.pie.attribution_campaigns':
             case 'mautic.lead.graph.pie.attribution_actions':
             case 'mautic.lead.graph.pie.attribution_channels':
                 $attributionQb->resetQueryParts(['select', 'orderBy']);
                 $outerQb = clone $attributionQb;
                 $outerQb->resetQueryParts()->select('slice, sum(contact_attribution) as total_attribution')->groupBy('slice');
                 $groupBy = str_replace('mautic.lead.graph.pie.attribution_', '', $g);
                 switch ($groupBy) {
                     case 'stages':
                         $attributionQb->select('CONCAT_WS(\':\', s.id, s.name) as slice, l.attribution as contact_attribution')->groupBy('l.id, s.id');
                         break;
                     case 'campaigns':
                         $attributionQb->select('CONCAT_WS(\':\', c.id, c.name) as slice, l.attribution as contact_attribution')->groupBy('l.id, c.id');
                         break;
                     case 'actions':
                         $attributionQb->select('SUBSTRING_INDEX(e.type, \'.\', -1) as slice, l.attribution as contact_attribution')->groupBy('l.id, SUBSTRING_INDEX(e.type, \'.\', -1)');
                         break;
                     case 'channels':
                         $attributionQb->select('SUBSTRING_INDEX(e.type, \'.\', 1) as slice, l.attribution as contact_attribution')->groupBy('l.id, SUBSTRING_INDEX(e.type, \'.\', 1)');
                         break;
                 }
                 $outerQb->from(sprintf('(%s) subq', $attributionQb->getSQL()));
                 $outerQb->setParameters($attributionQb->getParameters());
                 $chart = new PieChart();
                 $data = $outerQb->execute()->fetchAll();
                 foreach ($data as $row) {
                     switch ($groupBy) {
                         case 'actions':
                             $label = $this->channelActions[$row['slice']];
                             break;
                         case 'channels':
                             $label = $this->channels[$row['slice']];
                             break;
                         default:
                             $label = empty($row['slice']) ? $this->translator->trans('mautic.core.none') : $row['slice'];
                     }
                     $chart->setDataset($label, $row['total_attribution']);
                 }
                 $event->setGraph($g, ['data' => $chart->render(), 'name' => $g, 'iconClass' => 'fa-dollar']);
                 break;
             case 'mautic.lead.graph.line.leads':
                 $chart = new LineChart(null, $options['dateFrom'], $options['dateTo']);
                 $chartQuery->modifyTimeDataQuery($queryBuilder, 'date_added', 'l');
                 $leads = $chartQuery->loadAndBuildTimeData($queryBuilder);
                 $chart->setDataset($options['translator']->trans('mautic.lead.all.leads'), $leads);
                 $queryBuilder->andwhere($qb->expr()->isNotNull('l.date_identified'));
                 $identified = $chartQuery->loadAndBuildTimeData($queryBuilder);
                 $chart->setDataset($options['translator']->trans('mautic.lead.identified'), $identified);
                 $data = $chart->render();
                 $data['name'] = $g;
                 $event->setGraph($g, $data);
                 break;
             case 'mautic.lead.graph.line.points':
                 $chart = new LineChart(null, $options['dateFrom'], $options['dateTo']);
                 $chartQuery->modifyTimeDataQuery($queryBuilder, 'date_added', 'lp');
                 $leads = $chartQuery->loadAndBuildTimeData($queryBuilder);
                 $chart->setDataset($options['translator']->trans('mautic.lead.graph.line.points'), $leads);
                 $data = $chart->render();
                 $data['name'] = $g;
                 $event->setGraph($g, $data);
                 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 = [];
                 $graphData['data'] = $items;
                 $graphData['name'] = $g;
                 $graphData['iconClass'] = 'fa-asterisk';
                 $graphData['link'] = 'mautic_contact_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 = [];
                 $graphData['data'] = $items;
                 $graphData['name'] = $g;
                 $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 = [];
                 $graphData['data'] = $items;
                 $graphData['name'] = $g;
                 $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 = [];
                 $graphData['data'] = $items;
                 $graphData['name'] = $g;
                 $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 = [];
                 $graphData['data'] = $items;
                 $graphData['name'] = $g;
                 $graphData['iconClass'] = 'fa-bolt';
                 $event->setGraph($g, $graphData);
                 break;
         }
         unset($queryBuilder);
     }
 }
Exemplo n.º 2
0
 /**
  * Get pie chart data of dwell times
  *
  * @param string  $dateFrom
  * @param string  $dateTo
  * @param array   $filters
  * @param boolean $canViewOthers
  *
  * @return array
  */
 public function getAnonymousVsIdentifiedPieChartData($dateFrom, $dateTo, $filters = array(), $canViewOthers = true)
 {
     $chart = new PieChart();
     $query = new ChartQuery($this->em->getConnection(), $dateFrom, $dateTo);
     if (!$canViewOthers) {
         $filter['owner_id'] = $this->factory->getUser()->getId();
     }
     $identified = $query->count('leads', 'date_identified', 'date_added', $filters);
     $all = $query->count('leads', 'id', 'date_added', $filters);
     $chart->setDataset($this->factory->getTranslator()->trans('mautic.lead.identified'), $identified);
     $chart->setDataset($this->factory->getTranslator()->trans('mautic.lead.lead.anonymous'), $all - $identified);
     return $chart->render();
 }
Exemplo n.º 3
0
 /**
  * Get pie chart data of ignored vs opened emails
  *
  * @param string  $dateFrom
  * @param string  $dateTo
  * @param array   $filters
  * @param boolean $canViewOthers
  *
  * @return array
  */
 public function getDeviceGranularityPieChartData($dateFrom, $dateTo, $canViewOthers = true)
 {
     $chart = new PieChart();
     $deviceStats = $this->getStatDeviceRepository()->getDeviceStats(null, $dateFrom, $dateTo);
     foreach ($deviceStats as $device) {
         $chart->setDataset($device['device'], $device['count']);
     }
     return $chart->render();
 }
Exemplo n.º 4
0
 /**
  * Get pie chart data of ignored vs opened emails
  *
  * @param string  $dateFrom
  * @param string  $dateTo
  * @param array   $filters
  * @param boolean $canViewOthers
  *
  * @return array
  */
 public function getIgnoredVsReadPieChartData($dateFrom, $dateTo, $filters = array(), $canViewOthers = true)
 {
     $chart = new PieChart();
     $query = new ChartQuery($this->em->getConnection(), $dateFrom, $dateTo);
     $readFilters = $filters;
     $readFilters['is_read'] = true;
     $failedFilters = $filters;
     $failedFilters['is_failed'] = true;
     $sentQ = $query->getCountQuery('email_stats', 'id', 'date_sent', $filters);
     $readQ = $query->getCountQuery('email_stats', 'id', 'date_sent', $readFilters);
     $failedQ = $query->getCountQuery('email_stats', 'id', 'date_sent', $failedFilters);
     if (!$canViewOthers) {
         $this->limitQueryToCreator($sentQ);
         $this->limitQueryToCreator($readQ);
         $this->limitQueryToCreator($failedQ);
     }
     $sent = $query->fetchCount($sentQ);
     $read = $query->fetchCount($readQ);
     $failed = $query->fetchCount($failedQ);
     $chart->setDataset($this->factory->getTranslator()->trans('mautic.email.graph.pie.ignored.read.failed.ignored'), $sent - $read - $failed);
     $chart->setDataset($this->factory->getTranslator()->trans('mautic.email.graph.pie.ignored.read.failed.read'), $read);
     $chart->setDataset($this->factory->getTranslator()->trans('mautic.email.graph.pie.ignored.read.failed.failed'), $failed);
     return $chart->render();
 }
Exemplo n.º 5
0
 /**
  * Get bar chart data of hits.
  *
  * @param char     $unit       {@link php.net/manual/en/function.date.php#refsect1-function.date-parameters}
  * @param DateTime $dateFrom
  * @param DateTime $dateTo
  * @param string   $dateFormat
  * @param array    $filter
  *
  * @return array
  */
 public function getDeviceGranularityData(\DateTime $dateFrom, \DateTime $dateTo, $filters = [], $canViewOthers = true)
 {
     $data['values'] = [];
     $data['labels'] = [];
     $q = $this->em->getConnection()->createQueryBuilder();
     $q->select('count(h.id) as count, ds.device as device')->from(MAUTIC_TABLE_PREFIX . 'page_hits', 'h')->join('h', MAUTIC_TABLE_PREFIX . 'lead_devices', 'ds', 'ds.id=h.device_id')->orderBy('device', 'DESC')->andWhere($q->expr()->gte('h.date_hit', ':date_from'))->setParameter('date_from', $dateFrom->format('Y-m-d'))->andWhere($q->expr()->lte('h.date_hit', ':date_to'))->setParameter('date_to', $dateTo->format('Y-m-d' . ' 23:59:59'));
     $q->groupBy('ds.device');
     $results = $q->execute()->fetchAll();
     $chart = new PieChart($data['labels']);
     if (empty($results)) {
         $results[] = ['device' => $this->translator->trans('mautic.report.report.noresults'), 'count' => 0];
     }
     foreach ($results as $result) {
         $label = empty($result['device']) ? $this->translator->trans('mautic.core.no.info') : $result['device'];
         // $data['backgroundColor'][]='rgba(220,220,220,0.5)';
         $chart->setDataset($label, $result['count']);
     }
     return $chart->render();
 }
Exemplo n.º 6
0
 /**
  * Get pie chart data of unique vs repetitive downloads.
  * Repetitive in this case mean if a lead downloaded any of the assets more than once.
  *
  * @param string $dateFrom
  * @param string $dateTo
  * @param array  $filters
  * @param bool   $canViewOthers
  *
  * @return array
  */
 public function getUniqueVsRepetitivePieChartData($dateFrom, $dateTo, $filters = [], $canViewOthers = true)
 {
     $chart = new PieChart();
     $query = new ChartQuery($this->em->getConnection(), $dateFrom, $dateTo);
     $allQ = $query->getCountQuery('asset_downloads', 'id', 'date_download', $filters);
     $uniqueQ = $query->getCountQuery('asset_downloads', 'lead_id', 'date_download', $filters, ['getUnique' => true]);
     if (!$canViewOthers) {
         $allQ->join('t', MAUTIC_TABLE_PREFIX . 'assets', 'a', 'a.id = t.asset_id')->andWhere('a.created_by = :userId')->setParameter('userId', $this->userHelper->getUser()->getId());
         $uniqueQ->join('t', MAUTIC_TABLE_PREFIX . 'assets', 'a', 'a.id = t.asset_id')->andWhere('a.created_by = :userId')->setParameter('userId', $this->userHelper->getUser()->getId());
     }
     $all = $query->fetchCount($allQ);
     $unique = $query->fetchCount($uniqueQ);
     $repetitive = $all - $unique;
     $chart->setDataset($this->translator->trans('mautic.asset.unique'), $unique);
     $chart->setDataset($this->translator->trans('mautic.asset.repetitive'), $repetitive);
     return $chart->render();
 }
Exemplo n.º 7
0
 /**
  * Initialize the QueryBuilder object to generate reports from.
  *
  * @param ReportGraphEvent $event
  */
 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->em->getRepository('MauticEmailBundle:Stat');
     foreach ($graphs as $g) {
         $options = $event->getOptions($g);
         $queryBuilder = clone $qb;
         $chartQuery = clone $options['chartQuery'];
         $origQuery = clone $queryBuilder;
         $chartQuery->applyDateFilters($queryBuilder, 'date_sent', 'es');
         switch ($g) {
             case 'mautic.email.graph.line.stats':
                 $chart = new LineChart(null, $options['dateFrom'], $options['dateTo']);
                 $sendQuery = clone $queryBuilder;
                 $readQuery = clone $origQuery;
                 $failedQuery = clone $queryBuilder;
                 $failedQuery->andWhere($qb->expr()->eq('es.is_failed', ':true'));
                 $failedQuery->setParameter('true', true, 'boolean');
                 $chartQuery->applyDateFilters($readQuery, 'date_read', 'es');
                 $chartQuery->modifyTimeDataQuery($sendQuery, 'date_sent', 'es');
                 $chartQuery->modifyTimeDataQuery($readQuery, 'date_read', 'es');
                 $chartQuery->modifyTimeDataQuery($failedQuery, 'date_sent', 'es');
                 $sends = $chartQuery->loadAndBuildTimeData($sendQuery);
                 $reads = $chartQuery->loadAndBuildTimeData($readQuery);
                 $failes = $chartQuery->loadAndBuildTimeData($failedQuery);
                 $chart->setDataset($options['translator']->trans('mautic.email.sent.emails'), $sends);
                 $chart->setDataset($options['translator']->trans('mautic.email.read.emails'), $reads);
                 $chart->setDataset($options['translator']->trans('mautic.email.failed.emails'), $failes);
                 $data = $chart->render();
                 $data['name'] = $g;
                 $event->setGraph($g, $data);
                 break;
             case 'mautic.email.graph.pie.ignored.read.failed':
                 $counts = $statRepo->getIgnoredReadFailed($queryBuilder);
                 $chart = new PieChart();
                 $chart->setDataset($options['translator']->trans('mautic.email.read.emails'), $counts['read']);
                 $chart->setDataset($options['translator']->trans('mautic.email.failed.emails'), $counts['failed']);
                 $chart->setDataset($options['translator']->trans('mautic.email.ignored.emails'), $counts['ignored']);
                 $event->setGraph($g, ['data' => $chart->render(), 'name' => $g, 'iconClass' => 'fa-flag-checkered']);
                 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 = [];
                 $graphData['data'] = $items;
                 $graphData['name'] = $g;
                 $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 = [];
                 $graphData['data'] = $items;
                 $graphData['name'] = $g;
                 $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 = [];
                 $graphData['data'] = $items;
                 $graphData['name'] = $g;
                 $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 = [];
                 $graphData['data'] = $items;
                 $graphData['name'] = $g;
                 $graphData['iconClass'] = 'fa-tachometer';
                 $graphData['link'] = 'mautic_email_action';
                 $event->setGraph($g, $graphData);
                 break;
         }
         unset($queryBuilder);
     }
 }
Exemplo n.º 8
0
 public function getLifeCycleSegmentChartData($unit, \DateTime $dateFrom, \DateTime $dateTo, $dateFormat = null, $filter = array(), $canViewOthers = true, $listName)
 {
     $chart = new PieChart();
     $query = new ChartQuery($this->em->getConnection(), $dateFrom, $dateTo);
     if (!$canViewOthers) {
         $filter['owner_id'] = $this->user->getId();
     }
     if (isset($filter['flag'])) {
         unset($filter['flag']);
     }
     $allLists = $query->getCountQuery('leads', 'id', 'date_added', null);
     $lists = $query->count('leads', 'id', 'date_added', $filter, null);
     $all = $query->fetchCount($allLists);
     $identified = $lists;
     $chart->setDataset($listName, $identified);
     if (isset($filter['leadlist_id']['value'])) {
         $chart->setDataset($this->translator->trans('mautic.lead.lifecycle.graph.pie.all.lists'), $all);
     }
     return $chart->render(false);
 }
Exemplo n.º 9
0
 /**
  * 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;
         /** @var ChartQuery $chartQuery */
         $chartQuery = clone $options['chartQuery'];
         $chartQuery->applyDateFilters($queryBuilder, 'date_hit', 'ph');
         switch ($g) {
             case 'mautic.page.graph.line.hits':
                 $chart = new LineChart(null, $options['dateFrom'], $options['dateTo']);
                 $chartQuery->modifyTimeDataQuery($queryBuilder, 'date_hit', 'ph');
                 $hits = $chartQuery->loadAndBuildTimeData($queryBuilder);
                 $chart->setDataset($options['translator']->trans($g), $hits);
                 $data = $chart->render();
                 $data['name'] = $g;
                 $event->setGraph($g, $data);
                 break;
             case 'mautic.page.graph.line.time.on.site':
                 $chart = new LineChart(null, $options['dateFrom'], $options['dateTo']);
                 $queryBuilder->select('TIMESTAMPDIFF(SECOND, ph.date_hit, ph.date_left) as data, ph.date_hit as date');
                 $queryBuilder->andWhere($qb->expr()->isNotNull('ph.date_left'));
                 $hits = $chartQuery->loadAndBuildTimeData($queryBuilder);
                 $chart->setDataset($options['translator']->trans($g), $hits);
                 $data = $chart->render();
                 $data['name'] = $g;
                 $event->setGraph($g, $data);
                 break;
             case 'mautic.page.graph.pie.time.on.site':
                 $timesOnSite = $hitRepo->getDwellTimeLabels();
                 $chart = new PieChart();
                 foreach ($timesOnSite as $time) {
                     $q = clone $queryBuilder;
                     $chartQuery->modifyCountDateDiffQuery($q, 'date_hit', 'date_left', $time['from'], $time['till'], 'ph');
                     $data = $chartQuery->fetchCountDateDiff($q);
                     $chart->setDataset($time['label'], $data);
                 }
                 $event->setGraph($g, ['data' => $chart->render(), 'name' => $g, 'iconClass' => 'fa-clock-o']);
                 break;
             case 'mautic.page.graph.pie.new.vs.returning':
                 $chart = new PieChart();
                 $allQ = clone $queryBuilder;
                 $uniqueQ = clone $queryBuilder;
                 $chartQuery->modifyCountQuery($allQ, 'date_hit', [], 'ph');
                 $chartQuery->modifyCountQuery($uniqueQ, 'date_hit', ['getUnique' => true, 'selectAlso' => ['ph.page_id']], 'ph');
                 $all = $chartQuery->fetchCount($allQ);
                 $unique = $chartQuery->fetchCount($uniqueQ);
                 $returning = $all - $unique;
                 $chart->setDataset($this->factory->getTranslator()->trans('mautic.page.unique'), $unique);
                 $chart->setDataset($this->factory->getTranslator()->trans('mautic.page.graph.pie.new.vs.returning.returning'), $returning);
                 $event->setGraph($g, ['data' => $chart->render(), 'name' => $g, 'iconClass' => 'fa-bookmark-o']);
                 break;
             case 'mautic.page.graph.pie.languages':
                 $queryBuilder->select('ph.page_language, COUNT(distinct(ph.id)) as the_count')->groupBy('ph.page_language')->andWhere($qb->expr()->isNotNull('ph.page_language'));
                 $data = $queryBuilder->execute()->fetchAll();
                 $chart = new PieChart();
                 foreach ($data as $lang) {
                     $chart->setDataset($lang['page_language'], $lang['the_count']);
                 }
                 $event->setGraph($g, ['data' => $chart->render(), 'name' => $g, 'iconClass' => 'fa-globe']);
                 break;
             case 'mautic.page.graph.pie.devices':
                 $queryBuilder->select('ds.device, COUNT(distinct(ph.id)) as the_count')->groupBy('ds.device');
                 $data = $queryBuilder->execute()->fetchAll();
                 $chart = new PieChart();
                 foreach ($data as $device) {
                     $label = substr(empty($device['device']) ? $this->translator->trans('mautic.core.no.info') : $device['device'], 0, 12);
                     $chart->setDataset($label, $device['the_count']);
                 }
                 $event->setGraph($g, ['data' => $chart->render(), 'name' => $g, 'iconClass' => 'fa-globe']);
                 break;
             case 'mautic.page.table.referrers':
                 $limit = 10;
                 $offset = 0;
                 $items = $hitRepo->getReferers($queryBuilder, $limit, $offset);
                 $graphData = [];
                 $graphData['data'] = $items;
                 $graphData['name'] = $g;
                 $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 = [];
                 $graphData['data'] = $items;
                 $graphData['name'] = $g;
                 $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 = [];
                 $graphData['data'] = $items;
                 $graphData['name'] = $g;
                 $graphData['iconClass'] = 'fa-eye';
                 $graphData['link'] = 'mautic_page_action';
                 $event->setGraph($g, $graphData);
                 break;
         }
         unset($queryBuilder);
     }
 }
Exemplo n.º 10
0
 /**
  * Get pie chart data of dwell times
  *
  * @param DateTime $dateFrom
  * @param DateTime $dateTo
  * @param array    $filters
  * @param boolean  $canViewOthers
  *
  * @return array
  */
 public function getDwellTimesPieChartData(\DateTime $dateFrom, \DateTime $dateTo, $filters = array(), $canViewOthers = true)
 {
     $timesOnSite = array(array('label' => '< 1m', 'from' => 0, 'till' => 60), array('label' => '1 - 5m', 'from' => 60, 'till' => 300), array('label' => '5 - 10m', 'value' => 0, 'from' => 300, 'till' => 600), array('label' => '> 10m', 'from' => 600, 'till' => 999999));
     $chart = new PieChart();
     $query = new ChartQuery($this->factory->getEntityManager()->getConnection(), $dateFrom, $dateTo);
     foreach ($timesOnSite as $time) {
         $q = $query->getCountDateDiffQuery('page_hits', 'date_hit', 'date_left', $time['from'], $time['till'], $filters);
         if (!$canViewOthers) {
             $this->limitQueryToCreator($q);
         }
         $data = $query->fetchCountDateDiff($q);
         $chart->setDataset($time['label'], $data);
     }
     return $chart->render();
 }
Exemplo n.º 11
0
 /**
  * Get pie graph data for http statuses
  *
  * @param QueryBuilder $query
  *
  * @return array
  * @throws \Doctrine\ORM\NoResultException
  * @throws \Doctrine\ORM\NonUniqueResultException
  */
 public function getHttpStatuses($query)
 {
     $query->select('ad.code as status, count(ad.code) as count')->groupBy('ad.code')->orderBy('count', 'DESC');
     $results = $query->execute()->fetchAll();
     $chart = new PieChart();
     foreach ($results as $result) {
         $chart->setDataset($result['status'], $result['count']);
     }
     return $chart->render();
 }
Exemplo n.º 12
0
 /**
  * Get pie chart data of ignored vs opened emails.
  *
  * @param string $dateFrom
  * @param string $dateTo
  * @param array  $filters
  * @param bool   $canViewOthers
  *
  * @return array
  */
 public function getDeviceGranularityPieChartData($dateFrom, $dateTo, $canViewOthers = true)
 {
     $chart = new PieChart();
     $deviceStats = $this->getStatDeviceRepository()->getDeviceStats(null, $dateFrom, $dateTo);
     if (empty($deviceStats)) {
         $deviceStats[] = ['count' => 0, 'device' => $this->translator->trans('mautic.report.report.noresults'), 'list_id' => 0];
     }
     foreach ($deviceStats as $device) {
         $chart->setDataset($device['device'], $device['count']);
     }
     return $chart->render();
 }