-
- protected $baseRepo;
-
- /**
- * PageRepo constructor.
- */
- public function __construct(BaseRepo $baseRepo)
- {
- $this->baseRepo = $baseRepo;
- }
-
- /**
- * Get a page by ID.
- * @throws NotFoundException
- */
- public function getById(int $id, array $relations = ['book']): Page
- {
- $page = Page::visible()->with($relations)->find($id);
-
- if (!$page) {
- throw new NotFoundException(trans('errors.page_not_found'));
- }
-
- return $page;
- }
-
- /**
- * Get a page its book and own slug.
- * @throws NotFoundException
- */
- public function getBySlug(string $bookSlug, string $pageSlug): Page
- {
- $page = Page::visible()->whereSlugs($bookSlug, $pageSlug)->first();
-
- if (!$page) {
- throw new NotFoundException(trans('errors.page_not_found'));
- }
-
- return $page;
- }
-
- /**
- * Get a page by its old slug but checking the revisions table
- * for the last revision that matched the given page and book slug.
- */
- public function getByOldSlug(string $bookSlug, string $pageSlug): ?Page
- {
- $revision = PageRevision::query()
- ->whereHas('page', function (Builder $query) {
- $query->visible();
- })
- ->where('slug', '=', $pageSlug)
- ->where('type', '=', 'version')
- ->where('book_slug', '=', $bookSlug)
- ->orderBy('created_at', 'desc')
- ->with('page')
- ->first();
- return $revision ? $revision->page : null;
- }
-
- /**
- * Get pages that have been marked as a template.
- */
- public function getTemplates(int $count = 10, int $page = 1, string $search = ''): LengthAwarePaginator
- {
- $query = Page::visible()
- ->where('template', '=', true)
- ->orderBy('name', 'asc')
- ->skip(($page - 1) * $count)
- ->take($count);
-
- if ($search) {
- $query->where('name', 'like', '%' . $search . '%');
- }
-
- $paginator = $query->paginate($count, ['*'], 'page', $page);
- $paginator->withPath('/templates');
-
- return $paginator;
- }
-
- /**
- * Get a parent item via slugs.
- */
- public function getParentFromSlugs(string $bookSlug, string $chapterSlug = null): Entity
- {
- if ($chapterSlug !== null) {
- return $chapter = Chapter::visible()->whereSlugs($bookSlug, $chapterSlug)->firstOrFail();
- }
-
- return Book::visible()->where('slug', '=', $bookSlug)->firstOrFail();
- }
-
- /**
- * Get the draft copy of the given page for the current user.
- */
- public function getUserDraft(Page $page): ?PageRevision
- {
- $revision = $this->getUserDraftQuery($page)->first();
- return $revision;
+ public function __construct(
+ protected BaseRepo $baseRepo,
+ protected RevisionRepo $revisionRepo,
+ protected EntityQueries $entityQueries,
+ protected ReferenceStore $referenceStore,
+ protected ReferenceUpdater $referenceUpdater,
+ protected TrashCan $trashCan,
+ ) {