QCharts/ApiBundle/Controller/DatabaseController.php
public function chartDataAction(Request $request)
    {
        $authChecker = $this->get("security.authorization_checker");
        $queryService = $this->get("qcharts.query");
        $resultsFormatter = $this->get("qcharts.query_results_formatter");
        $strategyFactory = $this->get("qcharts.core.fetching_factory");
        $snapshotService = $this->get("qcharts.core.snapshot_service");

        $roles = $this->getParameter('qcharts.user_roles');
        $allow_demo_users = $this->getParameter('qcharts.allow_demo_users');

        if ($authChecker->isGranted($roles["user"]) || $allow_demo_users)
        {
            $opts = [];
            try
            {
                $queryId = $request->query->get("q", 0);
                $formatType = $request->query->get("type", 'line');
                $snapshot = $request->query->get("snapshot", null);

                /** @var QueryRequest $queryRequest */
                $queryRequest = $queryService->getQueryRequestById($queryId);

                $strategy = $strategyFactory->createStrategy($queryRequest->getConfig()->getIsCached(), $snapshot);

                $results = $strategy->getResults($queryRequest);
                $queryDuration = $strategy->getDuration();

                $chartResults = $resultsFormatter->formatResults($results, $formatType);

                try
                {
                    $snapshotUsed = $snapshotService->formatSnapshotName($queryRequest, $snapshot);
                }
                catch (SnapshotException $e)
                {
                    $snapshotUsed = "Got results live";
                }

                $opts = [
                    "status"=>200,
                    "textStatus"=>"Data for chart returned",
                    "chartData"=>$chartResults,
                    "duration"=>"{$queryDuration} secs",
                    "snapshot" => $snapshotUsed
                ];

            }
            catch (NotPlotableException $e)
            {
                $opts = [
                    "status" => $e->getCode(),
                    "textStatus" => $e->getMessage()
                ];
            }
            catch (ValidationFailedException $e)
            {
                $opts = [
                    "status" => $e->getCode(),
                    "textStatus" => $e->getMessage()
                ];
            }
            catch (InstanceNotFoundException $e)
            {
                $opts = [
                    "status" => $e->getCode(),
                    "textStatus" => $e->getMessage()
                ];
            }
            catch (ParameterNotPassedException $e)
            {
                $opts = [
                    "status" => $e->getCode(),
                    "textStatus" => $e->getMessage()
                ];
            }
            catch (SQLException $e)
            {
                $opts = [
                    "status" => $e->getCode(),
                    "textStatus" => $e->getMessage()
                ];
            }
            catch (DatabaseException $e)
            {
                $opts = [
                    "status" => $e->getCode(),
                    "textStatus" => $e->getMessage()
                ];
            }
            catch (TypeNotValidException $e)
            {
                $opts = [
                    "status" => $e->getCode(),
                    "textStatus" => $e->getMessage()
                ];
            }
            catch (SnapshotException $e)
            {
                $opts = [
                    "status"=> 404,
                    "textStatus"=> "The snapshot is not yet cached, sorry for the inconvenience"
                ];
            }
            catch (NotFoundException $e)
            {
                $opts = [
                    "status" => $e->getCode(),
                    "textStatus" => $e->getMessage()
                ];
            }
            catch (IOException $e)
            {
                $opts = [
                    "status"=>$e->getCode(),
                    "textStatus"=>$e->getMessage()
                ];
            }
            finally
            {
                return new JsonResponse($opts);
            }
        }

        return new JsonResponse(ApiController::getNotValidCredentials());

    }
