ImportEpub
in package
Use case for importing EPUB files as books.
Parses the EPUB, creates a book record, and imports each chapter as a text record linked to the book.
Tags
Table of Contents
Properties
- $bookRepository : BookRepositoryInterface
- $epubParser : EpubParserService
- $textRepository : TextRepositoryInterface
- $textSplitter : TextSplitterService
Methods
- __construct() : mixed
- Constructor.
- execute() : array{success: bool, message: string, bookId: int|null, chapterCount: int, textIds: int[]}
- Import an EPUB file as a book.
- applyTags() : void
- Apply tags to a text.
- createChapterText() : int
- Create a text record for a chapter.
- importChapter() : array<string|int, int>
- Import a single chapter as one or more text records.
- linkTextToBook() : void
- Link a text record to a book.
Properties
$bookRepository
private
BookRepositoryInterface
$bookRepository
$epubParser
private
EpubParserService
$epubParser
$textRepository
private
TextRepositoryInterface
$textRepository
$textSplitter
private
TextSplitterService
$textSplitter
Methods
__construct()
Constructor.
public
__construct(BookRepositoryInterface $bookRepository, TextRepositoryInterface $textRepository, EpubParserService $epubParser, TextSplitterService $textSplitter) : mixed
Parameters
- $bookRepository : BookRepositoryInterface
-
Book repository
- $textRepository : TextRepositoryInterface
-
Text repository
- $epubParser : EpubParserService
-
EPUB parser service
- $textSplitter : TextSplitterService
-
Text splitter service
execute()
Import an EPUB file as a book.
public
execute(int $languageId, array<string, mixed> $uploadedFile[, string|null $overrideTitle = null ][, array<string|int, int> $tagIds = [] ][, int|null $userId = null ]) : array{success: bool, message: string, bookId: int|null, chapterCount: int, textIds: int[]}
Parameters
- $languageId : int
-
Language ID for the book
- $uploadedFile : array<string, mixed>
-
Uploaded file data from $_FILES
- $overrideTitle : string|null = null
-
Optional title override
- $tagIds : array<string|int, int> = []
-
Tag IDs to apply to all chapters
- $userId : int|null = null
-
User ID (for multi-user mode)
Tags
Return values
array{success: bool, message: string, bookId: int|null, chapterCount: int, textIds: int[]}applyTags()
Apply tags to a text.
private
applyTags(int $textId, array<string|int, int> $tagIds) : void
Parameters
- $textId : int
-
Text ID
- $tagIds : array<string|int, int>
-
Array of tag IDs
createChapterText()
Create a text record for a chapter.
private
createChapterText(int $bookId, int $languageId, int $chapterNum, string $chapterTitle, string $content, array<string|int, int> $tagIds, int|null $userId) : int
Parameters
- $bookId : int
-
Book ID
- $languageId : int
-
Language ID
- $chapterNum : int
-
Chapter number
- $chapterTitle : string
-
Chapter title
- $content : string
-
Chapter content
- $tagIds : array<string|int, int>
-
Tag IDs to apply
- $userId : int|null
-
User ID
Return values
int —Text ID
importChapter()
Import a single chapter as one or more text records.
private
importChapter(int $bookId, int $languageId, int $chapterNum, string $chapterTitle, string $content, array<string|int, int> $tagIds, int|null $userId) : array<string|int, int>
If the chapter content exceeds 60KB, it will be split into multiple text records, each linked to the book.
Parameters
- $bookId : int
-
Book ID
- $languageId : int
-
Language ID
- $chapterNum : int
-
Chapter number
- $chapterTitle : string
-
Chapter title
- $content : string
-
Chapter content
- $tagIds : array<string|int, int>
-
Tag IDs to apply
- $userId : int|null
-
User ID
Return values
array<string|int, int> —Array of created text IDs
linkTextToBook()
Link a text record to a book.
private
linkTextToBook(int $textId, int $bookId, int $chapterNum, string $chapterTitle) : void
Parameters
- $textId : int
-
Text ID
- $bookId : int
-
Book ID
- $chapterNum : int
-
Chapter number
- $chapterTitle : string
-
Chapter title