ExportSurveyResultsService
in package
Uses
ResponseMappingTrait
Tags
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
$answerCache
protected
SurveyAnswerCache
$answerCache
$answerFormat
protected
string
$answerFormat
= 'long'
'long' for full translated answers, 'short' for raw answer codes.
$answerFormatter
protected
ExportAnswerFormatter
$answerFormatter
$chunkSize
protected
int
$chunkSize
= 500
Number of responses to fetch per chunk.
$language
protected
string|null
$language
Language code for the export. Defaults to survey base language.
$loadedSurvey
protected
Survey|null
$loadedSurvey
The loaded survey instance for the current export.
$outputMode
protected
string
$outputMode
= 'memory'
Output mode: 'memory' or 'file'.
$responseFilterPatcher
protected
FilterPatcher
$responseFilterPatcher
$supportedExportTypes
protected
mixed
$supportedExportTypes
= ['csv', 'html']
$survey
protected
Survey
$survey
Injected model instance used for querying.
$transformerOutputSurveyResponses
protected
TransformerOutputSurveyResponses
$transformerOutputSurveyResponses
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
Return values
array<string|int, mixed> —Export result with content/filePath and metadata
getAnswerFormat()
public
getAnswerFormat() : string
Return values
stringgetChunkSize()
public
getChunkSize() : int
Return values
intgetLanguage()
public
getLanguage() : string|null
Return values
string|nullgetOutputMode()
public
getOutputMode() : string
Return values
stringsetAnswerFormat()
public
setAnswerFormat(string $answerFormat) : $this
Parameters
- $answerFormat : string
-
'long' or 'short'
Return values
$thissetChunkSize()
public
setChunkSize(int $chunkSize) : $this
Parameters
- $chunkSize : int
Return values
$thissetLanguage()
public
setLanguage(string|null $language) : $this
Parameters
- $language : string|null
Return values
$thissetOutputMode()
public
setOutputMode(string $outputMode) : $this
Parameters
- $outputMode : string
-
'memory' or 'file'
Return values
$thisexportResponsesInChunks()
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
Return values
array<string|int, mixed> —Export result from the writer
fetchResponseChunkDirect()
Fetch a chunk of responses directly using CDbCriteria.
protected
fetchResponseChunkDirect(SurveyDynamic $model, int $offset, int $limit) : array<string|int, SurveyDynamic>
Parameters
- $model : SurveyDynamic
- $offset : int
- $limit : int
Tags
Return values
array<string|int, SurveyDynamic>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|nullgetExportWriter()
Get the appropriate export writer for the given type.
protected
getExportWriter(string $exportType) : ExportWriterInterface
Parameters
- $exportType : string
Tags
Return values
ExportWriterInterfacegetQuestionFieldMap()
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
Return values
intmapResponsesToQuestions()
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>