public function chartDataAction(Request $request)
    {
        $authChecker = $this->get("security.authorization_checker");
        $queryService = $this->get("qcharts.query");
        $resultsFormatter = $this->get("qcharts.query_results_formatter");
        $strategyFactory = $this->get("qcharts.core.fetching_factory");
        $snapshotService = $this->get("qcharts.core.snapshot_service");

        $roles = $this->getParameter('qcharts.user_roles');
        $allow_demo_users = $this->getParameter('qcharts.allow_demo_users');

        if ($authChecker->isGranted($roles["user"]) || $allow_demo_users)
        {
            $opts = [];
            try
            {
                $queryId = $request->query->get("q", 0);
                $formatType = $request->query->get("type", 'line');
                $snapshot = $request->query->get("snapshot", null);

                /** @var QueryRequest $queryRequest */
                $queryRequest = $queryService->getQueryRequestById($queryId);

                $strategy = $strategyFactory->createStrategy($queryRequest->getConfig()->getIsCached(), $snapshot);

                $results = $strategy->getResults($queryRequest);
                $queryDuration = $strategy->getDuration();

                $chartResults = $resultsFormatter->formatResults($results, $formatType);

                try
                {
                    $snapshotUsed = $snapshotService->formatSnapshotName($queryRequest, $snapshot);
                }
                catch (SnapshotException $e)
                {
                    $snapshotUsed = "Got results live";
                }

                $opts = [
                    "status"=>200,
                    "textStatus"=>"Data for chart returned",
                    "chartData"=>$chartResults,
                    "duration"=>"{$queryDuration} secs",
                    "snapshot" => $snapshotUsed
                ];

            }
            catch (NotPlotableException $e)
            {
                $opts = [
                    "status" => $e->getCode(),
                    "textStatus" => $e->getMessage()
                ];
            }
            catch (ValidationFailedException $e)
            {
                $opts = [
                    "status" => $e->getCode(),
                    "textStatus" => $e->getMessage()
                ];
            }
            catch (InstanceNotFoundException $e)
            {
                $opts = [
                    "status" => $e->getCode(),
                    "textStatus" => $e->getMessage()
                ];
            }
            catch (ParameterNotPassedException $e)
            {
                $opts = [
                    "status" => $e->getCode(),
                    "textStatus" => $e->getMessage()
                ];
            }
            catch (SQLException $e)
            {
                $opts = [
                    "status" => $e->getCode(),
                    "textStatus" => $e->getMessage()
                ];
            }
            catch (DatabaseException $e)
            {
                $opts = [
                    "status" => $e->getCode(),
                    "textStatus" => $e->getMessage()
                ];
            }
            catch (TypeNotValidException $e)
            {
                $opts = [
                    "status" => $e->getCode(),
                    "textStatus" => $e->getMessage()
                ];
            }
            catch (SnapshotException $e)
            {
                $opts = [
                    "status"=> 404,
                    "textStatus"=> "The snapshot is not yet cached, sorry for the inconvenience"
                ];
            }
            catch (NotFoundException $e)
            {
                $opts = [
                    "status" => $e->getCode(),
                    "textStatus" => $e->getMessage()
                ];
            }
            catch (IOException $e)
            {
                $opts = [
                    "status"=>$e->getCode(),
                    "textStatus"=>$e->getMessage()
                ];
            }
            finally
            {
                return new JsonResponse($opts);
            }
        }

        return new JsonResponse(ApiController::getNotValidCredentials());

    }
ApiDoc(
description="chartData Action, returns the data formatted for the chart",
parameters = {
{
"name" = "q",
"dataType" = "integer",
"required"  = true,
"description" = "The requested Query Id"
},
{
"name" = "snapshot",
"dataType" = "string",
"required" = false,
"description" = "The selected snapshot to format, if not given uses the freshest snapshot"
},
{
"name" = "type",
"dataType" = "string",
"required" = false,
"description" = "Type of formatting to be applied to the results of the query, default = 'line'"
}
},
statusCodes = {
200 = "Returned successfully",
402 = "Credentials not valid",
404 = "Requested Query was not found with the given Id",
405 = "Requested formatting is not supported",
500 = "Exception found and returned with error",
555 = "The snapshot given was not a valid format"
}
)
@param Request $request
@return JsonResponse