Documentation

MySqlBookRepository implements BookRepositoryInterface

MySQL repository for Book entities.

Provides database access for book management operations.

Tags
since
3.0.0

Table of Contents

Interfaces

BookRepositoryInterface
Repository interface for Book persistence operations.

Properties

$columnMap  : array<string, string>
$primaryKey  : string
$tableName  : string

Methods

beginTransaction()  : void
Begin a database transaction.
commit()  : void
Commit the current database transaction.
count()  : int
Count books for a user.
delete()  : bool
Delete a book by its ID.
existsBySourceHash()  : bool
Check if a book with the given source hash exists.
findAll()  : array<string|int, Book>
Get all books for a user.
findById()  : Book|null
Find a book by its ID.
findBySourceHash()  : Book|null
Find a book by its source hash (for duplicate detection).
getBookContextForText()  : array{bookId: int, bookTitle: string, chapterNum: int, chapterTitle: string|null, totalChapters: int, prevTextId: int|null, nextTextId: int|null}|null
Get book info for a text that belongs to a book.
getChapters()  : array<string|int, array{id: int, num: int, title: string}>
Get chapters (texts) for a book.
getChapterTextId()  : int|null
Get the text ID for a specific chapter of a book.
rollback()  : void
Rollback the current database transaction.
save()  : int
Save a book (insert or update).
updateChapterCount()  : void
Update the total chapter count for a book.
updateCurrentChapter()  : void
Update the current reading position for a book.
getEntityId()  : int
{@inheritdoc}
mapToEntity()  : Book
Map a database row to a Book entity.
mapToRow()  : array<string, scalar|null>
{@inheritdoc}
query()  : QueryBuilder
Create a query builder for the books table.
setEntityId()  : void
{@inheritdoc}

Properties

$columnMap

protected array<string, string> $columnMap = ['id' => 'BkID', 'userId' => 'BkUsID', 'languageId' => 'BkLgID', 'title' => 'BkTitle', 'author' => 'BkAuthor', 'description' => 'BkDescription', 'coverPath' => 'BkCoverPath', 'sourceType' => 'BkSourceType', 'sourceHash' => 'BkSourceHash', 'totalChapters' => 'BkTotalChapters', 'currentChapter' => 'BkCurrentChapter']

Property to column mapping

Methods

count()

Count books for a user.

public count([int|null $userId = null ][, int|null $languageId = null ]) : int
Parameters
$userId : int|null = null

User ID (null for all users)

$languageId : int|null = null

Filter by language

Return values
int

Number of books

delete()

Delete a book by its ID.

public delete(int $id) : bool
Parameters
$id : int

Book ID

Return values
bool

True if deleted

existsBySourceHash()

Check if a book with the given source hash exists.

public existsBySourceHash(string $hash[, int|null $userId = null ]) : bool
Parameters
$hash : string

SHA-256 hash of the source file

$userId : int|null = null

User ID for multi-user filtering

Return values
bool

True if exists

findAll()

Get all books for a user.

public findAll([int|null $userId = null ][, int|null $languageId = null ][, int $limit = 50 ][, int $offset = 0 ]) : array<string|int, Book>
Parameters
$userId : int|null = null

User ID (null for all users)

$languageId : int|null = null

Filter by language

$limit : int = 50

Maximum number of results

$offset : int = 0

Offset for pagination

Return values
array<string|int, Book>

findById()

Find a book by its ID.

public findById(int $id) : Book|null
Parameters
$id : int

Book ID

Return values
Book|null

The book or null if not found

findBySourceHash()

Find a book by its source hash (for duplicate detection).

public findBySourceHash(string $hash[, int|null $userId = null ]) : Book|null
Parameters
$hash : string

SHA-256 hash of the source file

$userId : int|null = null

User ID for multi-user filtering

Return values
Book|null

The book or null if not found

getBookContextForText()

Get book info for a text that belongs to a book.

public getBookContextForText(int $textId) : array{bookId: int, bookTitle: string, chapterNum: int, chapterTitle: string|null, totalChapters: int, prevTextId: int|null, nextTextId: int|null}|null
Parameters
$textId : int

Text ID

Return values
array{bookId: int, bookTitle: string, chapterNum: int, chapterTitle: string|null, totalChapters: int, prevTextId: int|null, nextTextId: int|null}|null

Book context or null if text doesn't belong to a book

getChapters()

Get chapters (texts) for a book.

public getChapters(int $bookId) : array<string|int, array{id: int, num: int, title: string}>
Parameters
$bookId : int

Book ID

Return values
array<string|int, array{id: int, num: int, title: string}>

Array of chapter info

getChapterTextId()

Get the text ID for a specific chapter of a book.

public getChapterTextId(int $bookId, int $chapterNum) : int|null
Parameters
$bookId : int

Book ID

$chapterNum : int

Chapter number (1-based)

Return values
int|null

Text ID or null if not found

save()

Save a book (insert or update).

public save(Book $book) : int
Parameters
$book : Book

The book to save

Return values
int

The book ID

updateChapterCount()

Update the total chapter count for a book.

public updateChapterCount(int $bookId, int $count) : void
Parameters
$bookId : int

Book ID

$count : int

Number of chapters

updateCurrentChapter()

Update the current reading position for a book.

public updateCurrentChapter(int $bookId, int $chapterNum) : void
Parameters
$bookId : int

Book ID

$chapterNum : int

Chapter number (1-based)

mapToEntity()

Map a database row to a Book entity.

protected mapToEntity(array<string, mixed> $row) : Book
Parameters
$row : array<string, mixed>

Database row

Return values
Book

mapToRow()

{@inheritdoc}

protected mapToRow(Book $entity) : array<string, scalar|null>
Parameters
$entity : Book
Return values
array<string, scalar|null>

        
On this page

Search results