/**
  * Fetch a specific goals
  *
  * @param AnalyticsOverview $overview The overview
  * @param $goalCollection
  */
 private function parseGoals(&$overview, $goalCollection)
 {
     $timespan = $overview->getTimespan() - $overview->getStartOffset();
     if ($overview->getGoals()) {
         // delete existing entries
         foreach ($overview->getGoals() as $goal) {
             $this->em->remove($goal);
         }
         $this->em->flush();
     }
     foreach ($goalCollection as $goalEntry) {
         // create a new goal
         $goal = new AnalyticsGoal();
         $goal->setOverview($overview);
         $goal->setName($goalEntry['name']);
         $goal->setPosition($goalEntry['position']);
         $chartData = array();
         $totalVisits = 0;
         $goalVisits = 0;
         $i = 0;
         // Fill the chartdata array
         foreach ($goalEntry['visits'] as $timestamp => $visits) {
             $totalVisits += $visits;
             if ($timespan <= 7 && $timespan > 1) {
                 $goalVisits += $visits;
                 if ($i % 5 == 0) {
                     $chartData[] = array('timestamp' => $timestamp, 'conversions' => $goalVisits);
                     $goalVisits = 0;
                 }
             } else {
                 $chartData[] = array('timestamp' => $timestamp, 'conversions' => $visits);
             }
             $i += 1;
         }
         // set the data
         $goal->setVisits($totalVisits);
         $goal->setChartData(json_encode($chartData));
         $goals = $overview->getGoals();
         $goals[] = $goal;
         $this->em->persist($goal);
         $this->output->writeln("\t\t" . 'Fetched goal ' . $goal->getPosition() . ': "' . $goal->getName() . '" @ ' . $totalVisits);
     }
 }