LimeSurvey API - Master branch

ExportSurveyResultsService
in package
Uses ResponseMappingTrait

Tags
SuppressWarnings

(PHPMD.ExcessiveClassComplexity)

SuppressWarnings

(PHPMD.ExcessiveMethodLength)

Table of Contents

Constants

META_COLUMN_MAP  = ['id' => ['key' => 'id', 'header' => 'Response ID'], 'submitdate' => ['key' => 'submitDate', 'header' => 'Date submitted'], 'lastpage' => ['key' => 'lastPage', 'header' => 'Last page'], 'startlanguage' => ['key' => 'language', 'header' => 'Start language'], 'seed' => ['key' => 'seed', 'header' => 'Seed'], 'token' => ['key' => 'token', 'header' => 'Token'], 'startdate' => ['key' => 'startDate', 'header' => 'Date started'], 'datestamp' => ['key' => 'dateLastAction', 'header' => 'Date last action'], 'ipaddr' => ['key' => 'ipAddr', 'header' => 'IP address'], 'refurl' => ['key' => 'refUrl', 'header' => 'Referrer URL']]

Properties

$answerCache  : SurveyAnswerCache
$answerFormat  : string
$answerFormatter  : ExportAnswerFormatter
$chunkSize  : int
$language  : string|null
$loadedSurvey  : Survey|null
$outputMode  : string
$responseFilterPatcher  : FilterPatcher
$supportedExportTypes  : mixed
$survey  : Survey
$transformerOutputSurveyResponses  : TransformerOutputSurveyResponses

Methods

__construct()  : mixed
ExportSurveyResultsService constructor.
exportResponses()  : array<string|int, mixed>
Export survey responses to the specified format.
getAnswerFormat()  : string
getChunkSize()  : int
getLanguage()  : string|null
getOutputMode()  : string
setAnswerFormat()  : $this
setChunkSize()  : $this
setLanguage()  : $this
setOutputMode()  : $this
exportResponsesInChunks()  : array<string|int, mixed>
Export survey responses in chunks, writing directly to the export writer.
fetchResponseChunkDirect()  : array<string|int, SurveyDynamic>
Fetch a chunk of responses directly using CDbCriteria.
fetchTimingsForChunk()  : array<string|int, mixed>
Fetch timing data for a chunk of SurveyDynamic response objects.
getActualAid()  : int|null
Get the actual answer ID using the shared answer cache.
getExportWriter()  : ExportWriterInterface
Get the appropriate export writer for the given type.
getQuestionFieldMap()  : array<string|int, mixed>
Get the question field map.
getTimingFieldMap()  : array<string|int, mixed>
Generate timing field map entries for export headers and data mapping.
getTotalResponseCount()  : int
Get the total number of responses for a survey.
mapResponsesToQuestions()  : array<string|int, mixed>
Map survey responses to survey questions.
processResponseChunk()  : array<string|int, mixed>
Process a chunk of SurveyDynamic responses through the transformer, override dates with raw values, format answers, and merge timing data.
mergeTimingData()  : mixed
Merge timing data into the response's answers array.
overrideDateFields()  : mixed
Override date fields with raw DB values (bypass ISO 8601 formatting) and merge any missing raw attributes into the response.

Constants

META_COLUMN_MAP

private mixed META_COLUMN_MAP = ['id' => ['key' => 'id', 'header' => 'Response ID'], 'submitdate' => ['key' => 'submitDate', 'header' => 'Date submitted'], 'lastpage' => ['key' => 'lastPage', 'header' => 'Last page'], 'startlanguage' => ['key' => 'language', 'header' => 'Start language'], 'seed' => ['key' => 'seed', 'header' => 'Seed'], 'token' => ['key' => 'token', 'header' => 'Token'], 'startdate' => ['key' => 'startDate', 'header' => 'Date started'], 'datestamp' => ['key' => 'dateLastAction', 'header' => 'Date last action'], 'ipaddr' => ['key' => 'ipAddr', 'header' => 'IP address'], 'refurl' => ['key' => 'refUrl', 'header' => 'Referrer URL']]

Properties

$answerFormat

protected string $answerFormat = 'long'

'long' for full translated answers, 'short' for raw answer codes.

Methods

__construct()

ExportSurveyResultsService constructor.

public __construct(Survey $survey, FilterPatcher $responseFilterPatcher, TransformerOutputSurveyResponses $transformerOutputSurveyResponses, ExportAnswerFormatter $answerFormatter, SurveyAnswerCache $answerCache) : mixed
Parameters
$survey : Survey
$responseFilterPatcher : FilterPatcher
$transformerOutputSurveyResponses : TransformerOutputSurveyResponses
$answerFormatter : ExportAnswerFormatter
$answerCache : SurveyAnswerCache

