MySqlTermRepository
in package
implements
TermRepositoryInterface
MySQL implementation of Term Repository.
Provides database access for vocabulary/word management operations. Handles both basic CRUD and term-specific queries.
Tags
Table of Contents
Interfaces
- TermRepositoryInterface
- Repository interface for Term entities.
Properties
- $columnMap : array<string, string>
- $primaryKey : string
- $tableName : string
Methods
- count() : int
- Count terms matching criteria.
- countByLanguage() : int
- Count terms for a specific language.
- delete() : bool
- Delete a term by ID.
- deleteMultiple() : int
- Delete multiple terms by IDs.
- exists() : bool
- Check if a term exists.
- find() : Term|null
- Find a term by ID.
- findAll() : array<string|int, Term>
- Find all terms.
- findByLanguage() : array<string|int, Term>
- Find all terms for a specific language.
- findByLemma() : array<string|int, Term>
- Find all terms sharing a lemma in a language (word family).
- findByStatus() : array<string|int, Term>
- Find terms by status.
- findByTextLc() : Term|null
- Find a term by lowercase text within a language.
- findForReview() : array<string|int, Term>
- Find terms needing review (based on score thresholds).
- findIgnored() : array<string|int, Term>
- Find ignored terms (status 98).
- findKnown() : array<string|int, Term>
- Find terms that are known (status 5 or 99).
- findLearning() : array<string|int, Term>
- Find terms in learning stages (status 1-4).
- findMultiWord() : array<string|int, Term>
- Find multi-word expressions (word count > 1).
- findPaginated() : Term[], total: int, page: int, per_page: int, total_pages: int}
- Get terms with pagination.
- findRecent() : array<string|int, Term>
- Find recently added terms.
- findRecentlyChanged() : array<string|int, Term>
- Find terms with status changed recently.
- findSingleWord() : array<string|int, Term>
- Find single-word terms (word count = 1).
- findWithoutTranslation() : array<string|int, Term>
- Find terms without translation.
- getBasicInfo() : array{id: int, text: string, language_id: int, status: int, has_translation: bool}|null
- Get basic term info (minimal data for lists).
- getForSelect() : array<int, array{id: int, text: string, language_id: int}>
- Get terms formatted for select dropdown options.
- getLanguagesWithTerms() : array<string|int, int>
- Get language IDs that have terms.
- getStatistics() : array{total: int, learning: int, known: int, ignored: int, multi_word: int}
- Get statistics for terms.
- getStatusDistribution() : array<int, int>
- Get status distribution counts.
- getWordCountDistribution() : array<int, int>
- Get term count by word count.
- save() : int
- Save a term (insert or update).
- searchByText() : array<string|int, Term>
- Search terms by text.
- searchByTranslation() : array<string|int, Term>
- Search terms by translation.
- termExists() : bool
- Check if a term exists within a language.
- updateLemma() : bool
- Update the lemma (base form) of a term.
- updateNotes() : bool
- Update the notes of a term.
- updateRomanization() : bool
- Update the romanization of a term.
- updateScores() : bool
- Update review scores for a term.
- updateSentence() : bool
- Update the example sentence of a term.
- updateStatus() : bool
- Update the status of a term.
- updateStatusMultiple() : int
- Update status for multiple terms.
- updateTranslation() : bool
- Update the translation of a term.
- mapToEntity() : Term
- Map a database row to a Term entity.
- mapToRow() : array<string, null|scalar>
- Map a Term entity to a database row.
- query() : QueryBuilder
- Get a query builder for this repository's table.
- parseDateTime() : DateTimeImmutable
- Parse a datetime string into DateTimeImmutable.
Properties
$columnMap
protected
array<string, string>
$columnMap
= ['id' => 'WoID', 'languageId' => 'WoLgID', 'text' => 'WoText', 'textLowercase' => 'WoTextLC', 'lemma' => 'WoLemma', 'lemmaLc' => 'WoLemmaLC', 'status' => 'WoStatus', 'translation' => 'WoTranslation', 'sentence' => 'WoSentence', 'notes' => 'WoNotes', 'romanization' => 'WoRomanization', 'wordCount' => 'WoWordCount', 'createdAt' => 'WoCreated', 'statusChangedAt' => 'WoStatusChanged', 'todayScore' => 'WoTodayScore', 'tomorrowScore' => 'WoTomorrowScore', 'random' => 'WoRandom']
Property to column mapping
$primaryKey
protected
string
$primaryKey
= 'WoID'
Primary key column
$tableName
protected
string
$tableName
= 'words'
Table name without prefix
Methods
count()
Count terms matching criteria.
public
count([array<string, mixed> $criteria = [] ]) : int
Parameters
- $criteria : array<string, mixed> = []
-
Field => value pairs
Return values
int —The count
countByLanguage()
Count terms for a specific language.
public
countByLanguage(int $languageId) : int
Parameters
- $languageId : int
-
Language ID
Return values
intdelete()
Delete a term by ID.
public
delete(int $id) : bool
Parameters
- $id : int
-
Term ID
Return values
bool —True if deleted
deleteMultiple()
Delete multiple terms by IDs.
public
deleteMultiple(array<string|int, mixed> $termIds) : int
Parameters
- $termIds : array<string|int, mixed>
-
Array of term IDs
Return values
int —Number of deleted terms
exists()
Check if a term exists.
public
exists(int $id) : bool
Parameters
- $id : int
-
Term ID
Return values
boolfind()
Find a term by ID.
public
find(int $id) : Term|null
Parameters
- $id : int
-
Term ID
Return values
Term|nullfindAll()
Find all terms.
public
findAll() : array<string|int, Term>
Return values
array<string|int, Term>findByLanguage()
Find all terms for a specific language.
public
findByLanguage(int $languageId[, string|null $orderBy = 'WoText' ][, string $direction = 'ASC' ]) : array<string|int, Term>
Parameters
- $languageId : int
-
Language ID
- $orderBy : string|null = 'WoText'
-
Column to order by
- $direction : string = 'ASC'
-
Sort direction
Return values
array<string|int, Term>findByLemma()
Find all terms sharing a lemma in a language (word family).
public
findByLemma(int $languageId, string $lemmaLc) : array<string|int, Term>
Parameters
- $languageId : int
-
Language ID
- $lemmaLc : string
-
Lowercase lemma
Return values
array<string|int, Term>findByStatus()
Find terms by status.
public
findByStatus(int $status[, int|null $languageId = null ]) : array<string|int, Term>
Parameters
- $status : int
-
Status value (1-5, 98, 99)
- $languageId : int|null = null
-
Language ID (null for all)
Return values
array<string|int, Term>findByTextLc()
Find a term by lowercase text within a language.
public
findByTextLc(int $languageId, string $textLc) : Term|null
Parameters
- $languageId : int
-
Language ID
- $textLc : string
-
Lowercase term text
Return values
Term|nullfindForReview()
Find terms needing review (based on score thresholds).
public
findForReview([int|null $languageId = null ][, float $scoreThreshold = 0.0 ][, int $limit = 100 ]) : array<string|int, Term>
Parameters
- $languageId : int|null = null
-
Language ID (null for all)
- $scoreThreshold : float = 0.0
-
Score threshold for today
- $limit : int = 100
-
Maximum results
Return values
array<string|int, Term>findIgnored()
Find ignored terms (status 98).
public
findIgnored([int|null $languageId = null ]) : array<string|int, Term>
Parameters
- $languageId : int|null = null
-
Language ID (null for all)
Return values
array<string|int, Term>findKnown()
Find terms that are known (status 5 or 99).
public
findKnown([int|null $languageId = null ]) : array<string|int, Term>
Parameters
- $languageId : int|null = null
-
Language ID (null for all)
Return values
array<string|int, Term>findLearning()
Find terms in learning stages (status 1-4).
public
findLearning([int|null $languageId = null ]) : array<string|int, Term>
Parameters
- $languageId : int|null = null
-
Language ID (null for all)
Return values
array<string|int, Term>findMultiWord()
Find multi-word expressions (word count > 1).
public
findMultiWord([int|null $languageId = null ]) : array<string|int, Term>
Parameters
- $languageId : int|null = null
-
Language ID (null for all)
Return values
array<string|int, Term>findPaginated()
Get terms with pagination.
public
findPaginated([int $languageId = 0 ][, int $page = 1 ][, int $perPage = 20 ][, string $orderBy = 'WoText' ][, string $direction = 'ASC' ]) : Term[], total: int, page: int, per_page: int, total_pages: int}
Parameters
- $languageId : int = 0
-
Language ID (0 for all)
- $page : int = 1
-
Page number (1-based)
- $perPage : int = 20
-
Items per page
- $orderBy : string = 'WoText'
-
Column to order by
- $direction : string = 'ASC'
-
Sort direction
Return values
Term[], total: int, page: int, per_page: int, total_pages: int}findRecent()
Find recently added terms.
public
findRecent([int|null $languageId = null ][, int $limit = 50 ]) : array<string|int, Term>
Parameters
- $languageId : int|null = null
-
Language ID (null for all)
- $limit : int = 50
-
Maximum results
Return values
array<string|int, Term>findRecentlyChanged()
Find terms with status changed recently.
public
findRecentlyChanged([int|null $languageId = null ][, int $days = 7 ][, int $limit = 50 ]) : array<string|int, Term>
Parameters
- $languageId : int|null = null
-
Language ID (null for all)
- $days : int = 7
-
Number of days to look back
- $limit : int = 50
-
Maximum results
Return values
array<string|int, Term>findSingleWord()
Find single-word terms (word count = 1).
public
findSingleWord([int|null $languageId = null ]) : array<string|int, Term>
Parameters
- $languageId : int|null = null
-
Language ID (null for all)
Return values
array<string|int, Term>findWithoutTranslation()
Find terms without translation.
public
findWithoutTranslation([int|null $languageId = null ]) : array<string|int, Term>
Parameters
- $languageId : int|null = null
-
Language ID (null for all)
Return values
array<string|int, Term>getBasicInfo()
Get basic term info (minimal data for lists).
public
getBasicInfo(int $termId) : array{id: int, text: string, language_id: int, status: int, has_translation: bool}|null
Parameters
- $termId : int
-
Term ID
Return values
array{id: int, text: string, language_id: int, status: int, has_translation: bool}|nullgetForSelect()
Get terms formatted for select dropdown options.
public
getForSelect([int $languageId = 0 ][, int $maxNameLength = 40 ]) : array<int, array{id: int, text: string, language_id: int}>
Parameters
- $languageId : int = 0
-
Language ID (0 for all languages)
- $maxNameLength : int = 40
-
Maximum text length before truncation
Return values
array<int, array{id: int, text: string, language_id: int}>getLanguagesWithTerms()
Get language IDs that have terms.
public
getLanguagesWithTerms() : array<string|int, int>
Return values
array<string|int, int> —Array of language IDs
getStatistics()
Get statistics for terms.
public
getStatistics([int|null $languageId = null ]) : array{total: int, learning: int, known: int, ignored: int, multi_word: int}
Parameters
- $languageId : int|null = null
-
Language ID (null for all)
Return values
array{total: int, learning: int, known: int, ignored: int, multi_word: int}getStatusDistribution()
Get status distribution counts.
public
getStatusDistribution([int|null $languageId = null ]) : array<int, int>
Parameters
- $languageId : int|null = null
-
Language ID (null for all)
Return values
array<int, int> —Status value => count
getWordCountDistribution()
Get term count by word count.
public
getWordCountDistribution([int|null $languageId = null ]) : array<int, int>
Parameters
- $languageId : int|null = null
-
Language ID (null for all)
Return values
array<int, int> —Word count => term count
save()
Save a term (insert or update).
public
save(Term $term) : int
Parameters
- $term : Term
-
The term to save
Return values
int —The term ID
searchByText()
Search terms by text.
public
searchByText(string $query[, int|null $languageId = null ][, int $limit = 50 ]) : array<string|int, Term>
Parameters
- $query : string
-
Search query
- $languageId : int|null = null
-
Language ID (null for all)
- $limit : int = 50
-
Maximum results
Return values
array<string|int, Term>searchByTranslation()
Search terms by translation.
public
searchByTranslation(string $query[, int|null $languageId = null ][, int $limit = 50 ]) : array<string|int, Term>
Parameters
- $query : string
-
Search query
- $languageId : int|null = null
-
Language ID (null for all)
- $limit : int = 50
-
Maximum results
Return values
array<string|int, Term>termExists()
Check if a term exists within a language.
public
termExists(int $languageId, string $textLc[, int|null $excludeId = null ]) : bool
Parameters
- $languageId : int
-
Language ID
- $textLc : string
-
Lowercase term text
- $excludeId : int|null = null
-
Term ID to exclude (for updates)
Return values
boolupdateLemma()
Update the lemma (base form) of a term.
public
updateLemma(int $termId, string|null $lemma) : bool
Parameters
- $termId : int
-
Term ID
- $lemma : string|null
-
New lemma (null to clear)
Return values
bool —True if updated
updateNotes()
Update the notes of a term.
public
updateNotes(int $termId, string $notes) : bool
Parameters
- $termId : int
-
Term ID
- $notes : string
-
New notes
Return values
bool —True if updated
updateRomanization()
Update the romanization of a term.
public
updateRomanization(int $termId, string $romanization) : bool
Parameters
- $termId : int
-
Term ID
- $romanization : string
-
New romanization
Return values
bool —True if updated
updateScores()
Update review scores for a term.
public
updateScores(int $termId, float $todayScore, float $tomorrowScore) : bool
Parameters
- $termId : int
-
Term ID
- $todayScore : float
-
Today's score
- $tomorrowScore : float
-
Tomorrow's score
Return values
bool —True if updated
updateSentence()
Update the example sentence of a term.
public
updateSentence(int $termId, string $sentence) : bool
Parameters
- $termId : int
-
Term ID
- $sentence : string
-
New sentence
Return values
bool —True if updated
updateStatus()
Update the status of a term.
public
updateStatus(int $termId, int $status) : bool
Parameters
- $termId : int
-
Term ID
- $status : int
-
New status value
Return values
bool —True if updated
updateStatusMultiple()
Update status for multiple terms.
public
updateStatusMultiple(array<string|int, mixed> $termIds, int $status) : int
Parameters
- $termIds : array<string|int, mixed>
-
Array of term IDs
- $status : int
-
New status value
Return values
int —Number of updated terms
updateTranslation()
Update the translation of a term.
public
updateTranslation(int $termId, string $translation) : bool
Parameters
- $termId : int
-
Term ID
- $translation : string
-
New translation
Return values
bool —True if updated
mapToEntity()
Map a database row to a Term entity.
protected
mapToEntity(array<string, mixed> $row) : Term
Parameters
- $row : array<string, mixed>
-
Database row
Return values
TermmapToRow()
Map a Term entity to a database row.
protected
mapToRow(Term $term) : array<string, null|scalar>
Parameters
- $term : Term
-
The term entity
Return values
array<string, null|scalar> —Database column => value pairs
query()
Get a query builder for this repository's table.
protected
query() : QueryBuilder
Return values
QueryBuilderparseDateTime()
Parse a datetime string into DateTimeImmutable.
private
parseDateTime(string|null $datetime) : DateTimeImmutable
Parameters
- $datetime : string|null
-
The datetime string