/** * Get pie chart data of dwell times. * * @param \DateTime $dateFrom * @param \DateTime $dateTo * @param array $filters * @param bool $canViewOthers * * @return array */ public function getDwellTimesPieChartData(\DateTime $dateFrom, \DateTime $dateTo, $filters = [], $canViewOthers = true) { $timesOnSite = $this->getHitRepository()->getDwellTimeLabels(); $chart = new PieChart(); $query = new ChartQuery($this->em->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(); }
/** * 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(); }