namespace BookStack\Entities\Repos;
-use BookStack\Actions\ActivityType;
+use BookStack\Activity\ActivityType;
use BookStack\Entities\Models\Book;
+use BookStack\Entities\Models\Page;
use BookStack\Entities\Models\Chapter;
-use BookStack\Entities\Models\Entity;
use BookStack\Entities\Tools\BookContents;
use BookStack\Entities\Tools\TrashCan;
use BookStack\Exceptions\MoveOperationException;
class ChapterRepo
{
- protected $baseRepo;
-
- /**
- * ChapterRepo constructor.
- */
- public function __construct(BaseRepo $baseRepo)
- {
- $this->baseRepo = $baseRepo;
+ public function __construct(
+ protected BaseRepo $baseRepo
+ ) {
}
/**
$chapter->book_id = $parentBook->id;
$chapter->priority = (new BookContents($parentBook))->getLastPriority() + 1;
$this->baseRepo->create($chapter, $input);
+ $this->baseRepo->updateDefaultTemplate($chapter, intval($input['default_template_id'] ?? null));
Activity::add(ActivityType::CHAPTER_CREATE, $chapter);
return $chapter;
public function update(Chapter $chapter, array $input): Chapter
{
$this->baseRepo->update($chapter, $input);
+
+ if (array_key_exists('default_template_id', $input)) {
+ $this->baseRepo->updateDefaultTemplate($chapter, intval($input['default_template_id']));
+ }
+
Activity::add(ActivityType::CHAPTER_UPDATE, $chapter);
return $chapter;