src/Kunstmaan/DashboardBundle/Controller/GoogleAnalyticsAJAXController.php
public function getOverviewAction($id)
    {
        $em = $this->getDoctrine()->getManager();
        /** @var AnalyticsOverviewRepository $analyticsOverviewRepository */
        $analyticsOverviewRepository = $em->getRepository('KunstmaanDashboardBundle:AnalyticsOverview');
        $overview = $analyticsOverviewRepository->find($id);

        // goals data
        $goals = array();
        foreach ($overview->getActiveGoals() as $key => $goal) {
            /* @var AnalyticsGoal $goal */
            $goals[$key]['name'] = $goal->getName();
            $goals[$key]['visits'] = $goal->getVisits();
            $goals[$key]['id'] = $goal->getId();
            $goals[$key]['chartData'] = json_decode($goal->getChartData());
        }

        // overview data
        $overviewData = array(
            'id' => $overview->getId(),
            'chartData' => json_decode($overview->getChartData(), true),
            'chartDataMaxValue' => $overview->getChartDataMaxValue(),
            'title' => $overview->getTitle(),
            'timespan' => $overview->getTimespan(),
            'startOffset' => $overview->getStartOffset(),
            'sessions' => number_format($overview->getSessions()),
            'users' => number_format($overview->getUsers()),
            'pagesPerSession' => round($overview->getPagesPerSession(), 2),
            'avgSessionDuration' => $overview->getAvgSessionDuration(),
            'returningUsers' => number_format($overview->getReturningUsers()),
            'newUsers' => round($overview->getNewUsers(), 2),
            'pageViews' => number_format($overview->getPageViews()),
            'returningUsersPercentage' => $overview->getReturningUsersPercentage(),
            'newUsersPercentage' => $overview->getNewUsersPercentage(),
        );

        // put all data in the return array
        $return = array(
            'responseCode' => 200,
            'overview' => $overviewData,
            'goals' => $goals,
        );

        // return json response
        return new JsonResponse($return, 200, array('Content-Type' => 'application/json'));
    }
public function getOverviewAction($id)
    {
        $em = $this->getDoctrine()->getManager();
        /** @var AnalyticsOverviewRepository $analyticsOverviewRepository */
        $analyticsOverviewRepository = $em->getRepository('KunstmaanDashboardBundle:AnalyticsOverview');
        $overview = $analyticsOverviewRepository->find($id);

        // goals data
        $goals = array();
        foreach ($overview->getActiveGoals() as $key => $goal) {
            /* @var AnalyticsGoal $goal */
            $goals[$key]['name'] = $goal->getName();
            $goals[$key]['visits'] = $goal->getVisits();
            $goals[$key]['id'] = $goal->getId();
            $goals[$key]['chartData'] = json_decode($goal->getChartData());
        }

        // overview data
        $overviewData = array(
            'id' => $overview->getId(),
            'chartData' => json_decode($overview->getChartData(), true),
            'chartDataMaxValue' => $overview->getChartDataMaxValue(),
            'title' => $overview->getTitle(),
            'timespan' => $overview->getTimespan(),
            'startOffset' => $overview->getStartOffset(),
            'sessions' => number_format($overview->getSessions()),
            'users' => number_format($overview->getUsers()),
            'pagesPerSession' => round($overview->getPagesPerSession(), 2),
            'avgSessionDuration' => $overview->getAvgSessionDuration(),
            'returningUsers' => number_format($overview->getReturningUsers()),
            'newUsers' => round($overview->getNewUsers(), 2),
            'pageViews' => number_format($overview->getPageViews()),
            'returningUsersPercentage' => $overview->getReturningUsersPercentage(),
            'newUsersPercentage' => $overview->getNewUsersPercentage(),
        );

        // put all data in the return array
        $return = array(
            'responseCode' => 200,
            'overview' => $overviewData,
            'goals' => $goals,
        );

        // return json response
        return new JsonResponse($return, 200, array('Content-Type' => 'application/json'));
    }
public function getOverviewAction ( $ id ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; /** @var AnalyticsOverviewRepository $analyticsOverviewRepository */ $ analyticsOverviewRepository = $ em -> getRepository ( 'KunstmaanDashboardBundle:AnalyticsOverview' ) ; $ overview = $ analyticsOverviewRepository -> find ( $ id ) ; // goals data $ goals = array ( ) ; foreach ( $ overview -> getActiveGoals ( ) as $ key => $ goal ) { /* @var AnalyticsGoal $goal */ $ goals [ $ key ] [ 'name' ] = $ goal -> getName ( ) ; $ goals [ $ key ] [ 'visits' ] = $ goal -> getVisits ( ) ; $ goals [ $ key ] [ 'id' ] = $ goal -> getId ( ) ; $ goals [ $ key ] [ 'chartData' ] = json_decode ( $ goal -> getChartData ( ) ) ; } // overview data $ overviewData = array ( 'id' => $ overview -> getId ( ) , 'chartData' => json_decode ( $ overview -> getChartData ( ) , true ) , 'chartDataMaxValue' => $ overview -> getChartDataMaxValue ( ) , 'title' => $ overview -> getTitle ( ) , 'timespan' => $ overview -> getTimespan ( ) , 'startOffset' => $ overview -> getStartOffset ( ) , 'sessions' => number_format ( $ overview -> getSessions ( ) ) , 'users' => number_format ( $ overview -> getUsers ( ) ) , 'pagesPerSession' => round ( $ overview -> getPagesPerSession ( ) , 2 ) , 'avgSessionDuration' => $ overview -> getAvgSessionDuration ( ) , 'returningUsers' => number_format ( $ overview -> getReturningUsers ( ) ) , 'newUsers' => round ( $ overview -> getNewUsers ( ) , 2 ) , 'pageViews' => number_format ( $ overview -> getPageViews ( ) ) , 'returningUsersPercentage' => $ overview -> getReturningUsersPercentage ( ) , 'newUsersPercentage' => $ overview -> getNewUsersPercentage ( ) , ) ; // put all data in the return array $ return = array ( 'responseCode' => 200 , 'overview' => $ overviewData , 'goals' => $ goals , ) ; // return json response return new JsonResponse ( $ return , 200 , array ( 'Content-Type' => 'application/json' ) ) ; }
Return an ajax response with all data for an overview

@Route("/getOverview/{id}", requirements={"id" = "\d+"}, name="KunstmaanDashboardBundle_analytics_overview_ajax")
Return an ajax response with all data for an overview