ExportService
in package
Service class for exporting vocabulary data.
Provides methods for exporting terms in various formats:
- Anki (with RTL support and sentence masking)
- TSV (simple tab-separated format)
- Flexible (customizable template-based format)
Tags
Table of Contents
Methods
- exportAnki() : never
- Export terms to Anki format and send as download.
- exportFlexible() : never
- Export terms using flexible template and send as download.
- exportTsv() : never
- Export terms to TSV format and send as download.
- generateAnkiContent() : string
- Generate Anki export content from SQL query.
- generateFlexibleContent() : string
- Generate flexible export content from SQL query.
- generateTsvContent() : string
- Generate TSV export content from SQL query.
- maskTermInSentence() : string
- Mask the term in a sentence by replacing characters with bullets.
- maskTermInSentenceV2() : string
- Mask the term in a sentence by replacing it with "[...]".
- replaceTabNewline() : string
- Replace all whitespace characters with simple space.
- formatAnkiRow() : string
- Format a single record for Anki export.
- formatFlexibleRow() : string
- Format a single record for flexible export.
- formatTsvRow() : string
- Format a single record for TSV export.
- sendDownloadResponse() : never
- Send content as a file download.
Methods
exportAnki()
Export terms to Anki format and send as download.
public
exportAnki(string $sql) : never
Parameters
- $sql : string
-
SQL query to retrieve terms
Return values
neverexportFlexible()
Export terms using flexible template and send as download.
public
exportFlexible(string $sql) : never
Parameters
- $sql : string
-
SQL query to retrieve terms
Return values
neverexportTsv()
Export terms to TSV format and send as download.
public
exportTsv(string $sql) : never
Parameters
- $sql : string
-
SQL query to retrieve terms
Return values
nevergenerateAnkiContent()
Generate Anki export content from SQL query.
public
generateAnkiContent(string $sql) : string
Parameters
- $sql : string
-
SQL query to retrieve terms
Return values
string —Anki-formatted export content
generateFlexibleContent()
Generate flexible export content from SQL query.
public
generateFlexibleContent(string $sql) : string
Parameters
- $sql : string
-
SQL query to retrieve terms
Return values
string —Template-formatted export content
generateTsvContent()
Generate TSV export content from SQL query.
public
generateTsvContent(string $sql) : string
Parameters
- $sql : string
-
SQL query to retrieve terms
Return values
string —TSV-formatted export content
maskTermInSentence()
Mask the term in a sentence by replacing characters with bullets.
public
static maskTermInSentence(string $s, string $regexword) : string
Characters within } brackets matching the regex pattern are replaced with bullet characters (•).
Parameters
- $s : string
-
Sentence with term marked by } brackets
- $regexword : string
-
Regex pattern for word characters
Return values
string —Sentence with term characters replaced by bullets
maskTermInSentenceV2()
Mask the term in a sentence by replacing it with "[...]".
public
static maskTermInSentenceV2(string $s) : string
The entire content within } brackets is replaced with "[...]".
Parameters
- $s : string
-
Sentence with term marked by } brackets
Return values
string —Sentence with term replaced by "[...]"
replaceTabNewline()
Replace all whitespace characters with simple space.
public
static replaceTabNewline(string $s) : string
Converts tabs, newlines, and multiple spaces to single spaces. The output string is also trimmed.
Parameters
- $s : string
-
String to parse
Return values
string —String with normalized whitespace
formatAnkiRow()
Format a single record for Anki export.
private
formatAnkiRow(array<string|int, mixed> $record) : string
Parameters
- $record : array<string|int, mixed>
-
Database record
Return values
string —Formatted row
formatFlexibleRow()
Format a single record for flexible export.
private
formatFlexibleRow(array<string|int, mixed> $record) : string
Parameters
- $record : array<string|int, mixed>
-
Database record
Return values
string —Formatted row using template
formatTsvRow()
Format a single record for TSV export.
private
formatTsvRow(array<string, mixed> $record) : string
Parameters
- $record : array<string, mixed>
-
Database record
Return values
string —Formatted row
sendDownloadResponse()
Send content as a file download.
private
sendDownloadResponse(string $content, string $filename) : never
Parameters
- $content : string
-
File content
- $filename : string
-
Download filename