CreateBookFromTexts
in package
Use case for creating a book from a large text that needs splitting.
Takes a long text, splits it into chapters, and creates a book with linked text records for each chapter.
Tags
Table of Contents
Properties
- $bookRepository : BookRepositoryInterface
- $textRepository : TextRepositoryInterface
- $textSplitter : TextSplitterService
Methods
- __construct() : mixed
- Constructor.
- execute() : array{success: bool, message: string, bookId: int|null, chapterCount: int, textIds: int[]}
- Create a book from a long text.
- applyTags() : void
- Apply tags to a text.
- cleanText() : string
- Clean text content.
- linkTextToBook() : void
- Link a text record to a book.
Properties
$bookRepository
private
BookRepositoryInterface
$bookRepository
$textRepository
private
TextRepositoryInterface
$textRepository
$textSplitter
private
TextSplitterService
$textSplitter
Methods
__construct()
Constructor.
public
__construct(BookRepositoryInterface $bookRepository, TextRepositoryInterface $textRepository, TextSplitterService $textSplitter) : mixed
Parameters
- $bookRepository : BookRepositoryInterface
-
Book repository
- $textRepository : TextRepositoryInterface
-
Text repository
- $textSplitter : TextSplitterService
-
Text splitter service
execute()
Create a book from a long text.
public
execute(int $languageId, string $title, string $text[, string|null $author = null ][, string $audioUri = '' ][, string $sourceUri = '' ][, array<string|int, int> $tagIds = [] ][, int|null $userId = null ]) : array{success: bool, message: string, bookId: int|null, chapterCount: int, textIds: int[]}
The text will be split at paragraph boundaries into chapters, each stored as a separate text record linked to the book.
Parameters
- $languageId : int
-
Language ID
- $title : string
-
Book title
- $text : string
-
Text content to split
- $author : string|null = null
-
Author name (optional)
- $audioUri : string = ''
-
Audio URI (applied to first chapter)
- $sourceUri : string = ''
-
Source URI (applied to first chapter)
- $tagIds : array<string|int, int> = []
-
Tag IDs to apply to all chapters
- $userId : int|null = null
-
User ID (for multi-user mode)
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
cleanText()
Clean text content.
private
cleanText(string $text) : string
Parameters
- $text : string
-
Raw text
Return values
string —Cleaned text
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