/**
  * @param int|null $id=null
  * @throws BadRequestException
  * @SWG\Get(
  *   tags={"Datasources"},
  *   path="/datasources/{id}/csv",
  *   summary="Get data source rows as CSV",
  *   produces={"text/csv"},
  *   security={{"apiKey":{}},{"apiKeyHeader":{}}},
  *   @SWG\Parameter(
  *     name="id",
  *     description="Datasource ID",
  *     required=true,
  *     type="integer",
  *     in="path"
  *   ),
  *   @SWG\Parameter(
  *     name="offset",
  *     description="Skip rows",
  *     required=false,
  *     type="integer",
  *     in="query"
  *   ),
  *   @SWG\Parameter(
  *     name="limit",
  *     description="Result rows count",
  *     required=false,
  *     type="integer",
  *     in="query"
  *   ),
  *   @SWG\Parameter(
  *     name="separator",
  *     description="Columns separator",
  *     required=true,
  *     type="string",
  *     in="query"
  *   ),
  *   @SWG\Parameter(
  *     name="enclosure",
  *     description="Enclosure character",
  *     required=false,
  *     type="string",
  *     in="query"
  *   ),
  *   @SWG\Response(
  *     response=200,
  *     description="CSV"
  *   ),
  *   @SWG\Response(
  *     response=400,
  *     description="Invalid API key supplied",
  *     @SWG\Schema(ref="#/definitions/StatusResponse")
  *   ),
  *   @SWG\Response(response=404, description="Requested datasource was not found.")
  * )
  */
 public function actionReadCsv($id)
 {
     $datasource = $this->findDatasourceWithCheckAccess($id);
     if (!$datasource->available) {
         $this->error('This datasource is not available!');
     }
     /** @var IDatabase $database */
     $database = $this->datasourcesFacade->getDatasourceDatabase($datasource);
     $dbDatasource = $database->getDbDatasource($datasource->dbDatasourceId ? $datasource->dbDatasourceId : $datasource->getDbTable());
     $inputData = $this->getInput()->getData();
     $offset = @$inputData['offset'];
     $limit = @$inputData['limit'] > 0 ? $inputData['limit'] : 10000;
     $separator = @$inputData['separator'] != '' ? $inputData['separator'] : ';';
     $enclosure = @$inputData['enclosure'] != '' ? $inputData['enclosure'] : '"';
     $csv = CsvSerializer::prepareCsvFromDatabase($database, $dbDatasource, $offset, $limit, $separator, $enclosure);
     $httpResponse = $this->getHttpResponse();
     $httpResponse->setContentType('text/csv', 'UTF-8');
     $this->sendResponse(new TextResponse($csv));
 }