X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/d39fc843019b9a4b7d7eebc7544edb8c86e245db..refs/pull/2023/head:/app/Entities/Page.php diff --git a/app/Entities/Page.php b/app/Entities/Page.php index 1c2cc5cff..76dc628fb 100644 --- a/app/Entities/Page.php +++ b/app/Entities/Page.php @@ -1,8 +1,25 @@ belongsTo(Book::class); - } - /** * Get the parent item - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ - public function parent() + public function parent(): Entity { - return $this->chapter_id ? $this->chapter() : $this->book(); + return $this->chapter_id ? $this->chapter : $this->book; } /** * Get the chapter that this page is in, If applicable. - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ public function chapter() { @@ -72,12 +79,12 @@ class Page extends Entity */ public function revisions() { - return $this->hasMany(PageRevision::class)->where('type', '=', 'version')->orderBy('created_at', 'desc'); + return $this->hasMany(PageRevision::class)->where('type', '=', 'version')->orderBy('created_at', 'desc')->orderBy('id', 'desc'); } /** * Get the attachments assigned to this page. - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ public function attachments() { @@ -95,27 +102,17 @@ class Page extends Entity $midText = $this->draft ? '/draft/' : '/page/'; $idComponent = $this->draft ? $this->id : urlencode($this->slug); + $url = '/books/' . urlencode($bookSlug) . $midText . $idComponent; if ($path !== false) { - return baseUrl('/books/' . urlencode($bookSlug) . $midText . $idComponent . '/' . trim($path, '/')); + $url .= '/' . trim($path, '/'); } - return baseUrl('/books/' . urlencode($bookSlug) . $midText . $idComponent); - } - - /** - * Return a generalised, common raw query that can be 'unioned' across entities. - * @param bool $withContent - * @return string - */ - public function entityRawQuery($withContent = false) - { - $htmlQuery = $withContent ? 'html' : "'' as html"; - return "'BookStack\\\\Page' as entity_type, id, id as entity_id, slug, name, {$this->textField} as text, {$htmlQuery}, book_id, priority, chapter_id, draft, created_by, updated_by, updated_at, created_at"; + return url($url); } /** * Get the current revision for the page if existing - * @return \BookStack\Entities\PageRevision|null + * @return PageRevision|null */ public function getCurrentRevision() {