X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/7f3f6e65b9705beabbafa5ceba8636a74ac22138..refs/pull/1688/head:/app/Entities/Bookshelf.php diff --git a/app/Entities/Bookshelf.php b/app/Entities/Bookshelf.php index 1de767fec..7ad2415ed 100644 --- a/app/Entities/Bookshelf.php +++ b/app/Entities/Bookshelf.php @@ -39,9 +39,9 @@ class Bookshelf extends Entity public function getUrl($path = false) { if ($path !== false) { - return baseUrl('/shelves/' . urlencode($this->slug) . '/' . trim($path, '/')); + return url('/http/source.bookstackapp.com/shelves/' . urlencode($this->slug) . '/' . trim($path, '/')); } - return baseUrl('/shelves/' . urlencode($this->slug)); + return url('/http/source.bookstackapp.com/shelves/' . urlencode($this->slug)); } /** @@ -59,7 +59,7 @@ class Bookshelf extends Entity } try { - $cover = $this->cover ? baseUrl($this->cover->getThumb($width, $height, false)) : $default; + $cover = $this->cover ? url($this->cover->getThumb($width, $height, false)) : $default; } catch (\Exception $err) { $cover = $default; } @@ -83,7 +83,7 @@ class Bookshelf extends Entity public function getExcerpt(int $length = 100) { $description = $this->description; - return strlen($description) > $length ? substr($description, 0, $length-3) . '...' : $description; + return mb_strlen($description) > $length ? mb_substr($description, 0, $length-3) . '...' : $description; } /** @@ -100,8 +100,22 @@ class Bookshelf extends Entity * @param Book $book * @return bool */ - public function contains(Book $book) + public function contains(Book $book): bool { return $this->books()->where('id', '=', $book->id)->count() > 0; } + + /** + * Add a book to the end of this shelf. + * @param Book $book + */ + public function appendBook(Book $book) + { + if ($this->contains($book)) { + return; + } + + $maxOrder = $this->books()->max('order'); + $this->books()->attach($book->id, ['order' => $maxOrder + 1]); + } }