MySqlTextRepository
extends AbstractRepository
in package
implements
TextRepositoryInterface
MySQL repository for Text entities.
Provides database access for text management operations. Handles both basic CRUD and text-specific queries.
Tags
Table of Contents
Interfaces
- TextRepositoryInterface
- Repository interface for Text entities.
Properties
- $columnMap : array<string, string>
- Column mapping: entity property => database column.
- $primaryKey : string
- The primary key column name.
- $tableName : string
- The table name (without prefix).
Methods
- beginTransaction() : bool
- Begin a database transaction.
- clearAnnotation() : bool
- Clear the annotated text for a text.
- commit() : bool
- Commit the current transaction.
- count() : int
- Count entities matching criteria.
- countByLanguage() : int
- Count texts for a specific language.
- delete() : bool
- Delete an entity.
- exists() : bool
- Check if an entity with the given ID exists.
- find() : object|null
- Find an entity by its primary key.
- findAll() : array<int, object>
- Find all entities.
- findAnnotated() : array<string|int, Text>
- Find annotated texts.
- findBy() : array<int, object>
- Find entities by criteria.
- findByLanguage() : array<string|int, Text>
- Find all texts for a specific language.
- findByTitle() : Text|null
- Find a text by title within a language.
- findOneBy() : object|null
- Find a single entity by criteria.
- findPaginated() : Text[], total: int, page: int, per_page: int, total_pages: int}
- Get texts with pagination and language info.
- findUnannotated() : array<string|int, Text>
- Find unannotated texts.
- findWithMedia() : array<string|int, Text>
- Find texts with media (audio/video).
- getBasicInfo() : array{id: int, title: string, language_id: int, has_media: bool, has_annotation: bool}|null
- Get basic text info (minimal data for lists).
- getForSelect() : array<int, array{id: int, title: string, language_id: int}>
- Get texts formatted for select dropdown options.
- getLanguagesWithTexts() : array<string|int, int>
- Get language IDs that have texts.
- getNextTextId() : int|null
- Get the next text ID in the language.
- getPreviousTextId() : int|null
- Get the previous text ID in the language.
- getStatistics() : array{total: int, with_media: int, annotated: int, with_source: int}
- Get statistics for texts.
- resetProgress() : bool
- Reset reading progress for a text.
- rollback() : bool
- Rollback the current transaction.
- save() : int
- Save an entity (insert or update).
- searchByTitle() : array<string|int, Text>
- Search texts by title.
- titleExists() : bool
- Check if a title exists within a language.
- updateAudioPosition() : bool
- Update the audio position for a text.
- updatePosition() : bool
- Update the reading position for a text.
- getEntityId() : int
- Get the ID from an entity.
- mapToEntity() : object
- Map a database row to an entity object.
- mapToRow() : array<string, mixed>
- Map an entity to a database row.
- query() : QueryBuilder
- Override base query to filter out archived texts.
- setEntityId() : void
- Set the ID on an entity.
Properties
$columnMap
Column mapping: entity property => database column.
protected
array<string, string>
$columnMap
= ['id' => 'TxID', 'languageId' => 'TxLgID', 'title' => 'TxTitle', 'text' => 'TxText', 'annotatedText' => 'TxAnnotatedText', 'mediaUri' => 'TxAudioURI', 'sourceUri' => 'TxSourceURI', 'position' => 'TxPosition', 'audioPosition' => 'TxAudioPosition']
Property to column mapping
$primaryKey
The primary key column name.
protected
string
$primaryKey
= 'TxID'
Primary key column
$tableName
The table name (without prefix).
protected
string
$tableName
= 'texts'
Table name without prefix
Methods
beginTransaction()
Begin a database transaction.
public
beginTransaction() : bool
Return values
boolclearAnnotation()
Clear the annotated text for a text.
public
clearAnnotation(int $textId) : bool
Parameters
- $textId : int
-
Text ID
Return values
bool —True if updated
commit()
Commit the current transaction.
public
commit() : bool
Return values
boolcount()
Count entities matching criteria.
public
count([array<string, mixed> $criteria = [] ]) : int
Parameters
- $criteria : array<string, mixed> = []
Return values
int —The count
countByLanguage()
Count texts for a specific language.
public
countByLanguage(int $languageId) : int
Parameters
- $languageId : int
-
Language ID
Return values
intdelete()
Delete an entity.
public
delete(object|int $entityOrId) : bool
Parameters
- $entityOrId : object|int
-
The entity or its ID
Tags
Return values
bool —True if deleted, false if not found
exists()
Check if an entity with the given ID exists.
public
exists(int $id) : bool
Parameters
- $id : int
-
The entity ID
Return values
boolfind()
Find an entity by its primary key.
public
find(int $id) : object|null
Parameters
- $id : int
-
The entity ID
Return values
object|null —The entity or null if not found
findAll()
Find all entities.
public
findAll() : array<int, object>
Return values
array<int, object> —Array of entities
findAnnotated()
Find annotated texts.
public
findAnnotated([int|null $languageId = null ]) : array<string|int, Text>
Parameters
- $languageId : int|null = null
-
Language ID (null for all)
Return values
array<string|int, Text>findBy()
Find entities by criteria.
public
findBy(array<string, mixed> $criteria[, array<string, string>|null $orderBy = null ][, int|null $limit = null ][, int|null $offset = null ]) : array<int, object>
Parameters
- $criteria : array<string, mixed>
- $orderBy : array<string, string>|null = null
- $limit : int|null = null
-
Maximum results
- $offset : int|null = null
-
Offset for pagination
Return values
array<int, object> —Array of matching entities
findByLanguage()
Find all texts for a specific language.
public
findByLanguage(int $languageId[, string|null $orderBy = 'TxTitle' ][, string $direction = 'ASC' ]) : array<string|int, Text>
Parameters
- $languageId : int
-
Language ID
- $orderBy : string|null = 'TxTitle'
-
Column to order by
- $direction : string = 'ASC'
-
Sort direction (ASC/DESC)
Return values
array<string|int, Text>findByTitle()
Find a text by title within a language.
public
findByTitle(int $languageId, string $title) : Text|null
Parameters
- $languageId : int
-
Language ID
- $title : string
-
Text title
Return values
Text|nullfindOneBy()
Find a single entity by criteria.
public
findOneBy(array<string, mixed> $criteria) : object|null
Parameters
- $criteria : array<string, mixed>
Tags
Return values
object|nullfindPaginated()
Get texts with pagination and language info.
public
findPaginated([int $languageId = 0 ][, int $page = 1 ][, int $perPage = 20 ][, string $orderBy = 'TxTitle' ][, string $direction = 'ASC' ]) : Text[], 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 = 'TxTitle'
-
Column to order by
- $direction : string = 'ASC'
-
Sort direction
Return values
Text[], total: int, page: int, per_page: int, total_pages: int}findUnannotated()
Find unannotated texts.
public
findUnannotated([int|null $languageId = null ]) : array<string|int, Text>
Parameters
- $languageId : int|null = null
-
Language ID (null for all)
Return values
array<string|int, Text>findWithMedia()
Find texts with media (audio/video).
public
findWithMedia([int|null $languageId = null ]) : array<string|int, Text>
Parameters
- $languageId : int|null = null
-
Language ID (null for all)
Return values
array<string|int, Text>getBasicInfo()
Get basic text info (minimal data for lists).
public
getBasicInfo(int $textId) : array{id: int, title: string, language_id: int, has_media: bool, has_annotation: bool}|null
Parameters
- $textId : int
-
Text ID
Return values
array{id: int, title: string, language_id: int, has_media: bool, has_annotation: bool}|nullgetForSelect()
Get texts formatted for select dropdown options.
public
getForSelect([int $languageId = 0 ][, int $maxNameLength = 40 ]) : array<int, array{id: int, title: string, language_id: int}>
Parameters
- $languageId : int = 0
-
Language ID (0 for all languages)
- $maxNameLength : int = 40
-
Maximum title length before truncation
Return values
array<int, array{id: int, title: string, language_id: int}>getLanguagesWithTexts()
Get language IDs that have texts.
public
getLanguagesWithTexts() : array<string|int, int>
Return values
array<string|int, int> —Array of language IDs
getNextTextId()
Get the next text ID in the language.
public
getNextTextId(int $textId, int $languageId) : int|null
Parameters
- $textId : int
-
Current text ID
- $languageId : int
-
Language ID
Return values
int|null —Next text ID or null
getPreviousTextId()
Get the previous text ID in the language.
public
getPreviousTextId(int $textId, int $languageId) : int|null
Parameters
- $textId : int
-
Current text ID
- $languageId : int
-
Language ID
Return values
int|null —Previous text ID or null
getStatistics()
Get statistics for texts.
public
getStatistics([int|null $languageId = null ]) : array{total: int, with_media: int, annotated: int, with_source: int}
Parameters
- $languageId : int|null = null
-
Language ID (null for all)
Return values
array{total: int, with_media: int, annotated: int, with_source: int}resetProgress()
Reset reading progress for a text.
public
resetProgress(int $textId) : bool
Parameters
- $textId : int
-
Text ID
Return values
bool —True if updated
rollback()
Rollback the current transaction.
public
rollback() : bool
Return values
boolsave()
Save an entity (insert or update).
public
save(object $entity) : int
Parameters
- $entity : object
-
The entity to save
Tags
Return values
int —The entity ID (useful for inserts)
searchByTitle()
Search texts by title.
public
searchByTitle(string $query[, int|null $languageId = null ][, int $limit = 50 ]) : array<string|int, Text>
Parameters
- $query : string
-
Search query
- $languageId : int|null = null
-
Language ID (null for all)
- $limit : int = 50
-
Maximum results
Return values
array<string|int, Text>titleExists()
Check if a title exists within a language.
public
titleExists(int $languageId, string $title[, int|null $excludeId = null ]) : bool
Parameters
- $languageId : int
-
Language ID
- $title : string
-
Text title
- $excludeId : int|null = null
-
Text ID to exclude (for updates)
Return values
boolupdateAudioPosition()
Update the audio position for a text.
public
updateAudioPosition(int $textId, float $position) : bool
Parameters
- $textId : int
-
Text ID
- $position : float
-
New audio position in seconds
Return values
bool —True if updated
updatePosition()
Update the reading position for a text.
public
updatePosition(int $textId, int $position) : bool
Parameters
- $textId : int
-
Text ID
- $position : int
-
New reading position
Return values
bool —True if updated
getEntityId()
Get the ID from an entity.
protected
getEntityId(Text $entity) : int
Parameters
- $entity : Text
Return values
int —The entity ID
mapToEntity()
Map a database row to an entity object.
protected
mapToEntity(array<string|int, mixed> $row) : object
Parameters
- $row : array<string|int, mixed>
-
Database row
Return values
object —The entity
mapToRow()
Map an entity to a database row.
protected
mapToRow(Text $entity) : array<string, mixed>
Parameters
- $entity : Text
Return values
array<string, mixed>query()
Override base query to filter out archived texts.
protected
query() : QueryBuilder
Active texts have TxArchivedAt IS NULL. Archived texts use a separate set of methods that explicitly include TxArchivedAt IS NOT NULL.
Return values
QueryBuildersetEntityId()
Set the ID on an entity.
protected
setEntityId(Text $entity, int $id) : void
Parameters
- $entity : Text
- $id : int
-
The ID to set