QCharts/ApiBundle/Controller/ApiController.php
public function registerAction(Request $request)
    {
        $authorizationChecker = $this->get('security.authorization_checker');
		$queryService = $this->get('qcharts.query');
        $snapshotService = $this->get("qcharts.core.snapshot_service");
		$formFactory = $this->get('form.factory');

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

		if (!$authorizationChecker->isGranted($roles['admin']))
        {
			return $this->getCredentialsNotValid();
		}
		
		try
        {
            $doctrine = $this->get("doctrine");
            $chartTypes = $this->getParameter("qcharts.chart_types");
			/** @var Form $form */
			$form = $formFactory->create(new QueryRequestType($doctrine, $chartTypes));
			$form->submit($request->request->get($form->getName()));
			
			if ($form->isValid())
            {
				$user = $this->getUser();

                $results = $queryService->add($form, $user);

                $snapshotService->writeSnapshot($results["query"], $results["results"]);

                $opts = [
						"status"=>201,
						"textStatus"=>"Query created"
				];
				return new JsonResponse($opts);
			}
		}
        catch (OffLimitsException $e)
        {
            $snapshotService->writeSnapshot($e->getData()["query"], $e->getData()["results"]);

            $options = [
                "status"=>201,
                "textStatus"=>"{$e->getMessage()}. {$e->getPrevious()->getMessage()}"
            ];

            return new JsonResponse($options);
        }
        catch(ParameterNotPassedException $e)
        {
			return $this->getTheFormNotvalid();
		}
        catch (ValidationFailedException $e)
        {
            $options = [
                "status"=>$e->getCode(),
                "textStatus"=>$e->getMessage()
            ];
            return new JsonResponse($options);
        }
        catch (TypeNotValidException $e)
        {
            $options = [
                "status"=>$e->getCode(),
                "textStatus"=>$e->getMessage()
            ];
            return new JsonResponse($options);
        }
        catch (DatabaseException $e)
        {
            $options = [
                "status"=>$e->getCode(),
                "textStatus"=>$e->getMessage()
            ];
            return new JsonResponse($options);
        }
		
		return $this->getTheFormNotValid();
	}
public function registerAction(Request $request)
    {
        $authorizationChecker = $this->get('security.authorization_checker');
		$queryService = $this->get('qcharts.query');
        $snapshotService = $this->get("qcharts.core.snapshot_service");
		$formFactory = $this->get('form.factory');

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

		if (!$authorizationChecker->isGranted($roles['admin']))
        {
			return $this->getCredentialsNotValid();
		}
		
		try
        {
            $doctrine = $this->get("doctrine");
            $chartTypes = $this->getParameter("qcharts.chart_types");
			/** @var Form $form */
			$form = $formFactory->create(new QueryRequestType($doctrine, $chartTypes));
			$form->submit($request->request->get($form->getName()));
			
			if ($form->isValid())
            {
				$user = $this->getUser();

                $results = $queryService->add($form, $user);

                $snapshotService->writeSnapshot($results["query"], $results["results"]);

                $opts = [
						"status"=>201,
						"textStatus"=>"Query created"
				];
				return new JsonResponse($opts);
			}
		}
        catch (OffLimitsException $e)
        {
            $snapshotService->writeSnapshot($e->getData()["query"], $e->getData()["results"]);

            $options = [
                "status"=>201,
                "textStatus"=>"{$e->getMessage()}. {$e->getPrevious()->getMessage()}"
            ];

            return new JsonResponse($options);
        }
        catch(ParameterNotPassedException $e)
        {
			return $this->getTheFormNotvalid();
		}
        catch (ValidationFailedException $e)
        {
            $options = [
                "status"=>$e->getCode(),
                "textStatus"=>$e->getMessage()
            ];
            return new JsonResponse($options);
        }
        catch (TypeNotValidException $e)
        {
            $options = [
                "status"=>$e->getCode(),
                "textStatus"=>$e->getMessage()
            ];
            return new JsonResponse($options);
        }
        catch (DatabaseException $e)
        {
            $options = [
                "status"=>$e->getCode(),
                "textStatus"=>$e->getMessage()
            ];
            return new JsonResponse($options);
        }
		
		return $this->getTheFormNotValid();
	}
ApiDoc(
description = "Save a query request",
parameters = {
{
"name" = "query_request[title]",
"description" = "Title of the Query",
"required" = true,
"dataType" = "string"
}, {
"name" = "query_request[description]",
"description" = "Brief or concrete description of the query",
"required" = true,
"dataType" = "string"
}, {
"name" = "query_request[config][databaseConnection]",
"required" = true,
"dataType" = "string",
"description" = "The connection to use"
}, {
"name" = "query_request[config][typeOfChart]",
"description" = "Type of chart to display and/or to format query results,
please refer to the documentation for supported chart types",
"required" = true,
"dataType" = "string"
}, {
"name" = "query_request[query][query]",
"description" = "Query to execute",
"required" = true,
"dataType" = "string"
}, {
"name" = "query_request[config][queryLimit]",
"required" = false,
"dataType" = "integer",
"description" = "The limit of rows to fetch from the database,
refer to the documentation to see the default limit"
}, {
"name"="query_request[config][offset]",
"required" = true,
"dataType" = "integer",
"description" = "The offset from the limit"
}, {
"name"="query_request[config][executionLimit]",
"required" = true,
"dataType" = "number",
"description" = "The time limit execution"
}, {
"name" = "query_request[config][isCached]",
"required" = true,
"dataType" = "integer",
"description" = "type of cached used",
"format" = "[0-2]"
}, {
"name" = "query_request[cronExpression]",
"required" = true,
"dataType" = "string",
"description" = "Cron expression",
}, {
"name" = "query_request[directory]",
"required" = false,
"dataType" = "integer",
"description" = "The folder id to save the query in"
}
},
statusCodes = {
200 = "Registration was successful",
402 = "Credentials not valid",
500 = "The process encountered an unexpected exception"
}
)

@param Request $request
@return JsonResponse