exportResponses()

Export survey responses to the specified format.

public exportResponses(int $surveyId, string $exportType) : array<string|int, mixed>
Parameters
$surveyId : int

The survey ID

$exportType : string

The export format (csv, html)

Tags
throws
InvalidArgumentException

If the export type is not supported

throws
RuntimeException

If survey is not found or responses cannot be fetched

Return values
array<string|int, mixed>

Export result with content/filePath and metadata

setAnswerFormat()

public setAnswerFormat(string $answerFormat) : $this
Parameters
$answerFormat : string

'long' or 'short'

Return values
$this

setLanguage()

public setLanguage(string|null $language) : $this
Parameters
$language : string|null
Return values
$this

setOutputMode()

public setOutputMode(string $outputMode) : $this
Parameters
$outputMode : string

'memory' or 'file'

Return values
$this

exportResponsesInChunks()

Export survey responses in chunks, writing directly to the export writer.

protected exportResponsesInChunks(int $surveyId, string $exportType, array<string|int, mixed> $metadata) : array<string|int, mixed>
Parameters
$surveyId : int
$exportType : string
$metadata : array<string|int, mixed>
Tags
throws
RuntimeException

If responses cannot be fetched

Return values
array<string|int, mixed>

Export result from the writer

fetchTimingsForChunk()

Fetch timing data for a chunk of SurveyDynamic response objects.

protected fetchTimingsForChunk(int $surveyId, array<string|int, mixed> $chunk) : array<string|int, mixed>
Parameters
$surveyId : int
$chunk : array<string|int, mixed>

Array of SurveyDynamic objects

Return values
array<string|int, mixed>

Timing rows indexed by response ID

getActualAid()

Get the actual answer ID using the shared answer cache.

protected getActualAid(int $questionID, int $scaleId, string $value) : int|null
Parameters
$questionID : int
$scaleId : int
$value : string
Return values
int|null

getQuestionFieldMap()

Get the question field map.

protected getQuestionFieldMap() : array<string|int, mixed>
Return values
array<string|int, mixed>

getTimingFieldMap()

Generate timing field map entries for export headers and data mapping.

protected getTimingFieldMap([string|null $language = null ]) : array<string|int, mixed>
Parameters
$language : string|null = null
Return values
array<string|int, mixed>

Timing field map keyed by field name

getTotalResponseCount()

Get the total number of responses for a survey.

protected getTotalResponseCount(int $surveyId) : int
Parameters
$surveyId : int
Tags
throws
RuntimeException
Return values
int

mapResponsesToQuestions()

Map survey responses to survey questions.

protected mapResponsesToQuestions(array<string|int, mixed> $responses, array<string|int, mixed> $surveyQuestions) : array<string|int, mixed>
Parameters
$responses : array<string|int, mixed>
$surveyQuestions : array<string|int, mixed>
Return values
array<string|int, mixed>

processResponseChunk()

Process a chunk of SurveyDynamic responses through the transformer, override dates with raw values, format answers, and merge timing data.

protected processResponseChunk(array<string|int, mixed> $chunk, array<string|int, mixed> $surveyQuestions[, array<string|int, mixed> $timingsData = [] ][, array<string|int, mixed> $timingFieldKeys = [] ]) : array<string|int, mixed>
Parameters
$chunk : array<string|int, mixed>

Array of SurveyDynamic objects

$surveyQuestions : array<string|int, mixed>

The survey questions field map

$timingsData : array<string|int, mixed> = []

Timing data indexed by response ID

$timingFieldKeys : array<string|int, mixed> = []

Array of timing field keys

Return values
array<string|int, mixed>

Processed responses ready for the writer

mergeTimingData()

Merge timing data into the response's answers array.

private mergeTimingData(array<string|int, mixed> &$response, array<string|int, mixed> $timingsData, array<string|int, mixed> $timingFieldKeys) : mixed
Parameters
$response : array<string|int, mixed>
$timingsData : array<string|int, mixed>

Timing data indexed by response ID

$timingFieldKeys : array<string|int, mixed>

overrideDateFields()

Override date fields with raw DB values (bypass ISO 8601 formatting) and merge any missing raw attributes into the response.

private overrideDateFields(array<string|int, mixed> &$response, array<string|int, mixed> $rawAttributes) : mixed
Parameters
$response : array<string|int, mixed>
$rawAttributes : array<string|int, mixed>

        
On this page

Search results