CsvExportWriter
in package
implements
ExportWriterInterface
Uses
ExportHeadingTrait
Table of Contents
Interfaces
Properties
- $filename : string
- $filePath : string|null
- $handle : resource|null
- $headersWritten : bool
- $metaColumns : array<string|int, mixed>
- $metadata : array<string|int, mixed>
- $responseCount : int
Methods
- export() : array<string|int, mixed>
- Export survey responses to CSV format.
- finalize() : array<string|int, mixed>
- Finalize the export and return the result.
- getFileExtension() : string
- Get the file extension for CSV format.
- getMimeType() : string
- Get the MIME type for CSV format.
- init() : void
- Initialize the writer for chunked export.
- writeChunk() : void
- Write a chunk of responses.
- buildQuestionHeading() : string
- Build a question heading matching the legacy export "full" heading format.
- cleanHeadingText() : string
- Strip HTML tags and decode entities from text.
- csvEscape() : string
- Escape a value for CSV output.
- writeCsvRow() : void
- Write a single CSV row with RFC 4180 line endings (\r\n).
Properties
$filename
private
string
$filename
= ''
Generated filename
$filePath
private
string|null
$filePath
= null
File path for file output mode
$handle
private
resource|null
$handle
= null
File handle for chunked writing
$headersWritten
private
bool
$headersWritten
= false
Whether headers have been written
$metaColumns
private
array<string|int, mixed>
$metaColumns
= []
Active metadata columns from fieldMap
$metadata
private
array<string|int, mixed>
$metadata
= []
Metadata from init
$responseCount
private
int
$responseCount
= 0
Response count for chunked writing
Methods
export()
Export survey responses to CSV format.
public
export(array<string|int, mixed> $responses, array<string|int, mixed> $surveyQuestions, array<string|int, mixed> $metadata) : array<string|int, mixed>
Can generate content in-memory or write to a file depending on outputMode.
Parameters
- $responses : array<string|int, mixed>
-
The survey responses data
- $surveyQuestions : array<string|int, mixed>
-
The survey questions field map
- $metadata : array<string|int, mixed>
-
Additional metadata (survey ID, language, outputMode, etc.)
Tags
Return values
array<string|int, mixed> —Export result with content/filePath and metadata
finalize()
Finalize the export and return the result.
public
finalize() : array<string|int, mixed>
Return values
array<string|int, mixed> —Export result with content/filePath and metadata
getFileExtension()
Get the file extension for CSV format.
public
getFileExtension() : string
Return values
stringgetMimeType()
Get the MIME type for CSV format.
public
getMimeType() : string
Return values
stringinit()
Initialize the writer for chunked export.
public
init(array<string|int, mixed> $surveyQuestions, array<string|int, mixed> $metadata) : void
Parameters
- $surveyQuestions : array<string|int, mixed>
-
The survey questions field map (for headers)
- $metadata : array<string|int, mixed>
-
Additional metadata (surveyId, language, etc.)
writeChunk()
Write a chunk of responses.
public
writeChunk(array<string|int, mixed> $responses, array<string|int, mixed> $surveyQuestions) : void
Parameters
- $responses : array<string|int, mixed>
-
Chunk of survey responses data
- $surveyQuestions : array<string|int, mixed>
-
The survey questions field map
buildQuestionHeading()
Build a question heading matching the legacy export "full" heading format.
private
buildQuestionHeading(array<string|int, mixed> $question) : string
Parameters
- $question : array<string|int, mixed>
-
Question field map entry
Return values
stringcleanHeadingText()
Strip HTML tags and decode entities from text.
private
cleanHeadingText(string $text) : string
Parameters
- $text : string
Return values
stringcsvEscape()
Escape a value for CSV output.
private
csvEscape(mixed $value) : string
Parameters
- $value : mixed
Return values
stringwriteCsvRow()
Write a single CSV row with RFC 4180 line endings (\r\n).
private
writeCsvRow(array<string|int, mixed> $fields) : void
Parameters
- $fields : array<string|int, mixed>