BookRepositoryInterface
in
Repository interface for Book persistence operations.
Tags
Table of Contents
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.
Methods
beginTransaction()
Begin a database transaction.
public
beginTransaction() : void
commit()
Commit the current database transaction.
public
commit() : void
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
Cascades to delete all associated text chapters.
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> —Array of books
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
rollback()
Rollback the current database transaction.
public
rollback() : void
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)