QCharts/ApiBundle/Controller/DatabaseController.php
public function runAction(Request $request)
    {
        $authChecker = $this->get('security.authorization_checker');

        /** @var QueryService $queryService */
        $queryService = $this->get('qcharts.query');

        $chartValidator = $this->get("qcharts.chart_validator");

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

        if (!$authChecker->isGranted($roles["admin"]))
        {
            return new JsonResponse(ApiController::getNotValidCredentials());
        }

        $query = $request->request->get('query');
        try
        {
            $queryLimit = $request->request->get('limit', 0);
            $connection = $request->request->get('connection', 'default');

            $result = $queryService->getResultsFromQuery($query, $queryLimit, $connection);

            $isPieCompatible = false;
            try
            {
                $isPieCompatible = $chartValidator->resultsArePieCompatible($result["results"]);
                $isPieCompatible = $isPieCompatible && $chartValidator->resultsAreNumeric($result["results"], 'pie');
            }
            catch (ValidationFailedException $e)
            {
                $isPieCompatible = false;
            }
            finally
            {
                return new JsonResponse([
                    "status" => 200,
                    "originalQuery" => $query,
                    "textStatus" => "Results are returned",
                    "results" => $result["results"],
                    "lengthResults" => count($result["results"]),
                    "queryDuration" => $result["duration"],
                    "limit"=>$queryLimit,
                    "isPieChartCompatible" => $isPieCompatible,
                ]);
            }

        }
        catch (ParameterNotPassedException $e)
        {
            //return the error as an error
            return new JsonResponse([
                "status"=>500,
                "textStatus" => $e->getMessage(),
                "originalQuery" => $query,
            ]);
        }
        catch (DatabaseException $e)
        {
            return new JsonResponse([
                "status" => $e->getCode(),
                "textStatus"=>$e->getMessage()
            ]);
        }
        catch (ValidationFailedException $e)
        {
            return new JsonResponse([
                "status" => $e->getCode(),
                "textStatus"=>$e->getMessage(),
                "originalQuery"=>$query
            ]);
        }
        catch (\InvalidArgumentException $e)
        {
            return new JsonResponse([
                "status"=>500,
                "textStatus"=>$e->getMessage(),
                "originalQuery"=>$query
            ]);
        }
    }
public function runAction(Request $request)
    {
        $authChecker = $this->get('security.authorization_checker');

        /** @var QueryService $queryService */
        $queryService = $this->get('qcharts.query');

        $chartValidator = $this->get("qcharts.chart_validator");

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

        if (!$authChecker->isGranted($roles["admin"]))
        {
            return new JsonResponse(ApiController::getNotValidCredentials());
        }

        $query = $request->request->get('query');
        try
        {
            $queryLimit = $request->request->get('limit', 0);
            $connection = $request->request->get('connection', 'default');

            $result = $queryService->getResultsFromQuery($query, $queryLimit, $connection);

            $isPieCompatible = false;
            try
            {
                $isPieCompatible = $chartValidator->resultsArePieCompatible($result["results"]);
                $isPieCompatible = $isPieCompatible && $chartValidator->resultsAreNumeric($result["results"], 'pie');
            }
            catch (ValidationFailedException $e)
            {
                $isPieCompatible = false;
            }
            finally
            {
                return new JsonResponse([
                    "status" => 200,
                    "originalQuery" => $query,
                    "textStatus" => "Results are returned",
                    "results" => $result["results"],
                    "lengthResults" => count($result["results"]),
                    "queryDuration" => $result["duration"],
                    "limit"=>$queryLimit,
                    "isPieChartCompatible" => $isPieCompatible,
                ]);
            }

        }
        catch (ParameterNotPassedException $e)
        {
            //return the error as an error
            return new JsonResponse([
                "status"=>500,
                "textStatus" => $e->getMessage(),
                "originalQuery" => $query,
            ]);
        }
        catch (DatabaseException $e)
        {
            return new JsonResponse([
                "status" => $e->getCode(),
                "textStatus"=>$e->getMessage()
            ]);
        }
        catch (ValidationFailedException $e)
        {
            return new JsonResponse([
                "status" => $e->getCode(),
                "textStatus"=>$e->getMessage(),
                "originalQuery"=>$query
            ]);
        }
        catch (\InvalidArgumentException $e)
        {
            return new JsonResponse([
                "status"=>500,
                "textStatus"=>$e->getMessage(),
                "originalQuery"=>$query
            ]);
        }
    }
ApiDoc(
description="Run Action, returns the results directly from database",
parameters={
{
"name"="query",
"dataType"="string",
"required"=true,
"description"="The query to run in the database"
},
{
"name"="limit",
"dataType"="integer",
"required"=false,
"description"="The limit to use"
},
{
"name"="connection",
"dataType"="string",
"required"=false,
"description"="Connection to query from, default connection is used if not passed"
}
},
statusCodes = {
200 = "Returned successfully",
402 = "Credentials not valid",
500 = "Exception found and returned with error"
}
)
@param Request $request
@return JsonResponse